Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Disallow warnings from clippy #52

Merged
merged 2 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace --all-targets --all-features
args: --workspace --all-targets --all-features -- -Dwarnings

# Ensure that the project could be successfully compiled
cargo_check:
Expand Down
4 changes: 1 addition & 3 deletions src/checker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::finder::Checker;
#[cfg(unix)]
use libc;
#[cfg(unix)]
use std::ffi::CString;
use std::fs;
#[cfg(unix)]
Expand All @@ -20,7 +18,7 @@ impl Checker for ExecutableChecker {
#[cfg(unix)]
fn is_valid(&self, path: &Path) -> bool {
CString::new(path.as_os_str().as_bytes())
.and_then(|c| Ok(unsafe { libc::access(c.as_ptr(), libc::X_OK) == 0 }))
.map(|c| unsafe { libc::access(c.as_ptr(), libc::X_OK) == 0 })
.unwrap_or(false)
}

Expand Down
5 changes: 4 additions & 1 deletion src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ impl Finder {
T: AsRef<OsStr>,
{
let p = paths.ok_or(Error::CannotFindBinaryPath)?;
// Collect needs to happen in order to not have to
// change the API to borrow on `paths`.
#[allow(clippy::needless_collect)]
let paths: Vec<_> = env::split_paths(&p).collect();

let matching_re = paths
Expand Down Expand Up @@ -169,7 +172,7 @@ impl Finder {
})
// PATHEXT not being set or not being a proper Unicode string is exceedingly
// improbable and would probably break Windows badly. Still, don't crash:
.unwrap_or(vec![]);
.unwrap_or_default();
}

paths
Expand Down
36 changes: 22 additions & 14 deletions tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate tempdir;
extern crate which;

#[cfg(feature = "regex")]
#[cfg(all(unix, feature = "regex"))]
use regex::Regex;
use std::ffi::{OsStr, OsString};
use std::fs;
Expand All @@ -19,8 +19,8 @@ struct TestFixture {
pub bins: Vec<PathBuf>,
}

const SUBDIRS: &'static [&'static str] = &["a", "b", "c"];
const BIN_NAME: &'static str = "bin";
const SUBDIRS: &[&str] = &["a", "b", "c"];
const BIN_NAME: &str = "bin";

#[cfg(unix)]
fn mk_bin(dir: &Path, path: &str, extension: &str) -> io::Result<PathBuf> {
Expand Down Expand Up @@ -63,25 +63,25 @@ impl TestFixture {
for d in SUBDIRS.iter() {
let p = tempdir.path().join(d);
builder.create(&p).unwrap();
bins.push(mk_bin(&p, &BIN_NAME, "").unwrap());
bins.push(mk_bin(&p, &BIN_NAME, "exe").unwrap());
bins.push(mk_bin(&p, &BIN_NAME, "cmd").unwrap());
bins.push(mk_bin(&p, BIN_NAME, "").unwrap());
bins.push(mk_bin(&p, BIN_NAME, "exe").unwrap());
bins.push(mk_bin(&p, BIN_NAME, "cmd").unwrap());
paths.push(p);
}
TestFixture {
tempdir: tempdir,
tempdir,
paths: env::join_paths(paths).unwrap(),
bins: bins,
bins,
}
}

#[allow(dead_code)]
pub fn touch(&self, path: &str, extension: &str) -> io::Result<PathBuf> {
touch(self.tempdir.path(), &path, &extension)
touch(self.tempdir.path(), path, extension)
}

pub fn mk_bin(&self, path: &str, extension: &str) -> io::Result<PathBuf> {
mk_bin(self.tempdir.path(), &path, &extension)
mk_bin(self.tempdir.path(), path, extension)
}
}

Expand Down Expand Up @@ -165,10 +165,18 @@ fn test_which_re_in_without_matches() {
#[test]
#[cfg(all(unix, feature = "regex"))]
fn test_which_re_accepts_owned_and_borrow() {
which::which_re(Regex::new(r".").unwrap());
which::which_re(&Regex::new(r".").unwrap());
which::which_re_in(Regex::new(r".").unwrap(), Some("pth"));
which::which_re_in(&Regex::new(r".").unwrap(), Some("pth"));
which::which_re(Regex::new(r".").unwrap())
.unwrap()
.for_each(drop);
which::which_re(&Regex::new(r".").unwrap())
.unwrap()
.for_each(drop);
which::which_re_in(Regex::new(r".").unwrap(), Some("pth"))
.unwrap()
.for_each(drop);
which::which_re_in(&Regex::new(r".").unwrap(), Some("pth"))
.unwrap()
.for_each(drop);
}

#[test]
Expand Down