Skip to content

Commit 989edf4

Browse files
committed
Review feedback
* Use a match statement. * Clarify why we can't use `file_stem()`. * Error if the `:` is missing for Tidy error codes, rather than no-oping.
1 parent a3174de commit 989edf4

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

compiler/rustc_mir/src/transform/coverage/debug.rs

+36-32
Original file line numberDiff line numberDiff line change
@@ -152,38 +152,42 @@ impl DebugOptions {
152152
None => (setting_str, None),
153153
Some((k, v)) => (k, Some(v)),
154154
};
155-
if option == "allow_unused_expressions" {
156-
allow_unused_expressions = bool_option_val(option, value);
157-
debug!(
158-
"{} env option `allow_unused_expressions` is set to {}",
159-
RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions
160-
);
161-
} else if option == "counter_format" {
162-
match value {
163-
None => {
164-
bug!(
165-
"`{}` option in environment variable {} requires one or more \
166-
plus-separated choices (a non-empty subset of \
167-
`id+block+operation`)",
168-
option,
169-
RUSTC_COVERAGE_DEBUG_OPTIONS
170-
);
171-
}
172-
Some(val) => {
173-
counter_format = counter_format_option_val(val);
174-
debug!(
175-
"{} env option `counter_format` is set to {:?}",
176-
RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format
177-
);
178-
}
179-
};
180-
} else {
181-
bug!(
182-
"Unsupported setting `{}` in environment variable {}",
183-
option,
184-
RUSTC_COVERAGE_DEBUG_OPTIONS
185-
)
186-
}
155+
match option {
156+
"allow_unused_expressions" => {
157+
allow_unused_expressions = bool_option_val(option, value);
158+
debug!(
159+
"{} env option `allow_unused_expressions` is set to {}",
160+
RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions
161+
);
162+
}
163+
"counter_format" => {
164+
match value {
165+
None => {
166+
bug!(
167+
"`{}` option in environment variable {} requires one or more \
168+
plus-separated choices (a non-empty subset of \
169+
`id+block+operation`)",
170+
option,
171+
RUSTC_COVERAGE_DEBUG_OPTIONS
172+
);
173+
}
174+
Some(val) => {
175+
counter_format = counter_format_option_val(val);
176+
debug!(
177+
"{} env option `counter_format` is set to {:?}",
178+
RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format
179+
);
180+
}
181+
};
182+
}
183+
_ => {
184+
bug!(
185+
"Unsupported setting `{}` in environment variable {}",
186+
option,
187+
RUSTC_COVERAGE_DEBUG_OPTIONS
188+
)
189+
}
190+
};
187191
}
188192
}
189193

src/tools/tidy/src/error_codes_check.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ fn extract_error_codes(
8585
for line in f.lines() {
8686
let s = line.trim();
8787
if !reached_no_explanation && s.starts_with('E') && s.contains("include_str!(\"") {
88-
let err_code = match s.split_once(':') {
89-
None => continue,
90-
Some((err_code, _)) => err_code.to_owned(),
91-
};
88+
let err_code = s
89+
.split_once(':')
90+
.expect(
91+
format!(
92+
"Expected a line with the format `E0xxx: include_str!(\"..\")`, but got {} without a `:` delimiter",
93+
s,
94+
).as_str()
95+
)
96+
.0
97+
.to_owned();
9298
if !error_codes.contains_key(&err_code) {
9399
error_codes.insert(err_code.clone(), false);
94100
}

src/tools/tidy/src/ui_tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub fn check(path: &Path, bad: &mut bool) {
1919
//
2020
// For now, just make sure that there is a corresponding
2121
// `$testname.rs` file.
22+
//
23+
// NB: We do not use file_stem() as some file names have multiple `.`s and we
24+
// must strip all of them.
2225
let testname =
2326
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
2427
if !file_path.with_file_name(testname).with_extension("rs").exists() {

0 commit comments

Comments
 (0)