Skip to content

Commit c2399cd

Browse files
authored
Rollup merge of rust-lang#126088 - onur-ozkan:brooming, r=albertlarsan68
[1/2] clean-up / general improvements This PR applies various clippy suggestions on the tools. I have only applied the ones that make sense and left out trivial changes (e.g., suggestions like 'remove &' are ignored to keep the original commit history for the lines). I am planning to do the same for the library and compiler, but those will add too many changes to this PR, so I will handle them in a separate PR later.
2 parents f20fc59 + eaa45c8 commit c2399cd

File tree

26 files changed

+139
-160
lines changed

26 files changed

+139
-160
lines changed

src/bootstrap/src/core/build_steps/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn get_modified_rs_files(build: &Builder<'_>) -> Result<Option<Vec<String>>, Str
9393
return Ok(None);
9494
}
9595

96-
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &vec!["rs"])
96+
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"])
9797
}
9898

9999
#[derive(serde_derive::Deserialize)]

src/tools/build-manifest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl Builder {
495495
Some(p) => p,
496496
None => return false,
497497
};
498-
pkg.target.get(&c.target).is_some()
498+
pkg.target.contains_key(&c.target)
499499
};
500500
extensions.retain(&has_component);
501501
components.retain(&has_component);

src/tools/build_helper/src/git.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn output_result(cmd: &mut Command) -> Result<String, String> {
2121
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
2222
));
2323
}
24-
Ok(String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))?)
24+
String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))
2525
}
2626

2727
/// Finds the remote for rust-lang/rust.
@@ -64,18 +64,14 @@ pub fn rev_exists(rev: &str, git_dir: Option<&Path>) -> Result<bool, String> {
6464
match output.status.code() {
6565
Some(0) => Ok(true),
6666
Some(128) => Ok(false),
67-
None => {
68-
return Err(format!(
69-
"git didn't exit properly: {}",
70-
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
71-
));
72-
}
73-
Some(code) => {
74-
return Err(format!(
75-
"git command exited with status code: {code}: {}",
76-
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
77-
));
78-
}
67+
None => Err(format!(
68+
"git didn't exit properly: {}",
69+
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
70+
)),
71+
Some(code) => Err(format!(
72+
"git command exited with status code: {code}: {}",
73+
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
74+
)),
7975
}
8076
}
8177

@@ -96,7 +92,7 @@ pub fn updated_master_branch(
9692
}
9793
}
9894

99-
Err(format!("Cannot find any suitable upstream master branch"))
95+
Err("Cannot find any suitable upstream master branch".to_owned())
10096
}
10197

10298
pub fn get_git_merge_base(
@@ -118,7 +114,7 @@ pub fn get_git_merge_base(
118114
pub fn get_git_modified_files(
119115
config: &GitConfig<'_>,
120116
git_dir: Option<&Path>,
121-
extensions: &Vec<&str>,
117+
extensions: &[&str],
122118
) -> Result<Option<Vec<String>>, String> {
123119
let merge_base = get_git_merge_base(config, git_dir)?;
124120

src/tools/compiletest/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl TargetCfgs {
582582
name,
583583
Some(
584584
value
585-
.strip_suffix("\"")
585+
.strip_suffix('\"')
586586
.expect("key-value pair should be properly quoted"),
587587
),
588588
)

src/tools/compiletest/src/header.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl EarlyProps {
8181
panic!("errors encountered during EarlyProps parsing");
8282
}
8383

84-
return props;
84+
props
8585
}
8686
}
8787

@@ -381,7 +381,7 @@ impl TestProps {
381381
// Individual flags can be single-quoted to preserve spaces; see
382382
// <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
383383
flags
384-
.split("'")
384+
.split('\'')
385385
.enumerate()
386386
.flat_map(|(i, f)| {
387387
if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
@@ -612,7 +612,7 @@ impl TestProps {
612612

613613
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
614614
if let Ok(val) = env::var(key) {
615-
if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
615+
if !self.exec_env.iter().any(|&(ref x, _)| x == key) {
616616
self.exec_env.push(((*key).to_owned(), val))
617617
}
618618
}
@@ -990,7 +990,7 @@ pub(crate) fn check_directive(directive_ln: &str) -> CheckDirectiveResult<'_> {
990990
let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
991991
let trailing_directive = {
992992
// 1. is the directive name followed by a space? (to exclude `:`)
993-
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(" "))
993+
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(' '))
994994
// 2. is what is after that directive also a directive (ex: "only-x86 only-arm")
995995
&& KNOWN_DIRECTIVE_NAMES.contains(&trailing)
996996
}
@@ -1354,7 +1354,7 @@ pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<u32> {
13541354
}
13551355
let version = String::from_utf8(output.stdout).ok()?;
13561356
for line in version.lines() {
1357-
if let Some(version) = line.split("LLVM version ").skip(1).next() {
1357+
if let Some(version) = line.split("LLVM version ").nth(1) {
13581358
return extract_llvm_version(version);
13591359
}
13601360
}
@@ -1385,7 +1385,7 @@ where
13851385

13861386
let min = parse(min)?;
13871387
let max = match max {
1388-
Some(max) if max.is_empty() => return None,
1388+
Some("") => return None,
13891389
Some(max) => parse(max)?,
13901390
_ => min,
13911391
};
@@ -1457,12 +1457,12 @@ pub fn make_test_description<R: Read>(
14571457
decision!(ignore_gdb(config, ln));
14581458
decision!(ignore_lldb(config, ln));
14591459

1460-
if config.target == "wasm32-unknown-unknown" {
1461-
if config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS) {
1462-
decision!(IgnoreDecision::Ignore {
1463-
reason: "ignored on WASM as the run results cannot be checked there".into(),
1464-
});
1465-
}
1460+
if config.target == "wasm32-unknown-unknown"
1461+
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS)
1462+
{
1463+
decision!(IgnoreDecision::Ignore {
1464+
reason: "ignored on WASM as the run results cannot be checked there".into(),
1465+
});
14661466
}
14671467

14681468
should_fail |= config.parse_name_directive(ln, "should-fail");

src/tools/compiletest/src/header/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
5858

5959
// Some of the matchers might be "" depending on what the target information is. To avoid
6060
// problems we outright reject empty directives.
61-
if name == "" {
61+
if name.is_empty() {
6262
return ParsedNameDirective::not_a_directive();
6363
}
6464

src/tools/compiletest/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
11471147
}
11481148

11491149
fn not_a_digit(c: char) -> bool {
1150-
!c.is_digit(10)
1150+
!c.is_ascii_digit()
11511151
}
11521152

11531153
fn check_overlapping_tests(found_paths: &HashSet<PathBuf>) {

src/tools/compiletest/src/read2.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod tests;
66

77
pub use self::imp::read2;
88
use std::io::{self, Write};
9-
use std::mem::replace;
109
use std::process::{Child, Output};
1110

1211
#[derive(Copy, Clone, Debug)]
@@ -101,10 +100,10 @@ impl ProcOutput {
101100
return;
102101
}
103102

104-
let mut head = replace(bytes, Vec::new());
103+
let mut head = std::mem::take(bytes);
105104
// Don't truncate if this as a whole line.
106105
// That should make it less likely that we cut a JSON line in half.
107-
if head.last() != Some(&('\n' as u8)) {
106+
if head.last() != Some(&b'\n') {
108107
head.truncate(MAX_OUT_LEN);
109108
}
110109
let skipped = new_len - head.len();

src/tools/compiletest/src/read2/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ fn test_abbreviate_filterss_are_detected() {
6464
#[test]
6565
fn test_abbreviate_filters_avoid_abbreviations() {
6666
let mut out = ProcOutput::new();
67-
let filters = &[std::iter::repeat('a').take(64).collect::<String>()];
67+
let filters = &["a".repeat(64)];
6868

69-
let mut expected = vec![b'.'; MAX_OUT_LEN - FILTERED_PATHS_PLACEHOLDER_LEN as usize];
69+
let mut expected = vec![b'.'; MAX_OUT_LEN - FILTERED_PATHS_PLACEHOLDER_LEN];
7070
expected.extend_from_slice(filters[0].as_bytes());
7171

7272
out.extend(&expected, filters);
@@ -81,7 +81,7 @@ fn test_abbreviate_filters_avoid_abbreviations() {
8181
#[test]
8282
fn test_abbreviate_filters_can_still_cause_abbreviations() {
8383
let mut out = ProcOutput::new();
84-
let filters = &[std::iter::repeat('a').take(64).collect::<String>()];
84+
let filters = &["a".repeat(64)];
8585

8686
let mut input = vec![b'.'; MAX_OUT_LEN];
8787
input.extend_from_slice(filters[0].as_bytes());

src/tools/compiletest/src/runtest.rs

+25-29
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ impl<'test> TestCx<'test> {
382382

383383
// if a test does not crash, consider it an error
384384
if proc_res.status.success() || matches!(proc_res.status.code(), Some(1 | 0)) {
385-
self.fatal(&format!(
385+
self.fatal(
386386
"test no longer crashes/triggers ICE! Please give it a mearningful name, \
387387
add a doc-comment to the start of the test explaining why it exists and \
388-
move it to tests/ui or wherever you see fit."
389-
));
388+
move it to tests/ui or wherever you see fit.",
389+
);
390390
}
391391
}
392392

@@ -705,10 +705,10 @@ impl<'test> TestCx<'test> {
705705
// since it is extensively used in the testsuite.
706706
check_cfg.push_str("cfg(FALSE");
707707
for revision in &self.props.revisions {
708-
check_cfg.push_str(",");
709-
check_cfg.push_str(&normalize_revision(&revision));
708+
check_cfg.push(',');
709+
check_cfg.push_str(&normalize_revision(revision));
710710
}
711-
check_cfg.push_str(")");
711+
check_cfg.push(')');
712712

713713
cmd.args(&["--check-cfg", &check_cfg]);
714714
}
@@ -826,7 +826,7 @@ impl<'test> TestCx<'test> {
826826
// Append the other `cdb-command:`s
827827
for line in &dbg_cmds.commands {
828828
script_str.push_str(line);
829-
script_str.push_str("\n");
829+
script_str.push('\n');
830830
}
831831

832832
script_str.push_str("qq\n"); // Quit the debugger (including remote debugger, if any)
@@ -1208,7 +1208,7 @@ impl<'test> TestCx<'test> {
12081208
// Append the other commands
12091209
for line in &dbg_cmds.commands {
12101210
script_str.push_str(line);
1211-
script_str.push_str("\n");
1211+
script_str.push('\n');
12121212
}
12131213

12141214
// Finally, quit the debugger
@@ -1258,7 +1258,7 @@ impl<'test> TestCx<'test> {
12581258
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
12591259
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
12601260

1261-
options.iter().filter(|x| !options_to_remove.contains(x)).map(|x| x.clone()).collect()
1261+
options.iter().filter(|x| !options_to_remove.contains(x)).cloned().collect()
12621262
}
12631263

12641264
fn maybe_add_external_args(&self, cmd: &mut Command, args: &Vec<String>) {
@@ -2512,8 +2512,8 @@ impl<'test> TestCx<'test> {
25122512
// This works with both `--emit asm` (as default output name for the assembly)
25132513
// and `ptx-linker` because the latter can write output at requested location.
25142514
let output_path = self.output_base_name().with_extension(extension);
2515-
let output_file = TargetLocation::ThisFile(output_path.clone());
2516-
output_file
2515+
2516+
TargetLocation::ThisFile(output_path.clone())
25172517
}
25182518
}
25192519

@@ -2760,7 +2760,7 @@ impl<'test> TestCx<'test> {
27602760
for entry in walkdir::WalkDir::new(dir) {
27612761
let entry = entry.expect("failed to read file");
27622762
if entry.file_type().is_file()
2763-
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
2763+
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html")
27642764
{
27652765
let status =
27662766
Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
@@ -2791,8 +2791,7 @@ impl<'test> TestCx<'test> {
27912791
&compare_dir,
27922792
self.config.verbose,
27932793
|file_type, extension| {
2794-
file_type.is_file()
2795-
&& (extension == Some("html".into()) || extension == Some("js".into()))
2794+
file_type.is_file() && (extension == Some("html") || extension == Some("js"))
27962795
},
27972796
) {
27982797
return;
@@ -2838,11 +2837,11 @@ impl<'test> TestCx<'test> {
28382837
}
28392838
match String::from_utf8(line.clone()) {
28402839
Ok(line) => {
2841-
if line.starts_with("+") {
2840+
if line.starts_with('+') {
28422841
write!(&mut out, "{}", line.green()).unwrap();
2843-
} else if line.starts_with("-") {
2842+
} else if line.starts_with('-') {
28442843
write!(&mut out, "{}", line.red()).unwrap();
2845-
} else if line.starts_with("@") {
2844+
} else if line.starts_with('@') {
28462845
write!(&mut out, "{}", line.blue()).unwrap();
28472846
} else {
28482847
out.write_all(line.as_bytes()).unwrap();
@@ -2915,7 +2914,7 @@ impl<'test> TestCx<'test> {
29152914
&& line.ends_with(';')
29162915
{
29172916
if let Some(ref mut other_files) = other_files {
2918-
other_files.push(line.rsplit("mod ").next().unwrap().replace(";", ""));
2917+
other_files.push(line.rsplit("mod ").next().unwrap().replace(';', ""));
29192918
}
29202919
None
29212920
} else {
@@ -3147,7 +3146,7 @@ impl<'test> TestCx<'test> {
31473146
let mut string = String::new();
31483147
for cgu in cgus {
31493148
string.push_str(&cgu[..]);
3150-
string.push_str(" ");
3149+
string.push(' ');
31513150
}
31523151

31533152
string
@@ -3180,10 +3179,7 @@ impl<'test> TestCx<'test> {
31803179
// CGUs joined with "--". This function splits such composite CGU names
31813180
// and handles each component individually.
31823181
fn remove_crate_disambiguators_from_set_of_cgu_names(cgus: &str) -> String {
3183-
cgus.split("--")
3184-
.map(|cgu| remove_crate_disambiguator_from_cgu(cgu))
3185-
.collect::<Vec<_>>()
3186-
.join("--")
3182+
cgus.split("--").map(remove_crate_disambiguator_from_cgu).collect::<Vec<_>>().join("--")
31873183
}
31883184
}
31893185

@@ -3365,7 +3361,7 @@ impl<'test> TestCx<'test> {
33653361
// endif
33663362
}
33673363

3368-
if self.config.target.contains("msvc") && self.config.cc != "" {
3364+
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
33693365
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
33703366
// and that `lib.exe` lives next to it.
33713367
let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
@@ -3647,7 +3643,7 @@ impl<'test> TestCx<'test> {
36473643
// endif
36483644
}
36493645

3650-
if self.config.target.contains("msvc") && self.config.cc != "" {
3646+
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
36513647
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
36523648
// and that `lib.exe` lives next to it.
36533649
let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
@@ -3838,7 +3834,7 @@ impl<'test> TestCx<'test> {
38383834
&& !self.props.dont_check_compiler_stderr
38393835
{
38403836
self.fatal_proc_rec(
3841-
&format!("compiler output got truncated, cannot compare with reference file"),
3837+
"compiler output got truncated, cannot compare with reference file",
38423838
&proc_res,
38433839
);
38443840
}
@@ -4019,8 +4015,8 @@ impl<'test> TestCx<'test> {
40194015
crate_name.to_str().expect("crate name implies file name must be valid UTF-8");
40204016
// replace `a.foo` -> `a__foo` for crate name purposes.
40214017
// replace `revision-name-with-dashes` -> `revision_name_with_underscore`
4022-
let crate_name = crate_name.replace(".", "__");
4023-
let crate_name = crate_name.replace("-", "_");
4018+
let crate_name = crate_name.replace('.', "__");
4019+
let crate_name = crate_name.replace('-', "_");
40244020
rustc.arg("--crate-name");
40254021
rustc.arg(crate_name);
40264022
}
@@ -4068,7 +4064,7 @@ impl<'test> TestCx<'test> {
40684064
fn check_mir_dump(&self, test_info: MiroptTest) {
40694065
let test_dir = self.testpaths.file.parent().unwrap();
40704066
let test_crate =
4071-
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");
4067+
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace('-', "_");
40724068

40734069
let MiroptTest { run_filecheck, suffix, files, passes: _ } = test_info;
40744070

src/tools/compiletest/src/runtest/debugger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@ fn check_single_line(line: &str, check_line: &str) -> bool {
148148
rest = &rest[pos + current_fragment.len()..];
149149
}
150150

151-
if !can_end_anywhere && !rest.is_empty() { false } else { true }
151+
can_end_anywhere || rest.is_empty()
152152
}

0 commit comments

Comments
 (0)