Skip to content

Commit 1969d41

Browse files
authored
Rollup merge of rust-lang#143724 - hkBst:tidy-cleanup, r=Mark-Simulacrum
Tidy cleanup
2 parents c230be7 + 8bf88a2 commit 1969d41

28 files changed

+91
-108
lines changed

src/tools/tidy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tidy"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
autobins = false
66

77
[dependencies]

src/tools/tidy/src/alphabetical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn check_section<'a>(
103103

104104
let prev_line_trimmed_lowercase = prev_line.trim_start_matches(' ');
105105

106-
if version_sort(&trimmed_line, &prev_line_trimmed_lowercase).is_lt() {
106+
if version_sort(trimmed_line, prev_line_trimmed_lowercase).is_lt() {
107107
tidy_error_ext!(err, bad, "{file}:{}: line not in alphabetical order", idx + 1);
108108
}
109109

src/tools/tidy/src/bins.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,15 @@ mod os_impl {
7575
return ReadOnlyFs;
7676
}
7777

78-
panic!("unable to create temporary file `{:?}`: {:?}", path, e);
78+
panic!("unable to create temporary file `{path:?}`: {e:?}");
7979
}
8080
}
8181
}
8282

8383
for &source_dir in sources {
8484
match check_dir(source_dir) {
8585
Unsupported => return false,
86-
ReadOnlyFs => {
87-
return match check_dir(output) {
88-
Supported => true,
89-
_ => false,
90-
};
91-
}
86+
ReadOnlyFs => return matches!(check_dir(output), Supported),
9287
_ => {}
9388
}
9489
}
@@ -139,7 +134,7 @@ mod os_impl {
139134
return;
140135
}
141136

142-
if t!(is_executable(&file), file) {
137+
if t!(is_executable(file), file) {
143138
let rel_path = file.strip_prefix(path).unwrap();
144139
let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
145140

src/tools/tidy/src/deps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ fn check_proc_macro_dep_list(root: &Path, cargo: &Path, bless: bool, bad: &mut b
624624
let is_proc_macro_pkg = |pkg: &Package| pkg.targets.iter().any(|target| target.is_proc_macro());
625625

626626
let mut proc_macro_deps = HashSet::new();
627-
for pkg in metadata.packages.iter().filter(|pkg| is_proc_macro_pkg(*pkg)) {
627+
for pkg in metadata.packages.iter().filter(|pkg| is_proc_macro_pkg(pkg)) {
628628
deps_of(&metadata, &pkg.id, &mut proc_macro_deps);
629629
}
630630
// Remove the proc-macro crates themselves

src/tools/tidy/src/error_codes.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
119119
let Some(split_line) = split_line else {
120120
errors.push(format!(
121121
"{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
122-
but got \"{}\" without a `:` delimiter",
123-
line,
122+
but got \"{line}\" without a `:` delimiter",
124123
));
125124
continue;
126125
};
@@ -129,10 +128,8 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
129128

130129
// If this is a duplicate of another error code, emit a fatal error.
131130
if error_codes.contains(&err_code) {
132-
errors.push(format!(
133-
"{path}:{line_index}: Found duplicate error code: `{}`",
134-
err_code
135-
));
131+
errors
132+
.push(format!("{path}:{line_index}: Found duplicate error code: `{err_code}`"));
136133
continue;
137134
}
138135

@@ -145,8 +142,7 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
145142
let Some(rest) = rest else {
146143
errors.push(format!(
147144
"{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
148-
but got \"{}\" without a `,` delimiter",
149-
line,
145+
but got \"{line}\" without a `,` delimiter",
150146
));
151147
continue;
152148
};
@@ -209,7 +205,7 @@ fn check_error_codes_docs(
209205
}
210206

211207
let (found_code_example, found_proper_doctest, emit_ignore_warning, no_longer_emitted) =
212-
check_explanation_has_doctest(&contents, &err_code);
208+
check_explanation_has_doctest(contents, err_code);
213209

214210
if emit_ignore_warning {
215211
verbose_print!(
@@ -232,7 +228,7 @@ fn check_error_codes_docs(
232228
return;
233229
}
234230

235-
let test_ignored = IGNORE_DOCTEST_CHECK.contains(&&err_code);
231+
let test_ignored = IGNORE_DOCTEST_CHECK.contains(&err_code);
236232

237233
// Check that the explanation has a doctest, and if it shouldn't, that it doesn't
238234
if !found_proper_doctest && !test_ignored {
@@ -300,7 +296,7 @@ fn check_error_codes_tests(
300296
let tests_path = root_path.join(Path::new(ERROR_TESTS_PATH));
301297

302298
for code in error_codes {
303-
let test_path = tests_path.join(format!("{}.stderr", code));
299+
let test_path = tests_path.join(format!("{code}.stderr"));
304300

305301
if !test_path.exists() && !IGNORE_UI_TEST_CHECK.contains(&code.as_str()) {
306302
verbose_print!(
@@ -388,7 +384,7 @@ fn check_error_codes_used(
388384

389385
if !error_codes.contains(&error_code) {
390386
// This error code isn't properly defined, we must error.
391-
errors.push(format!("Error code `{}` is used in the compiler but not defined and documented in `compiler/rustc_error_codes/src/lib.rs`.", error_code));
387+
errors.push(format!("Error code `{error_code}` is used in the compiler but not defined and documented in `compiler/rustc_error_codes/src/lib.rs`."));
392388
continue;
393389
}
394390

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ fn check_impl(
6464
extra_checks: Option<&str>,
6565
pos_args: &[String],
6666
) -> Result<(), Error> {
67-
let show_diff = std::env::var("TIDY_PRINT_DIFF")
68-
.map_or(false, |v| v.eq_ignore_ascii_case("true") || v == "1");
67+
let show_diff =
68+
std::env::var("TIDY_PRINT_DIFF").is_ok_and(|v| v.eq_ignore_ascii_case("true") || v == "1");
6969

7070
// Split comma-separated args up
7171
let lint_args = match extra_checks {
@@ -141,7 +141,7 @@ fn check_impl(
141141
);
142142
}
143143
// Rethrow error
144-
let _ = res?;
144+
res?;
145145
}
146146

147147
if python_fmt {
@@ -173,7 +173,7 @@ fn check_impl(
173173
}
174174

175175
// Rethrow error
176-
let _ = res?;
176+
res?;
177177
}
178178

179179
if cpp_fmt {
@@ -244,7 +244,7 @@ fn check_impl(
244244
}
245245
}
246246
// Rethrow error
247-
let _ = res?;
247+
res?;
248248
}
249249

250250
if shell_lint {
@@ -286,8 +286,8 @@ fn run_ruff(
286286
file_args: &[&OsStr],
287287
ruff_args: &[&OsStr],
288288
) -> Result<(), Error> {
289-
let mut cfg_args_ruff = cfg_args.into_iter().copied().collect::<Vec<_>>();
290-
let mut file_args_ruff = file_args.into_iter().copied().collect::<Vec<_>>();
289+
let mut cfg_args_ruff = cfg_args.to_vec();
290+
let mut file_args_ruff = file_args.to_vec();
291291

292292
let mut cfg_path = root_path.to_owned();
293293
cfg_path.extend(RUFF_CONFIG_PATH);
@@ -305,7 +305,7 @@ fn run_ruff(
305305
file_args_ruff.push(root_path.as_os_str());
306306
}
307307

308-
let mut args: Vec<&OsStr> = ruff_args.into_iter().copied().collect();
308+
let mut args: Vec<&OsStr> = ruff_args.to_vec();
309309
args.extend(merge_args(&cfg_args_ruff, &file_args_ruff));
310310
py_runner(py_path, true, None, "ruff", &args)
311311
}

src/tools/tidy/src/extdeps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn check(root: &Path, bad: &mut bool) {
4141
let source = line.split_once('=').unwrap().1.trim();
4242

4343
// Ensure source is allowed.
44-
if !ALLOWED_SOURCES.contains(&&*source) {
44+
if !ALLOWED_SOURCES.contains(&source) {
4545
tidy_error!(bad, "invalid source: {}", source);
4646
}
4747
}

src/tools/tidy/src/features.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pub fn check(
125125
let gate_test_str = "gate-test-";
126126

127127
let feature_name = match line.find(gate_test_str) {
128-
// NB: the `splitn` always succeeds, even if the delimiter is not present.
129-
Some(i) => line[i + gate_test_str.len()..].splitn(2, ' ').next().unwrap(),
128+
// `split` always contains at least 1 element, even if the delimiter is not present.
129+
Some(i) => line[i + gate_test_str.len()..].split(' ').next().unwrap(),
130130
None => continue,
131131
};
132132
match features.get_mut(feature_name) {
@@ -135,16 +135,14 @@ pub fn check(
135135
err(&format!(
136136
"The file is already marked as gate test \
137137
through its name, no need for a \
138-
'gate-test-{}' comment",
139-
feature_name
138+
'gate-test-{feature_name}' comment"
140139
));
141140
}
142141
f.has_gate_test = true;
143142
}
144143
None => {
145144
err(&format!(
146-
"gate-test test found referencing a nonexistent feature '{}'",
147-
feature_name
145+
"gate-test test found referencing a nonexistent feature '{feature_name}'"
148146
));
149147
}
150148
}
@@ -170,8 +168,7 @@ pub fn check(
170168
);
171169
println!(
172170
"Hint: If you already have such a test and don't want to rename it,\
173-
\n you can also add a // gate-test-{} line to the test file.",
174-
name
171+
\n you can also add a // gate-test-{name} line to the test file."
175172
);
176173
}
177174

@@ -231,7 +228,7 @@ pub fn check(
231228
fn get_version_and_channel(src_path: &Path) -> (Version, String) {
232229
let version_str = t!(std::fs::read_to_string(src_path.join("version")));
233230
let version_str = version_str.trim();
234-
let version = t!(std::str::FromStr::from_str(&version_str).map_err(|e| format!("{e:?}")));
231+
let version = t!(std::str::FromStr::from_str(version_str).map_err(|e| format!("{e:?}")));
235232
let channel_str = t!(std::fs::read_to_string(src_path.join("ci").join("channel")));
236233
(version, channel_str.trim().to_owned())
237234
}
@@ -468,7 +465,7 @@ fn get_and_check_lib_features(
468465
map_lib_features(base_src_path, &mut |res, file, line| match res {
469466
Ok((name, f)) => {
470467
let mut check_features = |f: &Feature, list: &Features, display: &str| {
471-
if let Some(ref s) = list.get(name) {
468+
if let Some(s) = list.get(name) {
472469
if f.tracking_issue != s.tracking_issue && f.level != Status::Accepted {
473470
tidy_error!(
474471
bad,
@@ -483,7 +480,7 @@ fn get_and_check_lib_features(
483480
}
484481
}
485482
};
486-
check_features(&f, &lang_features, "corresponding lang feature");
483+
check_features(&f, lang_features, "corresponding lang feature");
487484
check_features(&f, &lib_features, "previous");
488485
lib_features.insert(name.to_owned(), f);
489486
}
@@ -543,7 +540,7 @@ fn map_lib_features(
543540
continue;
544541
}
545542

546-
if let Some((ref name, ref mut f)) = becoming_feature {
543+
if let Some((name, ref mut f)) = becoming_feature {
547544
if f.tracking_issue.is_none() {
548545
f.tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
549546
}

src/tools/tidy/src/features/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl fmt::Display for Version {
2020
Version::Explicit { parts } => {
2121
f.pad(&format!("{}.{}.{}", parts[0], parts[1], parts[2]))
2222
}
23-
Version::CurrentPlaceholder => f.pad(&format!("CURRENT")),
23+
Version::CurrentPlaceholder => f.pad("CURRENT"),
2424
}
2525
}
2626
}

src/tools/tidy/src/features/version/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ fn test_to_string() {
3333

3434
assert_eq!(v_1_0_0.to_string(), "1.0.0");
3535
assert_eq!(v_1_32_1.to_string(), "1.32.1");
36-
assert_eq!(format!("{:<8}", v_1_32_1), "1.32.1 ");
37-
assert_eq!(format!("{:>8}", v_1_32_1), " 1.32.1");
36+
assert_eq!(format!("{v_1_32_1:<8}"), "1.32.1 ");
37+
assert_eq!(format!("{v_1_32_1:>8}"), " 1.32.1");
3838
}

0 commit comments

Comments
 (0)