Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_builtin_macros/src/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ use crate::errors::{CfgSelectNoMatches, CfgSelectUnreachable};

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

branches.wildcard.map(|(_, tt, span)| (tt, span))
let wildcard = branches.wildcard.map(|(_, tt, span)| (tt, span));
result.or(wildcard)
}

pub(super) fn expand_cfg_select<'cx>(
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/check-cfg/cfg-select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ check-pass

#![feature(cfg_select)]
#![crate_type = "lib"]

cfg_select! {
true => {}
invalid_cfg1 => {}
//~^ WARN unexpected `cfg` condition name
_ => {}
}

cfg_select! {
invalid_cfg2 => {}
//~^ WARN unexpected `cfg` condition name
true => {}
_ => {}
}
22 changes: 22 additions & 0 deletions tests/ui/check-cfg/cfg-select.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
warning: unexpected `cfg` condition name: `invalid_cfg1`
--> $DIR/cfg-select.rs:8:5
|
LL | invalid_cfg1 => {}
| ^^^^^^^^^^^^
|
= help: expected names are: `FALSE` and `test` and 31 more
= help: to expect this configuration use `--check-cfg=cfg(invalid_cfg1)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `invalid_cfg2`
--> $DIR/cfg-select.rs:14:5
|
LL | invalid_cfg2 => {}
| ^^^^^^^^^^^^
|
= help: to expect this configuration use `--check-cfg=cfg(invalid_cfg2)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration

warning: 2 warnings emitted

Loading