Auto merge of #75789 - matthiaskrgr:clippy_compiletest, r=Dylan-DPC

compiletest: fix a couple clippy lint findings
This commit is contained in:
bors 2020-08-23 10:25:53 +00:00
commit 2342cc3333
6 changed files with 59 additions and 72 deletions

View File

@ -148,7 +148,7 @@ fn parse_expected(
// If we find `//~ ERROR foo` or something like that, skip the first word.
let kind = first_word.parse::<ErrorKind>().ok();
if let Some(_) = kind {
if kind.is_some() {
msg = &msg.trim_start().split_at(first_word.len()).1;
}

View File

@ -173,10 +173,8 @@ impl EarlyProps {
// Ignore if actual version is smaller the minimum required
// version
actual_version < min_version
} else if line.starts_with("rust-lldb") && !config.lldb_native_rust {
true
} else {
false
line.starts_with("rust-lldb") && !config.lldb_native_rust
}
} else {
false
@ -657,7 +655,6 @@ fn iter_header<R: Read>(testfile: &Path, cfg: Option<&str>, rdr: R, it: &mut dyn
it(ln[comment.len()..].trim_start());
}
}
return;
}
impl Config {
@ -819,7 +816,7 @@ impl Config {
let name = line[prefix.len() + 1..].split(&[':', ' '][..]).next().unwrap();
let is_match = name == "test" ||
&self.target == name || // triple
self.target == name || // triple
util::matches_os(&self.target, name) || // target
util::matches_env(&self.target, name) || // env
self.target.ends_with(name) || // target and env
@ -857,10 +854,7 @@ impl Config {
// Ensure the directive is a whole word. Do not match "ignore-x86" when
// the line says "ignore-x86_64".
line.starts_with(directive)
&& match line.as_bytes().get(directive.len()) {
None | Some(&b' ') | Some(&b':') => true,
_ => false,
}
&& matches!(line.as_bytes().get(directive.len()), None | Some(&b' ') | Some(&b':'))
}
pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
@ -901,9 +895,9 @@ impl Config {
}
fn expand_variables(mut value: String, config: &Config) -> String {
const CWD: &'static str = "{{cwd}}";
const SRC_BASE: &'static str = "{{src-base}}";
const BUILD_BASE: &'static str = "{{build-base}}";
const CWD: &str = "{{cwd}}";
const SRC_BASE: &str = "{{src-base}}";
const BUILD_BASE: &str = "{{build-base}}";
if value.contains(CWD) {
let cwd = env::current_dir().unwrap();

View File

@ -75,7 +75,7 @@ pub fn extract_rendered(output: &str) -> String {
if line.starts_with('{') {
if let Ok(diagnostic) = serde_json::from_str::<Diagnostic>(line) {
diagnostic.rendered
} else if let Ok(_) = serde_json::from_str::<ArtifactNotification>(line) {
} else if serde_json::from_str::<ArtifactNotification>(line).is_ok() {
// Ignore the notification.
None
} else {

View File

@ -240,7 +240,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
cc: matches.opt_str("cc").unwrap(),
cxx: matches.opt_str("cxx").unwrap(),
cflags: matches.opt_str("cflags").unwrap(),
ar: matches.opt_str("ar").unwrap_or("ar".into()),
ar: matches.opt_str("ar").unwrap_or_else(|| String::from("ar")),
linker: matches.opt_str("linker"),
llvm_components: matches.opt_str("llvm-components").unwrap(),
nodejs: matches.opt_str("nodejs"),
@ -361,17 +361,13 @@ pub fn run_tests(config: Config) {
}
fn configure_cdb(config: &Config) -> Option<Config> {
if config.cdb.is_none() {
return None;
}
config.cdb.as_ref()?;
Some(Config { debugger: Some(Debugger::Cdb), ..config.clone() })
}
fn configure_gdb(config: &Config) -> Option<Config> {
if config.gdb_version.is_none() {
return None;
}
config.gdb_version?;
if util::matches_env(&config.target, "msvc") {
return None;
@ -405,9 +401,7 @@ fn configure_gdb(config: &Config) -> Option<Config> {
}
fn configure_lldb(config: &Config) -> Option<Config> {
if config.lldb_python_dir.is_none() {
return None;
}
config.lldb_python_dir.as_ref()?;
if let Some(350) = config.lldb_version {
println!(
@ -455,7 +449,7 @@ pub fn make_tests(config: &Config, tests: &mut Vec<test::TestDescAndFn>) {
debug!("making tests from {:?}", config.src_base.display());
let inputs = common_inputs_stamp(config);
collect_tests_from_dir(config, &config.src_base, &PathBuf::new(), &inputs, tests)
.expect(&format!("Could not read tests from {}", config.src_base.display()));
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
}
/// Returns a stamp constructed from input files common to all test cases.
@ -588,7 +582,7 @@ fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec<test
let revisions = if early_props.revisions.is_empty() || config.mode == Mode::Incremental {
vec![None]
} else {
early_props.revisions.iter().map(|r| Some(r)).collect()
early_props.revisions.iter().map(Some).collect()
};
revisions
.into_iter()
@ -735,24 +729,24 @@ fn make_test_closure(
/// Returns `true` if the given target is an Android target for the
/// purposes of GDB testing.
fn is_android_gdb_target(target: &String) -> bool {
match &target[..] {
"arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => true,
_ => false,
}
fn is_android_gdb_target(target: &str) -> bool {
matches!(
&target[..],
"arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android"
)
}
/// Returns `true` if the given target is a MSVC target for the purpouses of CDB testing.
fn is_pc_windows_msvc_target(target: &String) -> bool {
fn is_pc_windows_msvc_target(target: &str) -> bool {
target.ends_with("-pc-windows-msvc")
}
fn find_cdb(target: &String) -> Option<OsString> {
fn find_cdb(target: &str) -> Option<OsString> {
if !(cfg!(windows) && is_pc_windows_msvc_target(target)) {
return None;
}
let pf86 = env::var_os("ProgramFiles(x86)").or(env::var_os("ProgramFiles"))?;
let pf86 = env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?;
let cdb_arch = if cfg!(target_arch = "x86") {
"x86"
} else if cfg!(target_arch = "x86_64") {
@ -779,14 +773,14 @@ fn find_cdb(target: &String) -> Option<OsString> {
}
/// Returns Path to CDB
fn analyze_cdb(cdb: Option<String>, target: &String) -> Option<OsString> {
cdb.map(|s| OsString::from(s)).or(find_cdb(target))
fn analyze_cdb(cdb: Option<String>, target: &str) -> Option<OsString> {
cdb.map(OsString::from).or_else(|| find_cdb(target))
}
/// Returns (Path to GDB, GDB Version, GDB has Rust Support)
fn analyze_gdb(
gdb: Option<String>,
target: &String,
target: &str,
android_cross_path: &PathBuf,
) -> (Option<String>, Option<u32>, bool) {
#[cfg(not(windows))]

View File

@ -114,7 +114,7 @@ pub struct Mismatch {
impl Mismatch {
fn new(line_number: u32) -> Mismatch {
Mismatch { line_number: line_number, lines: Vec::new() }
Mismatch { line_number, lines: Vec::new() }
}
}
@ -199,7 +199,7 @@ fn write_diff(expected: &str, actual: &str, context_size: usize) -> String {
}
}
}
writeln!(output, "").unwrap();
writeln!(output).unwrap();
}
output
}
@ -230,7 +230,7 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) {
debug!("running {:?}", testpaths.file.display());
let props = TestProps::from_file(&testpaths.file, revision, &config);
let cx = TestCx { config: &config, props: &props, testpaths, revision: revision };
let cx = TestCx { config: &config, props: &props, testpaths, revision };
create_dir_all(&cx.output_base_dir()).unwrap();
if config.mode == Incremental {
@ -578,8 +578,8 @@ impl<'test> TestCx<'test> {
if self.props.pp_exact.is_some() {
// Now we have to care about line endings
let cr = "\r".to_owned();
actual = actual.replace(&cr, "").to_owned();
expected = expected.replace(&cr, "").to_owned();
actual = actual.replace(&cr, "");
expected = expected.replace(&cr, "");
}
self.compare_source(&expected, &actual);
@ -740,7 +740,7 @@ impl<'test> TestCx<'test> {
let exe_file = self.make_exe_name();
let prefixes = {
static PREFIXES: &'static [&'static str] = &["cdb", "cdbg"];
static PREFIXES: &[&str] = &["cdb", "cdbg"];
// No "native rust support" variation for CDB yet.
PREFIXES
};
@ -811,12 +811,12 @@ impl<'test> TestCx<'test> {
fn run_debuginfo_gdb_test_no_opt(&self) {
let prefixes = if self.config.gdb_native_rust {
// GDB with Rust
static PREFIXES: &'static [&'static str] = &["gdb", "gdbr"];
static PREFIXES: &[&str] = &["gdb", "gdbr"];
println!("NOTE: compiletest thinks it is using GDB with native rust support");
PREFIXES
} else {
// Generic GDB
static PREFIXES: &'static [&'static str] = &["gdb", "gdbg"];
static PREFIXES: &[&str] = &["gdb", "gdbg"];
println!("NOTE: compiletest thinks it is using GDB without native rust support");
PREFIXES
};
@ -875,12 +875,12 @@ impl<'test> TestCx<'test> {
.arg(&exe_file)
.arg(&self.config.adb_test_dir)
.status()
.expect(&format!("failed to exec `{:?}`", adb_path));
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", adb_path));
Command::new(adb_path)
.args(&["forward", "tcp:5039", "tcp:5039"])
.status()
.expect(&format!("failed to exec `{:?}`", adb_path));
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", adb_path));
let adb_arg = format!(
"export LD_LIBRARY_PATH={}; \
@ -897,7 +897,7 @@ impl<'test> TestCx<'test> {
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.expect(&format!("failed to exec `{:?}`", adb_path));
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", adb_path));
// Wait for the gdbserver to print out "Listening on port ..."
// at which point we know that it's started and then we can
@ -922,7 +922,7 @@ impl<'test> TestCx<'test> {
let Output { status, stdout, stderr } = Command::new(&gdb_path)
.args(debugger_opts)
.output()
.expect(&format!("failed to exec `{:?}`", gdb_path));
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", gdb_path));
let cmdline = {
let mut gdb = Command::new(&format!("{}-gdb", self.config.target));
gdb.args(debugger_opts);
@ -1063,11 +1063,11 @@ impl<'test> TestCx<'test> {
}
let prefixes = if self.config.lldb_native_rust {
static PREFIXES: &'static [&'static str] = &["lldb", "lldbr"];
static PREFIXES: &[&str] = &["lldb", "lldbr"];
println!("NOTE: compiletest thinks it is using LLDB with native rust support");
PREFIXES
} else {
static PREFIXES: &'static [&'static str] = &["lldb", "lldbg"];
static PREFIXES: &[&str] = &["lldb", "lldbg"];
println!("NOTE: compiletest thinks it is using LLDB without native rust support");
PREFIXES
};
@ -1842,8 +1842,8 @@ impl<'test> TestCx<'test> {
// Need to be sure to put both the lib_path and the aux path in the dylib
// search path for the child.
let mut path = env::split_paths(&env::var_os(dylib_env_var()).unwrap_or(OsString::new()))
.collect::<Vec<_>>();
let mut path =
env::split_paths(&env::var_os(dylib_env_var()).unwrap_or_default()).collect::<Vec<_>>();
if let Some(p) = aux_path {
path.insert(0, PathBuf::from(p))
}
@ -1854,7 +1854,7 @@ impl<'test> TestCx<'test> {
command.env(dylib_env_var(), newpath);
let mut child = disable_error_reporting(|| command.spawn())
.expect(&format!("failed to exec `{:?}`", &command));
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", &command));
if let Some(input) = input {
child.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
}
@ -2446,8 +2446,8 @@ impl<'test> TestCx<'test> {
self.check_no_compiler_crash(&proc_res, self.props.should_ice);
const PREFIX: &'static str = "MONO_ITEM ";
const CGU_MARKER: &'static str = "@@";
const PREFIX: &str = "MONO_ITEM ";
const CGU_MARKER: &str = "@@";
let actual: Vec<MonoItem> = proc_res
.stdout
@ -2976,7 +2976,7 @@ impl<'test> TestCx<'test> {
Filter::MachineApplicableOnly,
)
.unwrap_or_default();
if suggestions.len() > 0
if !suggestions.is_empty()
&& !self.props.run_rustfix
&& !self.props.rustfix_only_machine_applicable
{
@ -2990,7 +2990,7 @@ impl<'test> TestCx<'test> {
.open(coverage_file_path.as_path())
.expect("could not create or open file");
if let Err(_) = writeln!(file, "{}", self.testpaths.file.display()) {
if writeln!(file, "{}", self.testpaths.file.display()).is_err() {
panic!("couldn't write to {}", coverage_file_path.display());
}
}
@ -3007,10 +3007,9 @@ impl<'test> TestCx<'test> {
},
)
.unwrap();
let fixed_code = apply_suggestions(&unfixed_code, &suggestions).expect(&format!(
"failed to apply suggestions for {:?} with rustfix",
self.testpaths.file
));
let fixed_code = apply_suggestions(&unfixed_code, &suggestions).unwrap_or_else(|_| {
panic!("failed to apply suggestions for {:?} with rustfix", self.testpaths.file)
});
errors += self.compare_output("fixed", &fixed_code, &expected_fixed);
} else if !expected_fixed.is_empty() {
@ -3519,7 +3518,7 @@ impl<'test> TestCx<'test> {
let examined_content =
self.load_expected_output_from_path(&examined_path).unwrap_or_else(|_| String::new());
if canon_content == &examined_content {
if canon_content == examined_content {
self.delete_file(&examined_path);
}
}

View File

@ -9,7 +9,7 @@ use tracing::*;
mod tests;
/// Conversion table from triple OS name to Rust SYSNAME
const OS_TABLE: &'static [(&'static str, &'static str)] = &[
const OS_TABLE: &[(&str, &str)] = &[
("android", "android"),
("androideabi", "android"),
("cloudabi", "cloudabi"),
@ -37,7 +37,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[
("vxworks", "vxworks"),
];
const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
const ARCH_TABLE: &[(&str, &str)] = &[
("aarch64", "aarch64"),
("amd64", "x86_64"),
("arm", "arm"),
@ -82,7 +82,7 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
("xcore", "xcore"),
];
pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-fuchsia",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
@ -91,20 +91,20 @@ pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
"x86_64-unknown-linux-gnu",
];
pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] =
pub const LSAN_SUPPORTED_TARGETS: &[&str] =
&["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] =
pub const MSAN_SUPPORTED_TARGETS: &[&str] =
&["aarch64-unknown-linux-gnu", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"];
pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu",
];
const BIG_ENDIAN: &'static [&'static str] = &[
const BIG_ENDIAN: &[&str] = &[
"armebv7r",
"mips",
"mips64",
@ -195,11 +195,11 @@ pub trait PathBufExt {
impl PathBufExt for PathBuf {
fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
if extension.as_ref().len() == 0 {
if extension.as_ref().is_empty() {
self.clone()
} else {
let mut fname = self.file_name().unwrap().to_os_string();
if !extension.as_ref().to_str().unwrap().starts_with(".") {
if !extension.as_ref().to_str().unwrap().starts_with('.') {
fname.push(".");
}
fname.push(extension);