Skip to content

Commit 017671c

Browse files
committed
Tweak parse_check_cfg.
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.
1 parent e926e65 commit 017671c

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

compiler/rustc_interface/src/interface.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
132132
rustc_span::create_default_session_if_not_set_then(move |_| {
133133
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
134134
// are enabled by default.
135-
let exhaustive_names = !specs.is_empty();
136-
let exhaustive_values = !specs.is_empty();
137-
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
135+
let mut exhaustive_names = !specs.is_empty();
136+
let mut exhaustive_values = !specs.is_empty();
137+
let mut expecteds = FxHashMap::default();
138138

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

170-
check_cfg.exhaustive_names = true;
170+
exhaustive_names = true;
171171
for arg in args {
172172
if arg.is_word() && arg.ident().is_some() {
173173
let ident = arg.ident().expect("multi-segment cfg key");
174-
check_cfg
175-
.expecteds
174+
expecteds
176175
.entry(ident.name.to_string())
177176
.or_insert(ExpectedValues::Any);
178177
} else {
@@ -182,16 +181,15 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
182181
} else if meta_item.has_name(sym::values) {
183182
// defaults are flipped for the old syntax
184183
if old_syntax == None {
185-
check_cfg.exhaustive_names = false;
186-
check_cfg.exhaustive_values = false;
184+
exhaustive_names = false;
185+
exhaustive_values = false;
187186
}
188187
old_syntax = Some(true);
189188

190189
if let Some((name, values)) = args.split_first() {
191190
if name.is_word() && name.ident().is_some() {
192191
let ident = name.ident().expect("multi-segment cfg key");
193-
let expected_values = check_cfg
194-
.expecteds
192+
let expected_values = expecteds
195193
.entry(ident.name.to_string())
196194
.and_modify(|expected_values| match expected_values {
197195
ExpectedValues::Some(_) => {}
@@ -232,7 +230,7 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
232230
);
233231
}
234232
} else if args.is_empty() {
235-
check_cfg.exhaustive_values = true;
233+
exhaustive_values = true;
236234
} else {
237235
expected_error();
238236
}
@@ -322,11 +320,10 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
322320
error!("`cfg(any())` can only be provided in isolation");
323321
}
324322

325-
check_cfg.exhaustive_names = false;
323+
exhaustive_names = false;
326324
} else {
327325
for name in names {
328-
check_cfg
329-
.expecteds
326+
expecteds
330327
.entry(name.to_string())
331328
.and_modify(|v| match v {
332329
ExpectedValues::Some(v)
@@ -366,7 +363,7 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
366363
}
367364
}
368365

369-
check_cfg
366+
CheckCfg { exhaustive_names, exhaustive_values, expecteds }
370367
})
371368
}
372369

0 commit comments

Comments
 (0)