diff --git a/.cargo/config.toml b/.cargo/config.toml index 3e6810586b8..87d8b21363d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,7 +5,6 @@ rustflags = [ # Clippy lints "-W", "clippy::cloned_instead_of_copied", - "-W", "clippy::explicit_iter_loop", "-W", "clippy::map_unwrap_or", "-W", "clippy::redundant_closure_for_method_calls", "-W", "clippy::unnested_or_patterns", @@ -14,6 +13,7 @@ rustflags = [ # Rejected for now, and why # "-W" "clippy::default_trait_access" - sometimes makes imports necessary, just for a default value. It's good for more explicit typing though. # "-W" "clippy::range_plus_one" - useful, but caused too many false positives as we use range types directly quite a lot + # "-W", "clippy::explicit_iter_loop", - the cases I saw turned `foo.iter_mut()` into `&mut *foo` # Rustdoc lints diff --git a/gitoxide-core/src/corpus/db.rs b/gitoxide-core/src/corpus/db.rs index f2e9230bffb..f56275bd4c3 100644 --- a/gitoxide-core/src/corpus/db.rs +++ b/gitoxide-core/src/corpus/db.rs @@ -92,7 +92,7 @@ pub fn create(path: impl AsRef) -> anyhow::Result) -> anyhow::Result Cow<'_, BStr> { let mut buf = Vec::with_capacity(name.len()); for b in name.iter().copied() { match b { - b'\\' => buf.push_str(br#"\\"#), + b'\\' => buf.push_str(br"\\"), b'"' => buf.push_str(br#"\""#), _ => buf.push(b), } diff --git a/gix-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs b/gix-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs index f8b125b69d1..b9488402845 100644 --- a/gix-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs +++ b/gix-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs @@ -189,14 +189,14 @@ fn case_insensitive_matches_any_case() -> crate::Result { #[test] fn pattern_with_escaped_backslash() -> crate::Result { assert_section_value( - original_value_on_windows(Condition::new(r#"gitdir:\\work\\tree\\/"#)), + original_value_on_windows(Condition::new(r"gitdir:\\work\\tree\\/")), GitEnv::repo_name("worktree")?, ) } #[test] fn pattern_with_backslash() -> crate::Result { - assert_section_value(Condition::new(r#"gitdir:work\tree/"#), GitEnv::repo_name("worktree")?) + assert_section_value(Condition::new(r"gitdir:work\tree/"), GitEnv::repo_name("worktree")?) } #[test] diff --git a/gix-config/tests/file/mutable/section.rs b/gix-config/tests/file/mutable/section.rs index 7a4493360f9..ea17ce7a401 100644 --- a/gix-config/tests/file/mutable/section.rs +++ b/gix-config/tests/file/mutable/section.rs @@ -260,7 +260,7 @@ mod set_leading_whitespace { } fn multi_value_section() -> gix_config::File<'static> { - r#" + r" [a] a = v b = @@ -268,7 +268,7 @@ fn multi_value_section() -> gix_config::File<'static> { d e =a \ b \ - c"# + c" .parse() .unwrap() } diff --git a/gix-config/tests/parse/section.rs b/gix-config/tests/parse/section.rs index 700f847c65d..872052e9031 100644 --- a/gix-config/tests/parse/section.rs +++ b/gix-config/tests/parse/section.rs @@ -22,7 +22,7 @@ mod header { #[test] fn subsection_backslashes_and_quotes_are_escaped() -> crate::Result { assert_eq!( - section::Header::new("core", cow_section(r#"a\b"#))?.to_bstring(), + section::Header::new("core", cow_section(r"a\b"))?.to_bstring(), r#"[core "a\\b"]"# ); assert_eq!( diff --git a/gix-config/tests/value/normalize.rs b/gix-config/tests/value/normalize.rs index d0daa0db9f2..0179e408412 100644 --- a/gix-config/tests/value/normalize.rs +++ b/gix-config/tests/value/normalize.rs @@ -69,7 +69,7 @@ fn inner_quotes_are_removed() { #[test] fn newline_tab_backspace_are_escapable() { - assert_eq!(normalize_bstr(r#"\n\ta\b"#), cow_str("\n\t")); + assert_eq!(normalize_bstr(r"\n\ta\b"), cow_str("\n\t")); } #[test] @@ -80,7 +80,7 @@ fn tabs_are_not_resolved_to_spaces_unlike_what_git_does() { #[test] fn other_escapes_are_ignored_entirely() { assert_eq!( - normalize_bstr(r#"\x"#), + normalize_bstr(r"\x"), cow_str("x"), "however, these would cause failure on parsing level so we ignore it similar to subsections" ); diff --git a/gix-date/tests/time/parse.rs b/gix-date/tests/time/parse.rs index 20cf74b6c51..5b23fe1077a 100644 --- a/gix-date/tests/time/parse.rs +++ b/gix-date/tests/time/parse.rs @@ -148,11 +148,11 @@ mod relative { #[test] fn various() { - let now = Some(SystemTime::now()); - let two_weeks_ago = gix_date::parse("2 weeks ago", now).unwrap(); + let now = SystemTime::now(); + let two_weeks_ago = gix_date::parse("2 weeks ago", Some(now)).unwrap(); assert_eq!(Sign::Plus, two_weeks_ago.sign); assert_eq!(0, two_weeks_ago.offset); - let expected = OffsetDateTime::from(now.unwrap()).saturating_sub(Duration::weeks(2)); + let expected = OffsetDateTime::from(now).saturating_sub(Duration::weeks(2)); // account for the loss of precision when creating `Time` with seconds let expected = expected.replace_nanosecond(0).unwrap(); assert_eq!( diff --git a/gix-mailmap/tests/snapshot/mod.rs b/gix-mailmap/tests/snapshot/mod.rs index e231665ce46..408ad49b083 100644 --- a/gix-mailmap/tests/snapshot/mod.rs +++ b/gix-mailmap/tests/snapshot/mod.rs @@ -65,7 +65,7 @@ fn non_name_and_name_mappings_will_not_clash() { "old-email", ), ]; - for entries in vec![entries.clone().into_iter().rev().collect::>(), entries] { + for entries in [entries.clone().into_iter().rev().collect::>(), entries] { let snapshot = Snapshot::new(entries); assert_eq!( diff --git a/gix-odb/src/lib.rs b/gix-odb/src/lib.rs index e0beac54848..682c63c86ea 100644 --- a/gix-odb/src/lib.rs +++ b/gix-odb/src/lib.rs @@ -148,5 +148,5 @@ pub fn at_opts( /// Create a new cached handle to the object store. pub fn at(objects_dir: impl Into) -> std::io::Result { - at_opts(objects_dir, Vec::new().into_iter(), Default::default()) + at_opts(objects_dir, Vec::new(), Default::default()) } diff --git a/gix-packetline/tests/read/mod.rs b/gix-packetline/tests/read/mod.rs index d487239f7e4..8420af08ff4 100644 --- a/gix-packetline/tests/read/mod.rs +++ b/gix-packetline/tests/read/mod.rs @@ -174,7 +174,7 @@ pub mod streaming_peek_iter { #[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))] async fn read_from_file_and_reader_advancement() -> crate::Result { let mut bytes = fixture_bytes("v1/fetch/01-many-refs.response"); - bytes.extend(fixture_bytes("v1/fetch/01-many-refs.response").into_iter()); + bytes.extend(fixture_bytes("v1/fetch/01-many-refs.response")); let mut rd = gix_packetline::StreamingPeekableIter::new(&bytes[..], &[PacketLineRef::Flush]); let res = rd.read_line().await; assert_eq!(res.expect("line")??, first_line()); diff --git a/gix-revision/tests/spec/parse/anchor/colon_symbol.rs b/gix-revision/tests/spec/parse/anchor/colon_symbol.rs index a7674799b03..b8693923a53 100644 --- a/gix-revision/tests/spec/parse/anchor/colon_symbol.rs +++ b/gix-revision/tests/spec/parse/anchor/colon_symbol.rs @@ -55,7 +55,7 @@ fn various_forms_of_regex() { #[test] fn regex_do_not_get_any_backslash_processing() { - for (spec, regex) in [(r#":/{"#, "{"), (r#":/\{\}"#, r#"\{\}"#), (r#":/\\\\\}"#, r#"\\\\\}"#)] { + for (spec, regex) in [(r#":/{"#, "{"), (r":/\{\}", r"\{\}"), (r":/\\\\\}", r"\\\\\}")] { let rec = parse(spec); assert_eq!(rec.patterns, vec![(regex.into(), false)]); diff --git a/gix-revision/tests/spec/parse/navigate/caret_symbol.rs b/gix-revision/tests/spec/parse/navigate/caret_symbol.rs index aaf7792090c..ea80adb643a 100644 --- a/gix-revision/tests/spec/parse/navigate/caret_symbol.rs +++ b/gix-revision/tests/spec/parse/navigate/caret_symbol.rs @@ -105,40 +105,36 @@ fn regex_backslash_rules() { "matching inner parens do not need escaping", ), ( - r#"@^{/with count\{1\}}"#, + r"@^{/with count\{1\}}", r#"with count{1}"#, "escaped parens are entirely ignored", ), - (r#"@^{/1\}}"#, r#"1}"#, "unmatched closing parens need to be escaped"), - (r#"@^{/2\{}"#, r#"2{"#, "unmatched opening parens need to be escaped"), + (r"@^{/1\}}", r#"1}"#, "unmatched closing parens need to be escaped"), + (r"@^{/2\{}", r#"2{"#, "unmatched opening parens need to be escaped"), ( - r#"@^{/3{\{}}"#, + r"@^{/3{\{}}", r#"3{{}"#, "unmatched nested opening parens need to be escaped", ), ( - r#"@^{/4{\}}}"#, + r"@^{/4{\}}}", r#"4{}}"#, "unmatched nested closing parens need to be escaped", ), + (r"@^{/a\b\c}", r"a\b\c", "single backslashes do not need to be escaped"), ( - r#"@^{/a\b\c}"#, - r#"a\b\c"#, - "single backslashes do not need to be escaped", - ), - ( - r#"@^{/a\b\c\\}"#, - r#"a\b\c\"#, + r"@^{/a\b\c\\}", + r"a\b\c\", "single backslashes do not need to be escaped, trailing", ), ( - r#"@^{/a\\b\\c\\}"#, - r#"a\b\c\"#, + r"@^{/a\\b\\c\\}", + r"a\b\c\", "backslashes can be escaped nonetheless, trailing", ), ( - r#"@^{/5\\{}}"#, - r#"5\{}"#, + r"@^{/5\\{}}", + r"5\{}", "backslashes in front of parens must be escaped or they would unbalance the brace pair", ), ] { @@ -196,11 +192,11 @@ fn invalid_object_type() { #[test] fn incomplete_escaped_braces_in_regex_are_invalid() { - let err = try_parse(r#"@^{/a\{1}}"#).unwrap_err(); + let err = try_parse(r"@^{/a\{1}}").unwrap_err(); assert!(matches!(err, spec::parse::Error::UnconsumedInput {input} if input == "}")); - let err = try_parse(r#"@^{/a{1\}}"#).unwrap_err(); - assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r#"{/a{1\}}"#)); + let err = try_parse(r"@^{/a{1\}}").unwrap_err(); + assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r"{/a{1\}}")); } #[test] @@ -211,11 +207,11 @@ fn regex_with_empty_exclamation_mark_prefix_is_invalid() { #[test] fn bad_escapes_can_cause_brace_mismatch() { - let err = try_parse(r#"@^{\}"#).unwrap_err(); - assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r#"{\}"#)); + let err = try_parse(r"@^{\}").unwrap_err(); + assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r"{\}")); - let err = try_parse(r#"@^{{\}}"#).unwrap_err(); - assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r#"{{\}}"#)); + let err = try_parse(r"@^{{\}}").unwrap_err(); + assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r"{{\}}")); } #[test] diff --git a/gix-worktree-state/tests/state/checkout.rs b/gix-worktree-state/tests/state/checkout.rs index 6b57c0a92df..4c2e1f87b5d 100644 --- a/gix-worktree-state/tests/state/checkout.rs +++ b/gix-worktree-state/tests/state/checkout.rs @@ -281,12 +281,11 @@ fn keep_going_collects_results() { opts, "make_mixed_without_submodules", |_id| { - !matches!( - count.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |current| { + count + .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |current| { (current < 2).then_some(current + 1) - }), - Ok(_) - ) + }) + .is_err() }, |_| Ok(()), ) diff --git a/gix/src/config/cache/access.rs b/gix/src/config/cache/access.rs index 5f373362860..e3ba40d4e75 100644 --- a/gix/src/config/cache/access.rs +++ b/gix/src/config/cache/access.rs @@ -75,12 +75,11 @@ impl Cache { const DEFAULT: bool = true; self.resolved .boolean_by_key("core.commitGraph") - .map(|res| { + .map_or(Ok(DEFAULT), |res| { Core::COMMIT_GRAPH .enrich_error(res) .with_lenient_default_value(self.lenient_config, DEFAULT) }) - .unwrap_or(Ok(DEFAULT)) } pub(crate) fn diff_renames( diff --git a/gix/src/config/tree/sections/protocol.rs b/gix/src/config/tree/sections/protocol.rs index a0510f2b8df..7ef2cc8cb7c 100644 --- a/gix/src/config/tree/sections/protocol.rs +++ b/gix/src/config/tree/sections/protocol.rs @@ -127,7 +127,7 @@ mod validate { .to_decimal() .ok_or_else(|| format!("integer {value} cannot be represented as integer"))?; match value { - 0 | 1 | 2 => Ok(()), + 0..=2 => Ok(()), _ => Err(format!("protocol version {value} is unknown").into()), } } diff --git a/gix/src/object/tree/diff/for_each.rs b/gix/src/object/tree/diff/for_each.rs index a72033182b1..3932f902788 100644 --- a/gix/src/object/tree/diff/for_each.rs +++ b/gix/src/object/tree/diff/for_each.rs @@ -75,8 +75,9 @@ impl<'a, 'old> Platform<'a, 'old> { } Err(gix_diff::tree::changes::Error::Cancelled) => delegate .err - .map(|err| Err(Error::ForEach(Box::new(err)))) - .unwrap_or(Err(Error::Diff(gix_diff::tree::changes::Error::Cancelled))), + .map_or(Err(Error::Diff(gix_diff::tree::changes::Error::Cancelled)), |err| { + Err(Error::ForEach(Box::new(err))) + }), Err(err) => Err(err.into()), } }