Skip to content

Commit cc65413

Browse files
committed
compiletest: apply considerable clippy suggestions
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 9fdbfe1 commit cc65413

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
@@ -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

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
@@ -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

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)