Skip to content

Commit 8345571

Browse files
committed
RFC3239: Implement compact cfg(target(..))
1 parent ae38533 commit 8345571

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

compiler/rustc_attr/src/builtin.rs

+19
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,25 @@ pub fn eval_condition(
630630

631631
!eval_condition(mis[0].meta_item().unwrap(), sess, features, eval)
632632
}
633+
sym::target => {
634+
if let Some(features) = features && !features.cfg_target_compact {
635+
feature_err(
636+
sess,
637+
sym::cfg_target_compact,
638+
cfg.span,
639+
&"compact `cfg(target(..))` is experimental and subject to change"
640+
).emit();
641+
}
642+
643+
mis.iter().fold(true, |res, mi| {
644+
let mut mi = mi.meta_item().unwrap().clone();
645+
if let [seg, ..] = &mut mi.path.segments[..] {
646+
seg.ident.name = Symbol::intern(&format!("target_{}", seg.ident.name));
647+
}
648+
649+
res & eval_condition(&mi, sess, features, eval)
650+
})
651+
}
633652
_ => {
634653
struct_span_err!(
635654
sess.span_diagnostic,

compiler/rustc_attr/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
55
//! to this crate.
66
7+
#![feature(let_chains)]
78
#![feature(let_else)]
89

910
#[macro_use]

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ declare_features! (
319319
(active, cfg_sanitize, "1.41.0", Some(39699), None),
320320
/// Allows `cfg(target_abi = "...")`.
321321
(active, cfg_target_abi, "1.55.0", Some(80970), None),
322+
/// Allows `cfg(target(abi = "..."))`.
323+
(active, cfg_target_compact, "1.63.0", Some(96901), None),
322324
/// Allows `cfg(target_has_atomic_load_store = "...")`.
323325
(active, cfg_target_has_atomic, "1.60.0", Some(94039), None),
324326
/// Allows `cfg(target_has_atomic_equal_alignment = "...")`.

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ symbols! {
427427
cfg_panic,
428428
cfg_sanitize,
429429
cfg_target_abi,
430+
cfg_target_compact,
430431
cfg_target_feature,
431432
cfg_target_has_atomic,
432433
cfg_target_has_atomic_equal_alignment,
@@ -1375,6 +1376,7 @@ symbols! {
13751376
sym,
13761377
sync,
13771378
t32,
1379+
target,
13781380
target_abi,
13791381
target_arch,
13801382
target_endian,

0 commit comments

Comments
 (0)