Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
44962:ef8dcee272ac | 44973:26114bd6ec60 |
---|---|
322 lines: &[u8], | 322 lines: &[u8], |
323 file_path: P, | 323 file_path: P, |
324 warn: bool, | 324 warn: bool, |
325 ) -> Result<(Vec<IgnorePattern>, Vec<PatternFileWarning>), PatternError> { | 325 ) -> Result<(Vec<IgnorePattern>, Vec<PatternFileWarning>), PatternError> { |
326 let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap(); | 326 let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap(); |
327 | |
328 #[allow(clippy::trivial_regex)] | |
327 let comment_escape_regex = Regex::new(r"\\#").unwrap(); | 329 let comment_escape_regex = Regex::new(r"\\#").unwrap(); |
328 let mut inputs: Vec<IgnorePattern> = vec![]; | 330 let mut inputs: Vec<IgnorePattern> = vec![]; |
329 let mut warnings: Vec<PatternFileWarning> = vec![]; | 331 let mut warnings: Vec<PatternFileWarning> = vec![]; |
330 | 332 |
331 let mut current_syntax = b"relre:".as_ref(); | 333 let mut current_syntax = b"relre:".as_ref(); |
456 let (patterns, mut warnings) = read_pattern_file(&pattern_file, true)?; | 458 let (patterns, mut warnings) = read_pattern_file(&pattern_file, true)?; |
457 let patterns = patterns | 459 let patterns = patterns |
458 .into_iter() | 460 .into_iter() |
459 .flat_map(|entry| -> PatternResult<_> { | 461 .flat_map(|entry| -> PatternResult<_> { |
460 let IgnorePattern { | 462 let IgnorePattern { |
461 syntax, | 463 syntax, pattern, .. |
462 pattern, | |
463 source: _, | |
464 } = &entry; | 464 } = &entry; |
465 Ok(match syntax { | 465 Ok(match syntax { |
466 PatternSyntax::Include => { | 466 PatternSyntax::Include => { |
467 let inner_include = | 467 let inner_include = |
468 root_dir.as_ref().join(get_path_from_bytes(&pattern)); | 468 root_dir.as_ref().join(get_path_from_bytes(&pattern)); |
502 ) -> Result<SubInclude, HgPathError> { | 502 ) -> Result<SubInclude, HgPathError> { |
503 let normalized_source = | 503 let normalized_source = |
504 normalize_path_bytes(&get_bytes_from_path(source)); | 504 normalize_path_bytes(&get_bytes_from_path(source)); |
505 | 505 |
506 let source_root = get_path_from_bytes(&normalized_source); | 506 let source_root = get_path_from_bytes(&normalized_source); |
507 let source_root = source_root.parent().unwrap_or(source_root.deref()); | 507 let source_root = |
508 source_root.parent().unwrap_or_else(|| source_root.deref()); | |
508 | 509 |
509 let path = source_root.join(get_path_from_bytes(pattern)); | 510 let path = source_root.join(get_path_from_bytes(pattern)); |
510 let new_root = path.parent().unwrap_or(path.deref()); | 511 let new_root = path.parent().unwrap_or_else(|| path.deref()); |
511 | 512 |
512 let prefix = canonical_path(&root_dir, &root_dir, new_root)?; | 513 let prefix = canonical_path(&root_dir, &root_dir, new_root)?; |
513 | 514 |
514 Ok(Self { | 515 Ok(Self { |
515 prefix: path_to_hg_path_buf(prefix).and_then(|mut p| { | 516 prefix: path_to_hg_path_buf(prefix).and_then(|mut p| { |