Skip to content

Commit 5b72e72

Browse files
committed
compiletest: apply considerable clippy suggestions
Signed-off-by: onur-ozkan <[email protected]>
1 parent a330e49 commit 5b72e72

File tree

9 files changed

+51
-56
lines changed

9 files changed

+51
-56
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 12 deletions
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

@@ -376,7 +376,7 @@ impl TestProps {
376376
// Individual flags can be single-quoted to preserve spaces; see
377377
// <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
378378
flags
379-
.split("'")
379+
.split('\'')
380380
.enumerate()
381381
.flat_map(|(i, f)| {
382382
if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
@@ -602,7 +602,7 @@ impl TestProps {
602602

603603
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
604604
if let Ok(val) = env::var(key) {
605-
if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
605+
if !self.exec_env.iter().any(|&(ref x, _)| x == key) {
606606
self.exec_env.push(((*key).to_owned(), val))
607607
}
608608
}
@@ -978,7 +978,7 @@ pub(crate) fn check_directive(directive_ln: &str) -> CheckDirectiveResult<'_> {
978978
let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
979979
let trailing_directive = {
980980
// 1. is the directive name followed by a space? (to exclude `:`)
981-
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(" "))
981+
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(' '))
982982
// 2. is what is after that directive also a directive (ex: "only-x86 only-arm")
983983
&& KNOWN_DIRECTIVE_NAMES.contains(&trailing)
984984
}
@@ -1330,7 +1330,7 @@ pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<u32> {
13301330
}
13311331
let version = String::from_utf8(output.stdout).ok()?;
13321332
for line in version.lines() {
1333-
if let Some(version) = line.split("LLVM version ").skip(1).next() {
1333+
if let Some(version) = line.split("LLVM version ").nth(1) {
13341334
return extract_llvm_version(version);
13351335
}
13361336
}
@@ -1361,7 +1361,7 @@ where
13611361

13621362
let min = parse(min)?;
13631363
let max = match max {
1364-
Some(max) if max.is_empty() => return None,
1364+
Some("") => return None,
13651365
Some(max) => parse(max)?,
13661366
_ => min,
13671367
};
@@ -1433,12 +1433,12 @@ pub fn make_test_description<R: Read>(
14331433
decision!(ignore_gdb(config, ln));
14341434
decision!(ignore_lldb(config, ln));
14351435

1436-
if config.target == "wasm32-unknown-unknown" {
1437-
if config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS) {
1438-
decision!(IgnoreDecision::Ignore {
1439-
reason: "ignored on WASM as the run results cannot be checked there".into(),
1440-
});
1441-
}
1436+
if config.target == "wasm32-unknown-unknown"
1437+
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS)
1438+
{
1439+
decision!(IgnoreDecision::Ignore {
1440+
reason: "ignored on WASM as the run results cannot be checked there".into(),
1441+
});
14421442
}
14431443

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 25 additions & 29 deletions
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>) {
@@ -2498,8 +2498,8 @@ impl<'test> TestCx<'test> {
24982498
// This works with both `--emit asm` (as default output name for the assembly)
24992499
// and `ptx-linker` because the latter can write output at requested location.
25002500
let output_path = self.output_base_name().with_extension(extension);
2501-
let output_file = TargetLocation::ThisFile(output_path.clone());
2502-
output_file
2501+
2502+
TargetLocation::ThisFile(output_path.clone())
25032503
}
25042504
}
25052505

@@ -2746,7 +2746,7 @@ impl<'test> TestCx<'test> {
27462746
for entry in walkdir::WalkDir::new(dir) {
27472747
let entry = entry.expect("failed to read file");
27482748
if entry.file_type().is_file()
2749-
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
2749+
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html")
27502750
{
27512751
let status =
27522752
Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
@@ -2777,8 +2777,7 @@ impl<'test> TestCx<'test> {
27772777
&compare_dir,
27782778
self.config.verbose,
27792779
|file_type, extension| {
2780-
file_type.is_file()
2781-
&& (extension == Some("html".into()) || extension == Some("js".into()))
2780+
file_type.is_file() && (extension == Some("html") || extension == Some("js"))
27822781
},
27832782
) {
27842783
return;
@@ -2824,11 +2823,11 @@ impl<'test> TestCx<'test> {
28242823
}
28252824
match String::from_utf8(line.clone()) {
28262825
Ok(line) => {
2827-
if line.starts_with("+") {
2826+
if line.starts_with('+') {
28282827
write!(&mut out, "{}", line.green()).unwrap();
2829-
} else if line.starts_with("-") {
2828+
} else if line.starts_with('-') {
28302829
write!(&mut out, "{}", line.red()).unwrap();
2831-
} else if line.starts_with("@") {
2830+
} else if line.starts_with('@') {
28322831
write!(&mut out, "{}", line.blue()).unwrap();
28332832
} else {
28342833
out.write_all(line.as_bytes()).unwrap();
@@ -2901,7 +2900,7 @@ impl<'test> TestCx<'test> {
29012900
&& line.ends_with(';')
29022901
{
29032902
if let Some(ref mut other_files) = other_files {
2904-
other_files.push(line.rsplit("mod ").next().unwrap().replace(";", ""));
2903+
other_files.push(line.rsplit("mod ").next().unwrap().replace(';', ""));
29052904
}
29062905
None
29072906
} else {
@@ -3133,7 +3132,7 @@ impl<'test> TestCx<'test> {
31333132
let mut string = String::new();
31343133
for cgu in cgus {
31353134
string.push_str(&cgu[..]);
3136-
string.push_str(" ");
3135+
string.push(' ');
31373136
}
31383137

31393138
string
@@ -3166,10 +3165,7 @@ impl<'test> TestCx<'test> {
31663165
// CGUs joined with "--". This function splits such composite CGU names
31673166
// and handles each component individually.
31683167
fn remove_crate_disambiguators_from_set_of_cgu_names(cgus: &str) -> String {
3169-
cgus.split("--")
3170-
.map(|cgu| remove_crate_disambiguator_from_cgu(cgu))
3171-
.collect::<Vec<_>>()
3172-
.join("--")
3168+
cgus.split("--").map(remove_crate_disambiguator_from_cgu).collect::<Vec<_>>().join("--")
31733169
}
31743170
}
31753171

@@ -3351,7 +3347,7 @@ impl<'test> TestCx<'test> {
33513347
// endif
33523348
}
33533349

3354-
if self.config.target.contains("msvc") && self.config.cc != "" {
3350+
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
33553351
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
33563352
// and that `lib.exe` lives next to it.
33573353
let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
@@ -3629,7 +3625,7 @@ impl<'test> TestCx<'test> {
36293625
// endif
36303626
}
36313627

3632-
if self.config.target.contains("msvc") && self.config.cc != "" {
3628+
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
36333629
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
36343630
// and that `lib.exe` lives next to it.
36353631
let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
@@ -3820,7 +3816,7 @@ impl<'test> TestCx<'test> {
38203816
&& !self.props.dont_check_compiler_stderr
38213817
{
38223818
self.fatal_proc_rec(
3823-
&format!("compiler output got truncated, cannot compare with reference file"),
3819+
"compiler output got truncated, cannot compare with reference file",
38243820
&proc_res,
38253821
);
38263822
}
@@ -4001,8 +3997,8 @@ impl<'test> TestCx<'test> {
40013997
crate_name.to_str().expect("crate name implies file name must be valid UTF-8");
40023998
// replace `a.foo` -> `a__foo` for crate name purposes.
40033999
// replace `revision-name-with-dashes` -> `revision_name_with_underscore`
4004-
let crate_name = crate_name.replace(".", "__");
4005-
let crate_name = crate_name.replace("-", "_");
4000+
let crate_name = crate_name.replace('.', "__");
4001+
let crate_name = crate_name.replace('-', "_");
40064002
rustc.arg("--crate-name");
40074003
rustc.arg(crate_name);
40084004
}
@@ -4050,7 +4046,7 @@ impl<'test> TestCx<'test> {
40504046
fn check_mir_dump(&self, test_info: MiroptTest) {
40514047
let test_dir = self.testpaths.file.parent().unwrap();
40524048
let test_crate =
4053-
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");
4049+
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace('-', "_");
40544050

40554051
let MiroptTest { run_filecheck, suffix, files, passes: _ } = test_info;
40564052

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

Lines changed: 1 addition & 1 deletion
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
}

src/tools/compiletest/src/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ fn test_extract_lldb_version() {
5858

5959
#[test]
6060
fn is_test_test() {
61-
assert_eq!(true, is_test(&OsString::from("a_test.rs")));
62-
assert_eq!(false, is_test(&OsString::from(".a_test.rs")));
63-
assert_eq!(false, is_test(&OsString::from("a_cat.gif")));
64-
assert_eq!(false, is_test(&OsString::from("#a_dog_gif")));
65-
assert_eq!(false, is_test(&OsString::from("~a_temp_file")));
61+
assert!(is_test(&OsString::from("a_test.rs")));
62+
assert!(!is_test(&OsString::from(".a_test.rs")));
63+
assert!(!is_test(&OsString::from("a_cat.gif")));
64+
assert!(!is_test(&OsString::from("#a_dog_gif")));
65+
assert!(!is_test(&OsString::from("~a_temp_file")));
6666
}
6767

6868
#[test]

0 commit comments

Comments
 (0)