Skip to content

Commit 4a92ae2

Browse files
committed
Auto merge of #42896 - llogiq:clippy_compiletest, r=alexcrichton
fixed some clippy warnings in compiletest This is mainly readability stuff. Whenever the `clone_ref` lint asked me to clone the dereferenced object, I removed the `.clone()` instead, relying on the fact that it has worked so far and the immutable borrow ensures that the value won't change.
2 parents 7d89b20 + 7be171d commit 4a92ae2

File tree

6 files changed

+79
-94
lines changed

6 files changed

+79
-94
lines changed

src/tools/compiletest/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl FromStr for ErrorKind {
3535
"ERROR" => Ok(ErrorKind::Error),
3636
"NOTE" => Ok(ErrorKind::Note),
3737
"SUGGESTION" => Ok(ErrorKind::Suggestion),
38-
"WARN" => Ok(ErrorKind::Warning),
38+
"WARN" |
3939
"WARNING" => Ok(ErrorKind::Warning),
4040
_ => Err(()),
4141
}
@@ -95,7 +95,7 @@ pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<Error> {
9595

9696
let tag = match cfg {
9797
Some(rev) => format!("//[{}]~", rev),
98-
None => format!("//~"),
98+
None => "//~".to_string(),
9999
};
100100

101101
rdr.lines()
@@ -153,7 +153,7 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
153153
let msg = msg.trim().to_owned();
154154

155155
let (which, line_num) = if follow {
156-
assert!(adjusts == 0, "use either //~| or //~^, not both.");
156+
assert_eq!(adjusts, 0, "use either //~| or //~^, not both.");
157157
let line_num = last_nonfollow_error.expect("encountered //~| without \
158158
preceding //~^ line.");
159159
(FollowPrevious(line_num), line_num)

src/tools/compiletest/src/header.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl TestProps {
258258
check_stdout: false,
259259
no_prefer_dynamic: false,
260260
pretty_expanded: false,
261-
pretty_mode: format!("normal"),
261+
pretty_mode: "normal".to_string(),
262262
pretty_compare_only: false,
263263
forbid_output: vec![],
264264
incremental_dir: None,
@@ -381,14 +381,11 @@ impl TestProps {
381381
}
382382
});
383383

384-
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
385-
match env::var(key) {
386-
Ok(val) => {
387-
if self.exec_env.iter().find(|&&(ref x, _)| *x == key).is_none() {
388-
self.exec_env.push((key.to_owned(), val))
389-
}
384+
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
385+
if let Ok(val) = env::var(key) {
386+
if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
387+
self.exec_env.push(((*key).to_owned(), val))
390388
}
391-
Err(..) => {}
392389
}
393390
}
394391
}
@@ -409,7 +406,7 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
409406
return;
410407
} else if ln.starts_with("//[") {
411408
// A comment like `//[foo]` is specific to revision `foo`
412-
if let Some(close_brace) = ln.find("]") {
409+
if let Some(close_brace) = ln.find(']') {
413410
let lncfg = &ln[3..close_brace];
414411
let matches = match cfg {
415412
Some(s) => s == &lncfg[..],
@@ -521,12 +518,10 @@ impl Config {
521518
fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option<PathBuf> {
522519
if let Some(s) = self.parse_name_value_directive(line, "pp-exact") {
523520
Some(PathBuf::from(&s))
521+
} else if self.parse_name_directive(line, "pp-exact") {
522+
testfile.file_name().map(PathBuf::from)
524523
} else {
525-
if self.parse_name_directive(line, "pp-exact") {
526-
testfile.file_name().map(PathBuf::from)
527-
} else {
528-
None
529-
}
524+
None
530525
}
531526
}
532527

@@ -554,9 +549,7 @@ impl Config {
554549
pub fn lldb_version_to_int(version_string: &str) -> isize {
555550
let error_string = format!("Encountered LLDB version string with unexpected format: {}",
556551
version_string);
557-
let error_string = error_string;
558-
let major: isize = version_string.parse().ok().expect(&error_string);
559-
return major;
552+
version_string.parse().expect(&error_string)
560553
}
561554

562555
fn expand_variables(mut value: String, config: &Config) -> String {

src/tools/compiletest/src/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Er
6565
fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
6666
// The compiler sometimes intermingles non-JSON stuff into the
6767
// output. This hack just skips over such lines. Yuck.
68-
if line.chars().next() == Some('{') {
68+
if line.starts_with('{') {
6969
match json::decode::<Diagnostic>(line) {
7070
Ok(diagnostic) => {
7171
let mut expected_errors = vec![];

src/tools/compiletest/src/main.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
168168
src_base: opt_path(matches, "src-base"),
169169
build_base: opt_path(matches, "build-base"),
170170
stage_id: matches.opt_str("stage-id").unwrap(),
171-
mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"),
171+
mode: matches.opt_str("mode").unwrap().parse().expect("invalid mode"),
172172
run_ignored: matches.opt_present("ignored"),
173173
filter: matches.free.first().cloned(),
174174
filter_exact: matches.opt_present("exact"),
@@ -208,7 +208,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
208208

209209
pub fn log_config(config: &Config) {
210210
let c = config;
211-
logv(c, format!("configuration:"));
211+
logv(c, "configuration:".to_string());
212212
logv(c, format!("compile_lib_path: {:?}", config.compile_lib_path));
213213
logv(c, format!("run_lib_path: {:?}", config.run_lib_path));
214214
logv(c, format!("rustc_path: {:?}", config.rustc_path.display()));
@@ -238,10 +238,10 @@ pub fn log_config(config: &Config) {
238238
config.adb_device_status));
239239
logv(c, format!("verbose: {}", config.verbose));
240240
logv(c, format!("quiet: {}", config.quiet));
241-
logv(c, format!("\n"));
241+
logv(c, "\n".to_string());
242242
}
243243

244-
pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'a str {
244+
pub fn opt_str(maybestr: &Option<String>) -> &str {
245245
match *maybestr {
246246
None => "(none)",
247247
Some(ref s) => s,
@@ -465,11 +465,9 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn
465465
};
466466

467467
// Debugging emscripten code doesn't make sense today
468-
let mut ignore = early_props.ignore || !up_to_date(config, testpaths, &early_props);
469-
if (config.mode == DebugInfoGdb || config.mode == DebugInfoLldb) &&
470-
config.target.contains("emscripten") {
471-
ignore = true;
472-
}
468+
let ignore = early_props.ignore || !up_to_date(config, testpaths, &early_props) ||
469+
(config.mode == DebugInfoGdb || config.mode == DebugInfoLldb) &&
470+
config.target.contains("emscripten");
473471

474472
test::TestDescAndFn {
475473
desc: test::TestDesc {
@@ -488,7 +486,7 @@ fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf {
488486
.to_str().unwrap(),
489487
config.stage_id);
490488
config.build_base.canonicalize()
491-
.unwrap_or(config.build_base.clone())
489+
.unwrap_or_else(|_| config.build_base.clone())
492490
.join(stamp_name)
493491
}
494492

@@ -513,7 +511,7 @@ fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> boo
513511
fn mtime(path: &Path) -> FileTime {
514512
fs::metadata(path).map(|f| {
515513
FileTime::from_last_modification_time(&f)
516-
}).unwrap_or(FileTime::zero())
514+
}).unwrap_or_else(|_| FileTime::zero())
517515
}
518516

519517
pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
@@ -561,7 +559,7 @@ fn analyze_gdb(gdb: Option<String>) -> (Option<String>, Option<u32>, bool) {
561559

562560
let gdb_native_rust = version.map_or(false, |v| v >= MIN_GDB_WITH_RUST);
563561

564-
return (Some(gdb.to_owned()), version, gdb_native_rust);
562+
(Some(gdb.to_owned()), version, gdb_native_rust)
565563
}
566564

567565
fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
@@ -601,7 +599,8 @@ fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
601599
Some(idx) => if line.as_bytes()[idx] == b'.' {
602600
let patch = &line[idx + 1..];
603601

604-
let patch_len = patch.find(|c: char| !c.is_digit(10)).unwrap_or(patch.len());
602+
let patch_len = patch.find(|c: char| !c.is_digit(10))
603+
.unwrap_or_else(|| patch.len());
605604
let patch = &patch[..patch_len];
606605
let patch = if patch_len > 3 || patch_len == 0 { None } else { Some(patch) };
607606

src/tools/compiletest/src/procsrv.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::env;
12-
use std::ffi::OsString;
1312
use std::io::prelude::*;
1413
use std::io;
1514
use std::path::PathBuf;
@@ -31,7 +30,7 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
3130
// Need to be sure to put both the lib_path and the aux path in the dylib
3231
// search path for the child.
3332
let var = dylib_env_var();
34-
let mut path = env::split_paths(&env::var_os(var).unwrap_or(OsString::new()))
33+
let mut path = env::split_paths(&env::var_os(var).unwrap_or_default())
3534
.collect::<Vec<_>>();
3635
if let Some(p) = aux_path {
3736
path.insert(0, PathBuf::from(p))

0 commit comments

Comments
 (0)