Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/matchers.rs @ 50003:e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
All of these are simple changes that for the most part are clear improvements
and the rest are at most equivalent.
The remaining warnings have to be fixed either with a bigger refactor like for
the nested "revlog" module, or in the dependency `bytes-cast`, which we own.
This will be done sometime in the future.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 09 Jan 2023 19:18:43 +0100 |
parents | c15b415d1bff |
children | 1c31b343e514 |
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs Mon Jan 09 19:14:14 2023 +0100 +++ b/rust/hg-core/src/matchers.rs Mon Jan 09 19:18:43 2023 +0100 @@ -302,11 +302,11 @@ } fn matches(&self, filename: &HgPath) -> bool { - (self.match_fn)(filename.as_ref()) + (self.match_fn)(filename) } fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet { - let dir = directory.as_ref(); + let dir = directory; if self.prefix && self.roots.contains(dir) { return VisitChildrenSet::Recursive; } @@ -318,11 +318,11 @@ return VisitChildrenSet::This; } - if self.parents.contains(directory.as_ref()) { + if self.parents.contains(dir.as_ref()) { let multiset = self.get_all_parents_children(); if let Some(children) = multiset.get(dir) { return VisitChildrenSet::Set( - children.into_iter().map(HgPathBuf::from).collect(), + children.iter().map(HgPathBuf::from).collect(), ); } } @@ -446,7 +446,7 @@ VisitChildrenSet::This } (VisitChildrenSet::Set(m1), VisitChildrenSet::Set(m2)) => { - let set: HashSet<_> = m1.intersection(&m2).cloned().collect(); + let set: HashSet<_> = m1.intersection(m2).cloned().collect(); if set.is_empty() { VisitChildrenSet::Empty } else { @@ -699,10 +699,9 @@ PatternSyntax::RootGlob | PatternSyntax::Glob => { let mut root = HgPathBuf::new(); for p in pattern.split(|c| *c == b'/') { - if p.iter().any(|c| match *c { - b'[' | b'{' | b'*' | b'?' => true, - _ => false, - }) { + if p.iter() + .any(|c| matches!(*c, b'[' | b'{' | b'*' | b'?')) + { break; } root.push(HgPathBuf::from_bytes(p).as_ref()); @@ -780,10 +779,10 @@ /// Returns a function that checks whether a given file (in the general sense) /// should be matched. -fn build_match<'a, 'b>( +fn build_match<'a>( ignore_patterns: Vec<IgnorePattern>, -) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> { - let mut match_funcs: Vec<IgnoreFnType<'b>> = vec![]; +) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> { + let mut match_funcs: Vec<IgnoreFnType<'a>> = vec![]; // For debugging and printing let mut patterns = vec![]; @@ -921,9 +920,8 @@ dirs, parents, } = roots_dirs_and_parents(&ignore_patterns)?; - let prefix = ignore_patterns.iter().all(|k| match k.syntax { - PatternSyntax::Path | PatternSyntax::RelPath => true, - _ => false, + let prefix = ignore_patterns.iter().all(|k| { + matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath) }); let (patterns, match_fn) = build_match(ignore_patterns)?;