Skip to content

Commit 0d82ff0

Browse files
authored
Unrolled build for rust-lang#126088
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 0ef0dd2 + c8d2b93 commit 0d82ff0

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
@@ -82,7 +82,7 @@ impl EarlyProps {
8282
panic!("errors encountered during EarlyProps parsing");
8383
}
8484

85-
return props;
85+
props
8686
}
8787
}
8888

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

614614
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
615615
if let Ok(val) = env::var(key) {
616-
if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
616+
if !self.exec_env.iter().any(|&(ref x, _)| x == key) {
617617
self.exec_env.push(((*key).to_owned(), val))
618618
}
619619
}
@@ -991,7 +991,7 @@ pub(crate) fn check_directive(directive_ln: &str) -> CheckDirectiveResult<'_> {
991991
let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
992992
let trailing_directive = {
993993
// 1. is the directive name followed by a space? (to exclude `:`)
994-
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(" "))
994+
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(' '))
995995
// 2. is what is after that directive also a directive (ex: "only-x86 only-arm")
996996
&& KNOWN_DIRECTIVE_NAMES.contains(&trailing)
997997
}
@@ -1363,7 +1363,7 @@ pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<u32> {
13631363
}
13641364
let version = String::from_utf8(output.stdout).ok()?;
13651365
for line in version.lines() {
1366-
if let Some(version) = line.split("LLVM version ").skip(1).next() {
1366+
if let Some(version) = line.split("LLVM version ").nth(1) {
13671367
return extract_llvm_version(version);
13681368
}
13691369
}
@@ -1394,7 +1394,7 @@ where
13941394

13951395
let min = parse(min)?;
13961396
let max = match max {
1397-
Some(max) if max.is_empty() => return None,
1397+
Some("") => return None,
13981398
Some(max) => parse(max)?,
13991399
_ => min,
14001400
};
@@ -1466,12 +1466,12 @@ pub fn make_test_description<R: Read>(
14661466
decision!(ignore_gdb(config, ln));
14671467
decision!(ignore_lldb(config, ln));
14681468

1469-
if config.target == "wasm32-unknown-unknown" {
1470-
if config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS) {
1471-
decision!(IgnoreDecision::Ignore {
1472-
reason: "ignored on WASM as the run results cannot be checked there".into(),
1473-
});
1474-
}
1469+
if config.target == "wasm32-unknown-unknown"
1470+
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS)
1471+
{
1472+
decision!(IgnoreDecision::Ignore {
1473+
reason: "ignored on WASM as the run results cannot be checked there".into(),
1474+
});
14751475
}
14761476

14771477
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
@@ -374,11 +374,11 @@ impl<'test> TestCx<'test> {
374374

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

@@ -697,10 +697,10 @@ impl<'test> TestCx<'test> {
697697
// since it is extensively used in the testsuite.
698698
check_cfg.push_str("cfg(FALSE");
699699
for revision in &self.props.revisions {
700-
check_cfg.push_str(",");
701-
check_cfg.push_str(&normalize_revision(&revision));
700+
check_cfg.push(',');
701+
check_cfg.push_str(&normalize_revision(revision));
702702
}
703-
check_cfg.push_str(")");
703+
check_cfg.push(')');
704704

705705
cmd.args(&["--check-cfg", &check_cfg]);
706706
}
@@ -818,7 +818,7 @@ impl<'test> TestCx<'test> {
818818
// Append the other `cdb-command:`s
819819
for line in &dbg_cmds.commands {
820820
script_str.push_str(line);
821-
script_str.push_str("\n");
821+
script_str.push('\n');
822822
}
823823

824824
script_str.push_str("qq\n"); // Quit the debugger (including remote debugger, if any)
@@ -1200,7 +1200,7 @@ impl<'test> TestCx<'test> {
12001200
// Append the other commands
12011201
for line in &dbg_cmds.commands {
12021202
script_str.push_str(line);
1203-
script_str.push_str("\n");
1203+
script_str.push('\n');
12041204
}
12051205

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

1253-
options.iter().filter(|x| !options_to_remove.contains(x)).map(|x| x.clone()).collect()
1253+
options.iter().filter(|x| !options_to_remove.contains(x)).cloned().collect()
12541254
}
12551255

12561256
fn maybe_add_external_args(&self, cmd: &mut Command, args: &Vec<String>) {
@@ -2504,8 +2504,8 @@ impl<'test> TestCx<'test> {
25042504
// This works with both `--emit asm` (as default output name for the assembly)
25052505
// and `ptx-linker` because the latter can write output at requested location.
25062506
let output_path = self.output_base_name().with_extension(extension);
2507-
let output_file = TargetLocation::ThisFile(output_path.clone());
2508-
output_file
2507+
2508+
TargetLocation::ThisFile(output_path.clone())
25092509
}
25102510
}
25112511

@@ -2752,7 +2752,7 @@ impl<'test> TestCx<'test> {
27522752
for entry in walkdir::WalkDir::new(dir) {
27532753
let entry = entry.expect("failed to read file");
27542754
if entry.file_type().is_file()
2755-
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
2755+
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html")
27562756
{
27572757
let status =
27582758
Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
@@ -2783,8 +2783,7 @@ impl<'test> TestCx<'test> {
27832783
&compare_dir,
27842784
self.config.verbose,
27852785
|file_type, extension| {
2786-
file_type.is_file()
2787-
&& (extension == Some("html".into()) || extension == Some("js".into()))
2786+
file_type.is_file() && (extension == Some("html") || extension == Some("js"))
27882787
},
27892788
) {
27902789
return;
@@ -2830,11 +2829,11 @@ impl<'test> TestCx<'test> {
28302829
}
28312830
match String::from_utf8(line.clone()) {
28322831
Ok(line) => {
2833-
if line.starts_with("+") {
2832+
if line.starts_with('+') {
28342833
write!(&mut out, "{}", line.green()).unwrap();
2835-
} else if line.starts_with("-") {
2834+
} else if line.starts_with('-') {
28362835
write!(&mut out, "{}", line.red()).unwrap();
2837-
} else if line.starts_with("@") {
2836+
} else if line.starts_with('@') {
28382837
write!(&mut out, "{}", line.blue()).unwrap();
28392838
} else {
28402839
out.write_all(line.as_bytes()).unwrap();
@@ -2907,7 +2906,7 @@ impl<'test> TestCx<'test> {
29072906
&& line.ends_with(';')
29082907
{
29092908
if let Some(ref mut other_files) = other_files {
2910-
other_files.push(line.rsplit("mod ").next().unwrap().replace(";", ""));
2909+
other_files.push(line.rsplit("mod ").next().unwrap().replace(';', ""));
29112910
}
29122911
None
29132912
} else {
@@ -3139,7 +3138,7 @@ impl<'test> TestCx<'test> {
31393138
let mut string = String::new();
31403139
for cgu in cgus {
31413140
string.push_str(&cgu[..]);
3142-
string.push_str(" ");
3141+
string.push(' ');
31433142
}
31443143

31453144
string
@@ -3172,10 +3171,7 @@ impl<'test> TestCx<'test> {
31723171
// CGUs joined with "--". This function splits such composite CGU names
31733172
// and handles each component individually.
31743173
fn remove_crate_disambiguators_from_set_of_cgu_names(cgus: &str) -> String {
3175-
cgus.split("--")
3176-
.map(|cgu| remove_crate_disambiguator_from_cgu(cgu))
3177-
.collect::<Vec<_>>()
3178-
.join("--")
3174+
cgus.split("--").map(remove_crate_disambiguator_from_cgu).collect::<Vec<_>>().join("--")
31793175
}
31803176
}
31813177

@@ -3357,7 +3353,7 @@ impl<'test> TestCx<'test> {
33573353
// endif
33583354
}
33593355

3360-
if self.config.target.contains("msvc") && self.config.cc != "" {
3356+
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
33613357
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
33623358
// and that `lib.exe` lives next to it.
33633359
let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
@@ -3639,7 +3635,7 @@ impl<'test> TestCx<'test> {
36393635
// endif
36403636
}
36413637

3642-
if self.config.target.contains("msvc") && self.config.cc != "" {
3638+
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
36433639
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
36443640
// and that `lib.exe` lives next to it.
36453641
let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
@@ -3830,7 +3826,7 @@ impl<'test> TestCx<'test> {
38303826
&& !self.props.dont_check_compiler_stderr
38313827
{
38323828
self.fatal_proc_rec(
3833-
&format!("compiler output got truncated, cannot compare with reference file"),
3829+
"compiler output got truncated, cannot compare with reference file",
38343830
&proc_res,
38353831
);
38363832
}
@@ -4011,8 +4007,8 @@ impl<'test> TestCx<'test> {
40114007
crate_name.to_str().expect("crate name implies file name must be valid UTF-8");
40124008
// replace `a.foo` -> `a__foo` for crate name purposes.
40134009
// replace `revision-name-with-dashes` -> `revision_name_with_underscore`
4014-
let crate_name = crate_name.replace(".", "__");
4015-
let crate_name = crate_name.replace("-", "_");
4010+
let crate_name = crate_name.replace('.', "__");
4011+
let crate_name = crate_name.replace('-', "_");
40164012
rustc.arg("--crate-name");
40174013
rustc.arg(crate_name);
40184014
}
@@ -4060,7 +4056,7 @@ impl<'test> TestCx<'test> {
40604056
fn check_mir_dump(&self, test_info: MiroptTest) {
40614057
let test_dir = self.testpaths.file.parent().unwrap();
40624058
let test_crate =
4063-
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");
4059+
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace('-', "_");
40644060

40654061
let MiroptTest { run_filecheck, suffix, files, passes: _ } = test_info;
40664062

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)