Skip to content

Commit f57cc8c

Browse files
committed
Always evaluate all cfg predicate in all() and any()
1 parent cb4ee81 commit f57cc8c

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

compiler/rustc_attr/src/builtin.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,18 @@ pub fn eval_condition(
594594
match cfg.name_or_empty() {
595595
sym::any => mis
596596
.iter()
597-
.any(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
597+
// We don't use any() here, because we want to evaluate all cfg condition
598+
// as eval_condition can (and does) extra checks
599+
.fold(false, |res, mi| {
600+
res | eval_condition(mi.meta_item().unwrap(), sess, features, eval)
601+
}),
598602
sym::all => mis
599603
.iter()
600-
.all(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
604+
// We don't use all() here, because we want to evaluate all cfg condition
605+
// as eval_condition can (and does) extra checks
606+
.fold(true, |res, mi| {
607+
res & eval_condition(mi.meta_item().unwrap(), sess, features, eval)
608+
}),
601609
sym::not => {
602610
if mis.len() != 1 {
603611
struct_span_err!(

src/test/ui/cfg/cfg-path-error.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-fail
2+
3+
#[cfg(any(foo, foo::bar))]
4+
//~^ERROR `cfg` predicate key must be an identifier
5+
fn foo1() {}
6+
7+
#[cfg(any(foo::bar, foo))]
8+
//~^ERROR `cfg` predicate key must be an identifier
9+
fn foo2() {}
10+
11+
#[cfg(all(foo, foo::bar))]
12+
//~^ERROR `cfg` predicate key must be an identifier
13+
fn foo3() {}
14+
15+
#[cfg(all(foo::bar, foo))]
16+
//~^ERROR `cfg` predicate key must be an identifier
17+
fn foo4() {}
18+
19+
fn main() {}

src/test/ui/cfg/cfg-path-error.stderr

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: `cfg` predicate key must be an identifier
2+
--> $DIR/cfg-path-error.rs:3:16
3+
|
4+
LL | #[cfg(any(foo, foo::bar))]
5+
| ^^^^^^^^
6+
7+
error: `cfg` predicate key must be an identifier
8+
--> $DIR/cfg-path-error.rs:7:11
9+
|
10+
LL | #[cfg(any(foo::bar, foo))]
11+
| ^^^^^^^^
12+
13+
error: `cfg` predicate key must be an identifier
14+
--> $DIR/cfg-path-error.rs:11:16
15+
|
16+
LL | #[cfg(all(foo, foo::bar))]
17+
| ^^^^^^^^
18+
19+
error: `cfg` predicate key must be an identifier
20+
--> $DIR/cfg-path-error.rs:15:11
21+
|
22+
LL | #[cfg(all(foo::bar, foo))]
23+
| ^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
26+

0 commit comments

Comments
 (0)