Skip to content

Commit

Permalink
Always evaluate all cfg predicate in all() and any()
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Feb 23, 2022
1 parent cb4ee81 commit f57cc8c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,18 @@ pub fn eval_condition(
match cfg.name_or_empty() {
sym::any => mis
.iter()
.any(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
// We don't use any() here, because we want to evaluate all cfg condition
// as eval_condition can (and does) extra checks
.fold(false, |res, mi| {
res | eval_condition(mi.meta_item().unwrap(), sess, features, eval)
}),
sym::all => mis
.iter()
.all(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
// We don't use all() here, because we want to evaluate all cfg condition
// as eval_condition can (and does) extra checks
.fold(true, |res, mi| {
res & eval_condition(mi.meta_item().unwrap(), sess, features, eval)
}),
sym::not => {
if mis.len() != 1 {
struct_span_err!(
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/cfg/cfg-path-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check-fail

#[cfg(any(foo, foo::bar))]
//~^ERROR `cfg` predicate key must be an identifier
fn foo1() {}

#[cfg(any(foo::bar, foo))]
//~^ERROR `cfg` predicate key must be an identifier
fn foo2() {}

#[cfg(all(foo, foo::bar))]
//~^ERROR `cfg` predicate key must be an identifier
fn foo3() {}

#[cfg(all(foo::bar, foo))]
//~^ERROR `cfg` predicate key must be an identifier
fn foo4() {}

fn main() {}
26 changes: 26 additions & 0 deletions src/test/ui/cfg/cfg-path-error.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:3:16
|
LL | #[cfg(any(foo, foo::bar))]
| ^^^^^^^^

error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:7:11
|
LL | #[cfg(any(foo::bar, foo))]
| ^^^^^^^^

error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:11:16
|
LL | #[cfg(all(foo, foo::bar))]
| ^^^^^^^^

error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:15:11
|
LL | #[cfg(all(foo::bar, foo))]
| ^^^^^^^^

error: aborting due to 4 previous errors

0 comments on commit f57cc8c

Please sign in to comment.