Mercurial > hg
diff rust/hg-core/src/filepatterns.rs @ 44973:26114bd6ec60
rust: do a clippy pass
This is the result of running `cargo clippy` on hg-core/hg-cpython and fixing
the lints that do not require too much code churn (and would warrant a separate
commit/complete refactor) and only come from our code (a lot of warnings in
hg-cpython come from `rust-cpython`).
Most of those were good lints, two of them was the linter not being smart
enough (or compiler to get up to `clippy`'s level depending on how you see it).
Maybe in the future we could have `clippy` be part of the CI.
Differential Revision: https://phab.mercurial-scm.org/D8635
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 15 Jun 2020 18:26:40 +0200 |
parents | be6401a25726 |
children | 777c3d231913 |
line wrap: on
line diff
--- a/rust/hg-core/src/filepatterns.rs Mon Jun 15 15:14:16 2020 -0400 +++ b/rust/hg-core/src/filepatterns.rs Mon Jun 15 18:26:40 2020 +0200 @@ -324,6 +324,8 @@ warn: bool, ) -> Result<(Vec<IgnorePattern>, Vec<PatternFileWarning>), PatternError> { let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap(); + + #[allow(clippy::trivial_regex)] let comment_escape_regex = Regex::new(r"\\#").unwrap(); let mut inputs: Vec<IgnorePattern> = vec![]; let mut warnings: Vec<PatternFileWarning> = vec![]; @@ -458,9 +460,7 @@ .into_iter() .flat_map(|entry| -> PatternResult<_> { let IgnorePattern { - syntax, - pattern, - source: _, + syntax, pattern, .. } = &entry; Ok(match syntax { PatternSyntax::Include => { @@ -504,10 +504,11 @@ normalize_path_bytes(&get_bytes_from_path(source)); let source_root = get_path_from_bytes(&normalized_source); - let source_root = source_root.parent().unwrap_or(source_root.deref()); + let source_root = + source_root.parent().unwrap_or_else(|| source_root.deref()); let path = source_root.join(get_path_from_bytes(pattern)); - let new_root = path.parent().unwrap_or(path.deref()); + let new_root = path.parent().unwrap_or_else(|| path.deref()); let prefix = canonical_path(&root_dir, &root_dir, new_root)?;