Skip to content

Commit f4ca42f

Browse files
committed
Fix --check-cfg bug with args order when parsing
1 parent 4b94c23 commit f4ca42f

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

compiler/rustc_interface/src/interface.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,21 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
173173
let expected_values = check_cfg
174174
.expecteds
175175
.entry(ident.name.to_string())
176+
.and_modify(|expected_values| match expected_values {
177+
ExpectedValues::Some(_) => {}
178+
ExpectedValues::Any => {
179+
// handle the case where names(...) was done
180+
// before values by changing to a list
181+
*expected_values =
182+
ExpectedValues::Some(FxHashSet::default());
183+
}
184+
})
176185
.or_insert_with(|| {
177186
ExpectedValues::Some(FxHashSet::default())
178187
});
179188

180189
let ExpectedValues::Some(expected_values) = expected_values else {
181-
bug!("shoudn't be possible")
190+
bug!("`expected_values` should be a list a values")
182191
};
183192

184193
for val in values {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
warning: unexpected `cfg` condition value
2+
--> $DIR/order-independant.rs:8:7
3+
|
4+
LL | #[cfg(a)]
5+
| ^- help: specify a config value: `= "b"`
6+
|
7+
= note: expected values for `a` are: `b`
8+
= note: `#[warn(unexpected_cfgs)]` on by default
9+
10+
warning: unexpected `cfg` condition value
11+
--> $DIR/order-independant.rs:12:7
12+
|
13+
LL | #[cfg(a = "unk")]
14+
| ^^^^^^^^^
15+
|
16+
= note: expected values for `a` are: `b`
17+
18+
warning: 2 warnings emitted
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
warning: unexpected `cfg` condition value
2+
--> $DIR/order-independant.rs:8:7
3+
|
4+
LL | #[cfg(a)]
5+
| ^- help: specify a config value: `= "b"`
6+
|
7+
= note: expected values for `a` are: `b`
8+
= note: `#[warn(unexpected_cfgs)]` on by default
9+
10+
warning: unexpected `cfg` condition value
11+
--> $DIR/order-independant.rs:12:7
12+
|
13+
LL | #[cfg(a = "unk")]
14+
| ^^^^^^^^^
15+
|
16+
= note: expected values for `a` are: `b`
17+
18+
warning: 2 warnings emitted
19+
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
// revisions: names_before names_after
3+
// compile-flags: -Z unstable-options
4+
// compile-flags: --check-cfg=names(names_before,names_after)
5+
// [names_before]compile-flags: --check-cfg=names(a) --check-cfg=values(a,"b")
6+
// [names_after]compile-flags: --check-cfg=values(a,"b") --check-cfg=names(a)
7+
8+
#[cfg(a)]
9+
//~^ WARNING unexpected `cfg` condition value
10+
fn my_cfg() {}
11+
12+
#[cfg(a = "unk")]
13+
//~^ WARNING unexpected `cfg` condition value
14+
fn my_cfg() {}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)