Skip to content

Commit

Permalink
Tweak parse_check_cfg.
Browse files Browse the repository at this point in the history
Instead of constructing the `CheckCfg` up front and then modifying it,
construct the three components and then put them together at the end.

This change resulted in the compiler noticing that one
`exhaustive_names` assignment was dead, so I commented that one out.
  • Loading branch information
nnethercote committed Oct 27, 2023
1 parent e926e65 commit 017671c
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
rustc_span::create_default_session_if_not_set_then(move |_| {
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
// are enabled by default.
let exhaustive_names = !specs.is_empty();
let exhaustive_values = !specs.is_empty();
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
let mut exhaustive_names = !specs.is_empty();
let mut exhaustive_values = !specs.is_empty();
let mut expecteds = FxHashMap::default();

let mut old_syntax = None;
for s in specs {
Expand Down Expand Up @@ -162,17 +162,16 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
if meta_item.has_name(sym::names) {
// defaults are flipped for the old syntax
if old_syntax == None {
check_cfg.exhaustive_names = false;
check_cfg.exhaustive_values = false;
//exhaustive_names = false; // overwritten immediately below
exhaustive_values = false;
}
old_syntax = Some(true);

check_cfg.exhaustive_names = true;
exhaustive_names = true;
for arg in args {
if arg.is_word() && arg.ident().is_some() {
let ident = arg.ident().expect("multi-segment cfg key");
check_cfg
.expecteds
expecteds
.entry(ident.name.to_string())
.or_insert(ExpectedValues::Any);
} else {
Expand All @@ -182,16 +181,15 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
} else if meta_item.has_name(sym::values) {
// defaults are flipped for the old syntax
if old_syntax == None {
check_cfg.exhaustive_names = false;
check_cfg.exhaustive_values = false;
exhaustive_names = false;
exhaustive_values = false;
}
old_syntax = Some(true);

if let Some((name, values)) = args.split_first() {
if name.is_word() && name.ident().is_some() {
let ident = name.ident().expect("multi-segment cfg key");
let expected_values = check_cfg
.expecteds
let expected_values = expecteds
.entry(ident.name.to_string())
.and_modify(|expected_values| match expected_values {
ExpectedValues::Some(_) => {}
Expand Down Expand Up @@ -232,7 +230,7 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
);
}
} else if args.is_empty() {
check_cfg.exhaustive_values = true;
exhaustive_values = true;
} else {
expected_error();
}
Expand Down Expand Up @@ -322,11 +320,10 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
error!("`cfg(any())` can only be provided in isolation");
}

check_cfg.exhaustive_names = false;
exhaustive_names = false;
} else {
for name in names {
check_cfg
.expecteds
expecteds
.entry(name.to_string())
.and_modify(|v| match v {
ExpectedValues::Some(v)
Expand Down Expand Up @@ -366,7 +363,7 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
}
}

check_cfg
CheckCfg { exhaustive_names, exhaustive_values, expecteds }
})
}

Expand Down

0 comments on commit 017671c

Please sign in to comment.