Lints and clippys

This commit is contained in:
Félix Saparelli 2019-10-27 23:47:35 +13:00
parent 6b028cb649
commit f56e838fb9
No known key found for this signature in database
GPG Key ID: 25940898BB90EA51
8 changed files with 47 additions and 52 deletions

View File

@ -199,7 +199,7 @@ where
let cmd: Vec<String> = values_t!(args.values_of("command"), String)?;
let paths = values_t!(args.values_of("path"), String)
.unwrap_or(vec![".".into()])
.unwrap_or_else(|_| vec![".".into()])
.iter()
.map(|string_path| string_path.into())
.collect();
@ -212,7 +212,7 @@ where
args.value_of("signal").map(str::to_string)
};
let mut filters = values_t!(args.values_of("filter"), String).unwrap_or(Vec::new());
let mut filters = values_t!(args.values_of("filter"), String).unwrap_or_else(|_| Vec::new());
if let Some(extensions) = args.values_of("extensions") {
for exts in extensions {
@ -240,7 +240,7 @@ where
if args.occurrences_of("no-default-ignore") == 0 {
ignores.extend(default_ignores)
};
ignores.extend(values_t!(args.values_of("ignore"), String).unwrap_or(Vec::new()));
ignores.extend(values_t!(args.values_of("ignore"), String).unwrap_or_else(|_| Vec::new()));
let poll_interval = if args.occurrences_of("poll") > 0 {
value_t!(args.value_of("poll"), u32).unwrap_or_else(|e| e.exit())
@ -267,14 +267,14 @@ where
}
Ok(Args {
cmd: cmd,
paths: paths,
filters: filters,
ignores: ignores,
signal: signal,
cmd,
paths,
filters,
ignores,
signal,
clear_screen: args.is_present("clear"),
restart: args.is_present("restart"),
debounce: debounce,
debounce,
debug: args.is_present("verbose"),
run_initially: !args.is_present("postpone"),
no_shell: args.is_present("no-shell"),
@ -282,6 +282,6 @@ where
no_ignore: args.is_present("no-ignore"),
once: args.is_present("once"),
poll: args.occurrences_of("poll") > 0,
poll_interval: poll_interval,
poll_interval,
})
}

View File

@ -84,7 +84,7 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
impl Gitignore {
fn new(files: Vec<GitignoreFile>) -> Gitignore {
Gitignore { files: files }
Gitignore { files }
}
pub fn is_excluded(&self, path: &Path) -> bool {
@ -129,13 +129,13 @@ impl GitignoreFile {
let parsed_patterns = GitignoreFile::parse(strs);
for p in parsed_patterns {
let mut pat = String::from(p.pattern.clone());
let mut pat = p.pattern.clone();
if !p.anchored && !pat.starts_with("**/") {
pat = "**/".to_string() + &pat;
}
if !pat.ends_with("/**") {
pat = pat + "/**";
pat += "/**";
}
let glob = GlobBuilder::new(&pat).literal_separator(true).build()?;
@ -146,7 +146,7 @@ impl GitignoreFile {
Ok(GitignoreFile {
set: builder.build()?,
patterns: patterns,
patterns,
root: root.to_owned(),
})
}
@ -158,14 +158,14 @@ impl GitignoreFile {
fn matches(&self, path: &Path) -> MatchResult {
let stripped = path.strip_prefix(&self.root);
if !stripped.is_ok() {
if stripped.is_err() {
return MatchResult::None;
}
let matches = self.set.matches(stripped.unwrap());
for &i in matches.iter().rev() {
let pattern = &self.patterns[i];
if let Some(i) = matches.iter().rev().next() {
let pattern = &self.patterns[*i];
return match pattern.pattern_type {
PatternType::Whitelist => MatchResult::Whitelist,
PatternType::Ignore => MatchResult::Ignore,
@ -217,8 +217,8 @@ impl Pattern {
Pattern {
pattern: normalized,
pattern_type: pattern_type,
anchored: anchored,
pattern_type,
anchored,
}
}
}

View File

@ -77,7 +77,7 @@ pub fn load(paths: &[PathBuf]) -> Ignore {
impl Ignore {
fn new(files: Vec<IgnoreFile>) -> Ignore {
Ignore { files: files }
Ignore { files }
}
pub fn is_excluded(&self, path: &Path) -> bool {
@ -122,13 +122,13 @@ impl IgnoreFile {
let parsed_patterns = IgnoreFile::parse(strs);
for p in parsed_patterns {
let mut pat = String::from(p.pattern.clone());
let mut pat = p.pattern.clone();
if !p.anchored && !pat.starts_with("**/") {
pat = "**/".to_string() + &pat;
}
if !pat.ends_with("/**") {
pat = pat + "/**";
pat += "/**";
}
let glob = GlobBuilder::new(&pat).literal_separator(true).build()?;
@ -139,7 +139,7 @@ impl IgnoreFile {
Ok(IgnoreFile {
set: builder.build()?,
patterns: patterns,
patterns,
root: root.to_owned(),
})
}
@ -151,14 +151,14 @@ impl IgnoreFile {
fn matches(&self, path: &Path) -> MatchResult {
let stripped = path.strip_prefix(&self.root);
if !stripped.is_ok() {
if stripped.is_err() {
return MatchResult::None;
}
let matches = self.set.matches(stripped.unwrap());
for &i in matches.iter().rev() {
let pattern = &self.patterns[i];
if let Some(i) = matches.iter().rev().next() {
let pattern = &self.patterns[*i];
return match pattern.pattern_type {
PatternType::Whitelist => MatchResult::Whitelist,
PatternType::Ignore => MatchResult::Ignore,
@ -210,8 +210,8 @@ impl Pattern {
Pattern {
pattern: normalized,
pattern_type: pattern_type,
anchored: anchored,
pattern_type,
anchored,
}
}
}

View File

@ -30,7 +30,7 @@ impl NotificationFilter {
let mut ignore_set_builder = GlobSetBuilder::new();
for i in ignores {
let mut ignore_path = Path::new(i).to_path_buf();
if ignore_path.is_relative() && !i.starts_with("*") {
if ignore_path.is_relative() && !i.starts_with('*') {
ignore_path = Path::new("**").join(&ignore_path);
}
let pattern = ignore_path.to_str().unwrap();
@ -42,8 +42,8 @@ impl NotificationFilter {
filters: filter_set_builder.build()?,
filter_count: filters.len(),
ignores: ignore_set_builder.build()?,
gitignore_files: gitignore_files,
ignore_files: ignore_files,
gitignore_files,
ignore_files,
})
}

View File

@ -13,8 +13,8 @@ impl PathOp {
pub fn new(path: &Path, op: Option<op::Op>, cookie: Option<u32>) -> PathOp {
PathOp {
path: path.to_path_buf(),
op: op,
cookie: cookie,
op,
cookie,
}
}

View File

@ -3,7 +3,7 @@ use pathop::PathOp;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
pub fn spawn(cmd: &Vec<String>, updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
pub fn spawn(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
self::imp::Process::new(cmd, updated_paths, no_shell).map_err(|e| e.into())
}
@ -79,10 +79,9 @@ mod imp {
}
}
#[allow(unknown_lints)]
#[allow(mutex_atomic)]
#[allow(clippy::mutex_atomic)]
impl Process {
pub fn new(cmd: &Vec<String>, updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
use nix::unistd::*;
use std::os::unix::process::CommandExt;
@ -110,8 +109,8 @@ mod imp {
command.env(name, val);
}
unsafe { command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ())); }
command
.before_exec(|| setsid().map_err(from_nix_error).map(|_| ()))
.spawn()
.and_then(|p| {
Ok(Process {
@ -130,7 +129,6 @@ mod imp {
loop {
match waitpid(Pid::from_raw(-self.pgid), Some(WaitPidFlag::WNOHANG)) {
Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => {
finished = finished && true
}
Ok(_) => {
finished = false;
@ -284,8 +282,8 @@ mod imp {
resume_threads(handle);
Ok(Process {
job: job,
completion_port: completion_port,
job,
completion_port,
})
})
}
@ -373,9 +371,9 @@ mod imp {
/// RENAMED -> `notify::ops::RENAME`
fn collect_path_env_vars(pathops: &[PathOp]) -> Vec<(String, String)> {
#[cfg(target_family = "unix")]
const ENV_SEP: &'static str = ":";
const ENV_SEP: &str = ":";
#[cfg(not(target_family = "unix"))]
const ENV_SEP: &'static str = ";";
const ENV_SEP: &str = ";";
let mut by_op = HashMap::new(); // Paths as `String`s collected by `notify::op`
let mut all_pathbufs = HashSet::new(); // All unique `PathBuf`s
@ -417,7 +415,7 @@ fn collect_path_env_vars(pathops: &[PathOp]) -> Vec<(String, String)> {
let paths = if let Some(ref common_path) = common_path {
paths
.iter()
.map(|path_str| path_str.trim_left_matches(common_path).to_string())
.map(|path_str| path_str.trim_start_matches(common_path).to_string())
.collect::<Vec<_>>()
} else {
paths

View File

@ -97,9 +97,9 @@ where
let filter = NotificationFilter::new(&args.filters, &args.ignores, gitignore, ignore)?;
let (tx, rx) = channel();
let poll = args.poll.clone();
let poll = args.poll;
#[cfg(target_os = "linux")]
let poll_interval = args.poll_interval.clone();
let poll_interval = args.poll_interval;
let watcher = Watcher::new(tx.clone(), &paths, args.poll, args.poll_interval).or_else(|err| {
if poll {
return Err(err);
@ -129,10 +129,8 @@ where
}
// Call handler initially, if necessary
if args.run_initially {
if !handler.on_manual()? {
return Ok(());
}
if args.run_initially && !handler.on_manual()? {
return Ok(());
}
loop {

View File

@ -1,7 +1,7 @@
use std::sync::Mutex;
lazy_static! {
static ref CLEANUP: Mutex<Option<Box<Fn(self::Signal) + Send>>> = Mutex::new(None);
static ref CLEANUP: Mutex<Option<Box<dyn Fn(self::Signal) + Send>>> = Mutex::new(None);
}
#[cfg(unix)]
@ -75,7 +75,6 @@ pub fn install_handler<F>(handler: F)
where
F: Fn(self::Signal) + 'static + Send + Sync,
{
use nix::libc::c_int;
use nix::sys::signal::*;
use std::thread;