Skip to content

Commit 987cd25

Browse files
Some clippy fixes (#879)
* clippy: Use char, not str, versions when single char patterns. * clippy: Fix needless_return warnings. * clippy: Fix redundant_field_names warnings. * clippy: Fix needless_borrowed_reference warnings. * clippy: Fix useless_conversion warnings. * clippy: Fix most needless_borrow warnings. * clippy: Fix needless_bool warnings. * clippy: Suppress upper_case_acronyms lints. These are part of Windows FFI glue code and the Windows types use names in uppercase. * clippy: Fix doc_markdown warnings. * clippy: Fix if_same_then_else errors. * ci: Add a clippy check that only fails on errors.
1 parent bfd68f2 commit 987cd25

File tree

11 files changed

+122
-114
lines changed

11 files changed

+122
-114
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ jobs:
150150
- run: cargo check --lib
151151
- run: cargo check --lib --all-features
152152

153+
clippy:
154+
name: Clippy
155+
runs-on: ubuntu-latest
156+
steps:
157+
- uses: actions/checkout@v4
158+
- name: Install Rust
159+
run: |
160+
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
161+
rustup default stable
162+
shell: bash
163+
- run: cargo clippy
164+
153165
rustfmt:
154166
name: Rustfmt
155167
runs-on: ubuntu-latest

cc-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
.compile("bar");
2323

2424
let target = std::env::var("TARGET").unwrap();
25-
let file = target.split("-").next().unwrap();
25+
let file = target.split('-').next().unwrap();
2626
let file = format!(
2727
"src/{}.{}",
2828
file,

src/com.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464
fn as_unknown(&self) -> &IUnknown {
6565
unsafe { &*(self.0 as *mut IUnknown) }
6666
}
67-
/// Performs QueryInterface fun.
67+
/// Performs `QueryInterface` fun.
6868
pub fn cast<U>(&self) -> Result<ComPtr<U>, i32>
6969
where
7070
U: Interface,

src/lib.rs

Lines changed: 77 additions & 81 deletions
Large diffs are not rendered by default.

src/os_pipe.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Adapted from:
2-
//! - https://doc.rust-lang.org/src/std/sys/unix/pipe.rs.html
3-
//! - https://doc.rust-lang.org/src/std/sys/unix/fd.rs.html#385
4-
//! - https://github.com/rust-lang/rust/blob/master/library/std/src/sys/mod.rs#L57
5-
//! - https://github.com/oconnor663/os_pipe.rs
2+
//! - <https://doc.rust-lang.org/src/std/sys/unix/pipe.rs.html>
3+
//! - <https://doc.rust-lang.org/src/std/sys/unix/fd.rs.html#385>
4+
//! - <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/mod.rs#L57>
5+
//! - <https://github.com/oconnor663/os_pipe.rs>
66
use std::fs::File;
77

88
/// Open a new pipe and return a pair of [`File`] objects for the reader and writer.

src/os_pipe/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fs::File, io, os::windows::prelude::*, ptr};
44
/// NOTE: These pipes do not support IOCP.
55
///
66
/// If IOCP is needed, then you might want to emulate
7-
/// anonymous pipes with CreateNamedPipe, as Rust's stdlib does.
7+
/// anonymous pipes with `CreateNamedPipe`, as Rust's stdlib does.
88
pub(super) fn pipe() -> io::Result<(File, File)> {
99
let mut read_pipe = INVALID_HANDLE_VALUE;
1010
let mut write_pipe = INVALID_HANDLE_VALUE;

src/registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::{
2323
/// Must never be `HKEY_PERFORMANCE_DATA`.
2424
pub(crate) struct RegistryKey(Repr);
2525

26+
#[allow(clippy::upper_case_acronyms)]
2627
type DWORD = u32;
2728

2829
struct OwnedKey(HKEY);
@@ -147,7 +148,7 @@ impl RegistryKey {
147148
if !v.is_empty() && v[v.len() - 1] == 0 {
148149
v.pop();
149150
}
150-
return Ok(OsString::from_wide(&v));
151+
Ok(OsString::from_wide(&v))
151152
}
152153
}
153154
}

src/winapi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// All files in the project carrying such notice may not be copied, modified, or distributed
66
// except according to those terms.
77

8-
#![allow(bad_style)]
8+
#![allow(bad_style, clippy::upper_case_acronyms)]
99

1010
use std::os::raw;
1111

1212
pub type wchar_t = u16;
1313

14-
pub use crate::windows_sys::{FILETIME, GUID, HRESULT, SAFEARRAY, SAFEARRAYBOUND};
14+
pub use crate::windows_sys::{FILETIME, GUID, HRESULT, SAFEARRAY};
1515

1616
pub type REFIID = *const IID;
1717
pub type IID = GUID;

src/windows_registry.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//! A helper module to probe the Windows Registry when looking for
1212
//! windows-specific tools.
1313
14+
#![allow(clippy::upper_case_acronyms)]
15+
1416
use std::process::Command;
1517

1618
use crate::Tool;
@@ -71,11 +73,11 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
7173
// environment variables like `LIB`, `INCLUDE`, and `PATH` to ensure that
7274
// the tool is actually usable.
7375

74-
return impl_::find_msvc_environment(tool, target)
76+
impl_::find_msvc_environment(tool, target)
7577
.or_else(|| impl_::find_msvc_15plus(tool, target))
7678
.or_else(|| impl_::find_msvc_14(tool, target))
7779
.or_else(|| impl_::find_msvc_12(tool, target))
78-
.or_else(|| impl_::find_msvc_11(tool, target));
80+
.or_else(|| impl_::find_msvc_11(tool, target))
7981
}
8082

8183
/// A version of Visual Studio
@@ -182,7 +184,7 @@ mod impl_ {
182184
impl MsvcTool {
183185
fn new(tool: PathBuf) -> MsvcTool {
184186
MsvcTool {
185-
tool: tool,
187+
tool,
186188
libs: Vec::new(),
187189
path: Vec::new(),
188190
include: Vec::new(),
@@ -196,7 +198,7 @@ mod impl_ {
196198
path,
197199
include,
198200
} = self;
199-
let mut tool = Tool::with_family(tool.into(), MSVC_FAMILY);
201+
let mut tool = Tool::with_family(tool, MSVC_FAMILY);
200202
add_env(&mut tool, "LIB", libs);
201203
add_env(&mut tool, "PATH", path);
202204
add_env(&mut tool, "INCLUDE", include);
@@ -210,7 +212,7 @@ mod impl_ {
210212
fn is_vscmd_target(target: &str) -> Option<bool> {
211213
let vscmd_arch = env::var("VSCMD_ARG_TGT_ARCH").ok()?;
212214
// Convert the Rust target arch to its VS arch equivalent.
213-
let arch = match target.split("-").next() {
215+
let arch = match target.split('-').next() {
214216
Some("x86_64") => "x64",
215217
Some("aarch64") => "arm64",
216218
Some("i686") | Some("i586") => "x86",
@@ -242,7 +244,7 @@ mod impl_ {
242244
.map(|p| p.join(tool))
243245
.find(|p| p.exists())
244246
})
245-
.map(|path| Tool::with_family(path.into(), MSVC_FAMILY))
247+
.map(|path| Tool::with_family(path, MSVC_FAMILY))
246248
}
247249
}
248250

@@ -394,7 +396,7 @@ mod impl_ {
394396
.into_iter()
395397
.filter_map(|instance| instance.installation_path())
396398
.map(|path| path.join(tool))
397-
.find(|ref path| path.is_file()),
399+
.find(|path| path.is_file()),
398400
None => None,
399401
};
400402

@@ -467,18 +469,15 @@ mod impl_ {
467469
let path = instance_path.join(r"VC\Tools\MSVC").join(version);
468470
// This is the path to the toolchain for a particular target, running
469471
// on a given host
470-
let bin_path = path
471-
.join("bin")
472-
.join(&format!("Host{}", host))
473-
.join(&target);
472+
let bin_path = path.join("bin").join(format!("Host{}", host)).join(target);
474473
// But! we also need PATH to contain the target directory for the host
475474
// architecture, because it contains dlls like mspdb140.dll compiled for
476475
// the host architecture.
477476
let host_dylib_path = path
478477
.join("bin")
479-
.join(&format!("Host{}", host))
480-
.join(&host.to_lowercase());
481-
let lib_path = path.join("lib").join(&target);
478+
.join(format!("Host{}", host))
479+
.join(host.to_lowercase());
480+
let lib_path = path.join("lib").join(target);
482481
let include_path = path.join("include");
483482
Some((path, bin_path, host_dylib_path, lib_path, include_path))
484483
}
@@ -632,7 +631,7 @@ mod impl_ {
632631
path.join("bin").join(host),
633632
)
634633
})
635-
.filter(|&(ref path, _)| path.is_file())
634+
.filter(|(path, _)| path.is_file())
636635
.map(|(path, host)| {
637636
let mut tool = MsvcTool::new(path);
638637
tool.path.push(host);
@@ -840,7 +839,7 @@ mod impl_ {
840839
for subkey in key.iter().filter_map(|k| k.ok()) {
841840
let val = subkey
842841
.to_str()
843-
.and_then(|s| s.trim_left_matches("v").replace(".", "").parse().ok());
842+
.and_then(|s| s.trim_left_matches("v").replace('.', "").parse().ok());
844843
let val = match val {
845844
Some(s) => s,
846845
None => continue,
@@ -883,7 +882,7 @@ mod impl_ {
883882
}
884883

885884
pub fn find_devenv(target: &str) -> Option<Tool> {
886-
find_devenv_vs15(&target)
885+
find_devenv_vs15(target)
887886
}
888887

889888
fn find_devenv_vs15(target: &str) -> Option<Tool> {
@@ -894,7 +893,7 @@ mod impl_ {
894893
pub fn find_msbuild(target: &str) -> Option<Tool> {
895894
// VS 15 (2017) changed how to locate msbuild
896895
if let Some(r) = find_msbuild_vs17(target) {
897-
return Some(r);
896+
Some(r)
898897
} else if let Some(r) = find_msbuild_vs16(target) {
899898
return Some(r);
900899
} else if let Some(r) = find_msbuild_vs15(target) {

tests/support/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ impl Test {
3434
// lesser of the two evils.
3535
env::remove_var("RUSTC_WRAPPER");
3636

37-
let mut gcc = PathBuf::from(env::current_exe().unwrap());
37+
let mut gcc = env::current_exe().unwrap();
3838
gcc.pop();
3939
if gcc.ends_with("deps") {
4040
gcc.pop();
4141
}
4242
let td = Builder::new().prefix("gcc-test").tempdir_in(&gcc).unwrap();
4343
gcc.push(format!("gcc-shim{}", env::consts::EXE_SUFFIX));
4444
Test {
45-
td: td,
46-
gcc: gcc,
45+
td,
46+
gcc,
4747
msvc: false,
4848
}
4949
}

0 commit comments

Comments
 (0)