From 53daa4281fafe145110889840042da0ed91aeff3 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 22 Dec 2023 21:01:27 +0100 Subject: [PATCH 1/4] Do not deconstruct an error to rebuild it right after --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fef8090..6dc63a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,9 +208,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Result Date: Fri, 22 Dec 2023 21:07:08 +0100 Subject: [PATCH 2/4] Remove useless `as usize` --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6dc63a5..7700f12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -389,7 +389,7 @@ impl Iterator for Paths { if let Some(scope) = self.scope.take() { if !self.dir_patterns.is_empty() { // Shouldn't happen, but we're using -1 as a special index. - assert!(self.dir_patterns.len() < !0 as usize); + assert!(self.dir_patterns.len() < std::usize::MAX); fill_todo(&mut self.todo, &self.dir_patterns, 0, &scope, self.options); } @@ -407,7 +407,7 @@ impl Iterator for Paths { // idx -1: was already checked by fill_todo, maybe path was '.' or // '..' that we can't match here because of normalization. - if idx == !0 as usize { + if idx == std::usize::MAX { if self.require_dir && !path.is_directory { continue; } @@ -890,7 +890,7 @@ fn fill_todo( // We know it's good, so don't make the iterator match this path // against the pattern again. In particular, it can't match // . or .. globs since these never show up as path components. - todo.push(Ok((next_path, !0 as usize))); + todo.push(Ok((next_path, std::usize::MAX))); } else { fill_todo(todo, patterns, idx + 1, &next_path, options); } From b8611597d1f34be0cdc82d0d3d831ea4e80bdc90 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 22 Dec 2023 21:10:52 +0100 Subject: [PATCH 3/4] Use char rather than &str as `starts_with()` argument --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7700f12..c3f8598 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -939,7 +939,7 @@ fn fill_todo( Ok(mut children) => { if options.require_literal_leading_dot { children - .retain(|x| !x.file_name().unwrap().to_str().unwrap().starts_with(".")); + .retain(|x| !x.file_name().unwrap().to_str().unwrap().starts_with('.')); } children.sort_by(|p1, p2| p2.file_name().cmp(&p1.file_name())); todo.extend(children.into_iter().map(|x| Ok((x, idx)))); From d4df77a85901fe3f48053fdde8d9175cac805beb Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 22 Dec 2023 21:12:57 +0100 Subject: [PATCH 4/4] Remove useless references --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c3f8598..0ff4f58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -841,8 +841,8 @@ impl Pattern { false } AnyChar => true, - AnyWithin(ref specifiers) => in_char_specifiers(&specifiers, c, options), - AnyExcept(ref specifiers) => !in_char_specifiers(&specifiers, c, options), + AnyWithin(ref specifiers) => in_char_specifiers(specifiers, c, options), + AnyExcept(ref specifiers) => !in_char_specifiers(specifiers, c, options), Char(c2) => chars_eq(c, c2, options.case_sensitive), AnySequence | AnyRecursiveSequence => unreachable!(), } { @@ -1488,12 +1488,12 @@ mod test { fn test_matches_path() { // on windows, (Path::new("a/b").as_str().unwrap() == "a\\b"), so this // tests that / and \ are considered equivalent on windows - assert!(Pattern::new("a/b").unwrap().matches_path(&Path::new("a/b"))); + assert!(Pattern::new("a/b").unwrap().matches_path(Path::new("a/b"))); } #[test] fn test_path_join() { - let pattern = Path::new("one").join(&Path::new("**/*.rs")); + let pattern = Path::new("one").join(Path::new("**/*.rs")); assert!(Pattern::new(pattern.to_str().unwrap()).is_ok()); } }