Skip to content

Commit dff709b

Browse files
authored
Fix clippy warnings on Windows (#1088)
1 parent a6a928e commit dff709b

File tree

10 files changed

+204
-235
lines changed

10 files changed

+204
-235
lines changed

dev-tools/cc-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn main() {
169169
#[track_caller]
170170
fn run_forked_capture_output(out: &Path, action: &str) {
171171
let program = env::current_exe().unwrap();
172-
let output = Command::new(&program).arg(action).output().unwrap();
172+
let output = Command::new(program).arg(action).output().unwrap();
173173
assert!(output.status.success(), "output: {:#?}", output);
174174
// we've captured the output and now we write it to a dedicated directory in the
175175
// build output so our tests can access the output.

dev-tools/gen-target-info/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn generate_riscv_arch_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
1212
.iter()
1313
.filter_map(|(target, target_spec)| {
1414
let arch = target.split_once('-').unwrap().0;
15-
(arch.contains("riscv") && arch != &target_spec.arch)
15+
(arch.contains("riscv") && arch != target_spec.arch)
1616
.then_some((arch, &*target_spec.arch))
1717
})
1818
.collect::<Vec<_>>();

src/command_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub(crate) struct CmdAddOutputFileArgs {
398398

399399
pub(crate) fn command_add_output_file(cmd: &mut Command, dst: &Path, args: CmdAddOutputFileArgs) {
400400
if args.is_assembler_msvc
401-
|| (args.msvc && !args.clang && !args.gnu && !args.cuda && !(args.is_asm && args.is_arm))
401+
|| !(!args.msvc || args.clang || args.gnu || args.cuda || (args.is_asm && args.is_arm))
402402
{
403403
let mut s = OsString::from("-Fo");
404404
s.push(dst);

src/lib.rs

Lines changed: 172 additions & 187 deletions
Large diffs are not rendered by default.

src/parallel/job_token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ mod inherited_jobserver {
186186
// Fallback to creating a help thread with blocking acquire
187187
let helper_thread = self
188188
.helper_thread
189-
.get_or_try_init(|| HelperThread::new(&self.jobserver))?;
189+
.get_or_try_init(|| HelperThread::new(self.jobserver))?;
190190

191191
match helper_thread.rx.try_recv() {
192192
Ok(res) => {

src/tool.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Tool {
9696
) -> Self {
9797
fn is_zig_cc(path: &Path, cargo_output: &CargoOutput) -> bool {
9898
run_output(
99-
Command::new(&path).arg("--version"),
99+
Command::new(path).arg("--version"),
100100
path,
101101
// tool detection issues should always be shown as warnings
102102
cargo_output,
@@ -392,10 +392,7 @@ impl Tool {
392392

393393
/// Whether the tool is MSVC-like.
394394
pub fn is_like_msvc(&self) -> bool {
395-
match self.family {
396-
ToolFamily::Msvc { .. } => true,
397-
_ => false,
398-
}
395+
matches!(self.family, ToolFamily::Msvc { .. })
399396
}
400397
}
401398

src/windows/find_tools.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,13 @@ pub fn find_vs_version() -> Result<VsVers, String> {
142142
} else if impl_::has_msbuild_version("12.0") {
143143
Ok(VsVers::Vs12)
144144
} else {
145-
Err(format!(
146-
"\n\n\
145+
Err("\n\n\
147146
couldn't determine visual studio generator\n\
148147
if VisualStudio is installed, however, consider \
149148
running the appropriate vcvars script before building \
150149
this crate\n\
151150
"
152-
))
151+
.to_string())
153152
}
154153
}
155154
}
@@ -296,10 +295,8 @@ mod impl_ {
296295
/// Attempt to find the tool using environment variables set by vcvars.
297296
pub(super) fn find_msvc_environment(tool: &str, target: TargetArch<'_>) -> Option<Tool> {
298297
// Early return if the environment doesn't contain a VC install.
299-
if env::var_os("VCINSTALLDIR").is_none() {
300-
return None;
301-
}
302-
let vs_install_dir = env::var_os("VSINSTALLDIR")?.into();
298+
env::var_os("VCINSTALLDIR")?;
299+
let vs_install_dir: PathBuf = env::var_os("VSINSTALLDIR")?.into();
303300

304301
// If the vscmd target differs from the requested target then
305302
// attempt to get the tool using the VS install directory.
@@ -334,9 +331,9 @@ mod impl_ {
334331
};
335332
Box::new(instances.into_iter().filter_map(move |instance| {
336333
let installation_name = instance.installation_name()?;
337-
if installation_name.starts_with(&format!("VisualStudio/{}.", version)) {
338-
Some(instance.installation_path()?)
339-
} else if installation_name.starts_with(&format!("VisualStudioPreview/{}.", version)) {
334+
if installation_name.starts_with(&format!("VisualStudio/{}.", version))
335+
|| installation_name.starts_with(&format!("VisualStudioPreview/{}.", version))
336+
{
340337
Some(instance.installation_path()?)
341338
} else {
342339
None
@@ -417,7 +414,7 @@ mod impl_ {
417414
};
418415

419416
let vswhere_output = Command::new(vswhere_path)
420-
.args(&[
417+
.args([
421418
"-latest",
422419
"-products",
423420
"*",
@@ -500,7 +497,7 @@ mod impl_ {
500497
fn tool_from_vs15plus_instance(
501498
tool: &str,
502499
target: TargetArch<'_>,
503-
instance_path: &PathBuf,
500+
instance_path: &Path,
504501
) -> Option<Tool> {
505502
let (root_path, bin_path, host_dylib_path, lib_path, alt_lib_path, include_path) =
506503
vs15plus_vc_paths(target, instance_path)?;
@@ -706,7 +703,7 @@ mod impl_ {
706703
}
707704

708705
fn add_env(tool: &mut Tool, env: &str, paths: Vec<PathBuf>) {
709-
let prev = env::var_os(env).unwrap_or(OsString::new());
706+
let prev = env::var_os(env).unwrap_or_default();
710707
let prev = env::split_paths(&prev);
711708
let new = paths.into_iter().chain(prev);
712709
tool.env
@@ -809,8 +806,7 @@ mod impl_ {
809806
let dir = dirs
810807
.into_iter()
811808
.rev()
812-
.filter(|dir| dir.join("um").join("x64").join("kernel32.lib").is_file())
813-
.next()?;
809+
.find(|dir| dir.join("um").join("x64").join("kernel32.lib").is_file())?;
814810
let version = dir.components().last().unwrap();
815811
let version = version.as_os_str().to_str().unwrap().to_string();
816812
Some((root.into(), version))
@@ -922,7 +918,7 @@ mod impl_ {
922918
for subkey in key.iter().filter_map(|k| k.ok()) {
923919
let val = subkey
924920
.to_str()
925-
.and_then(|s| s.trim_start_matches("v").replace('.', "").parse().ok());
921+
.and_then(|s| s.trim_start_matches('v').replace('.', "").parse().ok());
926922
let val = match val {
927923
Some(s) => s,
928924
None => continue,

src/windows/vs_instances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl TryFrom<&Vec<u8>> for VswhereInstance {
7373
fn try_from(output: &Vec<u8>) -> Result<Self, Self::Error> {
7474
let map: HashMap<_, _> = output
7575
.lines()
76-
.filter_map(Result::ok)
76+
.map_while(Result::ok)
7777
.filter_map(|s| {
7878
let mut splitn = s.splitn(2, ": ");
7979
Some((splitn.next()?.to_owned(), splitn.next()?.to_owned()))

tests/cc_env.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,16 @@ fn ccache_env_flags() {
5555
compiler.cc_env(),
5656
OsString::from("ccache lol-this-is-not-a-compiler")
5757
);
58-
assert!(
59-
compiler
60-
.cflags_env()
61-
.into_string()
62-
.unwrap()
63-
.contains("ccache")
64-
== false
65-
);
66-
assert!(
67-
compiler
68-
.cflags_env()
69-
.into_string()
70-
.unwrap()
71-
.contains(" lol-this-is-not-a-compiler")
72-
== false
73-
);
58+
assert!(!compiler
59+
.cflags_env()
60+
.into_string()
61+
.unwrap()
62+
.contains("ccache"));
63+
assert!(!compiler
64+
.cflags_env()
65+
.into_string()
66+
.unwrap()
67+
.contains(" lol-this-is-not-a-compiler"));
7468

7569
env::set_var("CC", "");
7670
}

tests/support/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::io;
77
use std::io::prelude::*;
88
use std::path::{Path, PathBuf};
99

10-
use cc;
1110
use tempfile::{Builder, TempDir};
1211

1312
pub struct Test {
@@ -86,12 +85,10 @@ impl Test {
8685
let mut cfg = cc::Build::new();
8786
let target = if self.msvc {
8887
"x86_64-pc-windows-msvc"
88+
} else if cfg!(target_os = "macos") {
89+
"x86_64-apple-darwin"
8990
} else {
90-
if cfg!(target_os = "macos") {
91-
"x86_64-apple-darwin"
92-
} else {
93-
"x86_64-unknown-linux-gnu"
94-
}
91+
"x86_64-unknown-linux-gnu"
9592
};
9693

9794
cfg.target(target)

0 commit comments

Comments
 (0)