mirror of
https://github.com/openharmony/third_party_rust_which-rs.git
synced 2026-07-01 21:14:07 -04:00
Fix all clippy lints as of Rust 1.58
This commit is contained in:
+1
-3
@@ -1,7 +1,5 @@
|
||||
use crate::finder::Checker;
|
||||
#[cfg(unix)]
|
||||
use libc;
|
||||
#[cfg(unix)]
|
||||
use std::ffi::CString;
|
||||
use std::fs;
|
||||
#[cfg(unix)]
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -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
|
||||
@@ -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
|
||||
|
||||
+22
-14
@@ -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;
|
||||
@@ -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> {
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user