Skip to content

Commit c1f7650

Browse files
authored
Unrolled build for #149380
Rollup merge of #149380 - JonathanBrouwer:cfg_select_lints, r=Urgau Run `eval_config_entry` on all branches so we always emit lints Fixes #149090 Ideally I'd have liked to fix this issue using #149215, and this is still the long term plan, but this is slightly more annoying to implement than I'd have liked to, and this is also a nice and easy solution to the problem. r? `@tgross35`
2 parents 10776a4 + 41900f8 commit c1f7650

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

compiler/rustc_builtin_macros/src/cfg_select.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ use crate::errors::{CfgSelectNoMatches, CfgSelectUnreachable};
1010

1111
/// Selects the first arm whose predicate evaluates to true.
1212
fn select_arm(ecx: &ExtCtxt<'_>, branches: CfgSelectBranches) -> Option<(TokenStream, Span)> {
13+
let mut result = None;
1314
for (cfg, tt, arm_span) in branches.reachable {
1415
if let EvalConfigResult::True = attr::eval_config_entry(
1516
&ecx.sess,
1617
&cfg,
1718
ecx.current_expansion.lint_node_id,
1819
ShouldEmit::ErrorsAndLints,
1920
) {
20-
return Some((tt, arm_span));
21+
// FIXME(#149215) Ideally we should short-circuit here, but `eval_config_entry` currently emits lints so we cannot do this yet.
22+
result.get_or_insert((tt, arm_span));
2123
}
2224
}
2325

24-
branches.wildcard.map(|(_, tt, span)| (tt, span))
26+
let wildcard = branches.wildcard.map(|(_, tt, span)| (tt, span));
27+
result.or(wildcard)
2528
}
2629

2730
pub(super) fn expand_cfg_select<'cx>(

tests/ui/check-cfg/cfg-select.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
3+
#![feature(cfg_select)]
4+
#![crate_type = "lib"]
5+
6+
cfg_select! {
7+
true => {}
8+
invalid_cfg1 => {}
9+
//~^ WARN unexpected `cfg` condition name
10+
_ => {}
11+
}
12+
13+
cfg_select! {
14+
invalid_cfg2 => {}
15+
//~^ WARN unexpected `cfg` condition name
16+
true => {}
17+
_ => {}
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: unexpected `cfg` condition name: `invalid_cfg1`
2+
--> $DIR/cfg-select.rs:8:5
3+
|
4+
LL | invalid_cfg1 => {}
5+
| ^^^^^^^^^^^^
6+
|
7+
= help: expected names are: `FALSE` and `test` and 31 more
8+
= help: to expect this configuration use `--check-cfg=cfg(invalid_cfg1)`
9+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10+
= note: `#[warn(unexpected_cfgs)]` on by default
11+
12+
warning: unexpected `cfg` condition name: `invalid_cfg2`
13+
--> $DIR/cfg-select.rs:14:5
14+
|
15+
LL | invalid_cfg2 => {}
16+
| ^^^^^^^^^^^^
17+
|
18+
= help: to expect this configuration use `--check-cfg=cfg(invalid_cfg2)`
19+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
20+
21+
warning: 2 warnings emitted
22+

0 commit comments

Comments
 (0)