Skip to content

Commit

Permalink
thanks clippy
Browse files Browse the repository at this point in the history
For v1.72.0
  • Loading branch information
Byron committed Aug 24, 2023
1 parent 524000a commit 5044c3b
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/corpus/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
"#,
)?;
con.execute_batch(
r#"
r"
CREATE TABLE if not exists repository(
id integer PRIMARY KEY,
rela_path text, -- the path to the repository on disk, relative to the corpus root path, without leading `./` or `.\`
Expand All @@ -103,7 +103,7 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
FOREIGN KEY (corpus) REFERENCES corpus (id)
UNIQUE (rela_path, corpus)
)
"#,
",
)?;
con.execute_batch(
r#"
Expand Down
4 changes: 3 additions & 1 deletion gitoxide-core/src/repository/submodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub fn list(repo: Repository, mut out: impl std::io::Write, format: OutputFormat
bail!("Only human output is supported for now")
}

let Some(submodules) = repo.submodules()? else { return Ok(()) };
let Some(submodules) = repo.submodules()? else {
return Ok(());
};
for sm in submodules {
print_sm(sm, &mut out)?;
}
Expand Down
7 changes: 4 additions & 3 deletions gix-config/src/parse/nom/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod section_headers {
fn backslashes_in_subsections_do_not_escape_newlines_or_tabs() {
assert_eq!(
section_header.parse_peek(br#"[hello "single \ \\ \t \n \0"]"#).unwrap(),
fully_consumed(parsed_section_header("hello", (" ", r#"single \ t n 0"#)))
fully_consumed(parsed_section_header("hello", (" ", r"single \ t n 0")))
);
}

Expand Down Expand Up @@ -756,6 +756,7 @@ mod value_no_continuation {
}

#[test]
#[allow(clippy::needless_raw_string_hashes)]
fn trans_escaped_comment_marker_not_consumed() {
let mut events = section::Events::default();
assert_eq!(value_impl(br##"hello"#"world; a"##, &mut events).unwrap().0, b"; a");
Expand All @@ -776,7 +777,7 @@ mod value_no_continuation {

#[test]
fn invalid_escape() {
assert!(value_impl(br#"\x"#, &mut Default::default()).is_err());
assert!(value_impl(br"\x", &mut Default::default()).is_err());
}

#[test]
Expand All @@ -786,7 +787,7 @@ mod value_no_continuation {

#[test]
fn incomplete_escape() {
assert!(value_impl(br#"hello world\"#, &mut Default::default()).is_err());
assert!(value_impl(br"hello world\", &mut Default::default()).is_err());
}
}

Expand Down
2 changes: 1 addition & 1 deletion gix-config/src/parse/section/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn escape_subsection(name: &BStr) -> 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),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions gix-config/tests/file/mutable/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ mod set_leading_whitespace {
}

fn multi_value_section() -> gix_config::File<'static> {
r#"
r"
[a]
a = v
b =
c=
d
e =a \
b \
c"#
c"
.parse()
.unwrap()
}
2 changes: 1 addition & 1 deletion gix-config/tests/parse/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions gix-config/tests/value/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
);
Expand Down
6 changes: 3 additions & 3 deletions gix-date/tests/time/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion gix-mailmap/tests/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>(), entries] {
for entries in [entries.clone().into_iter().rev().collect::<Vec<_>>(), entries] {
let snapshot = Snapshot::new(entries);

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion gix-odb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,5 @@ pub fn at_opts(

/// Create a new cached handle to the object store.
pub fn at(objects_dir: impl Into<PathBuf>) -> std::io::Result<Handle> {
at_opts(objects_dir, Vec::new().into_iter(), Default::default())
at_opts(objects_dir, Vec::new(), Default::default())
}
2 changes: 1 addition & 1 deletion gix-packetline/tests/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion gix-revision/tests/spec/parse/anchor/colon_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down
42 changes: 19 additions & 23 deletions gix-revision/tests/spec/parse/navigate/caret_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
] {
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions gix-worktree-state/tests/state/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
)
Expand Down
3 changes: 1 addition & 2 deletions gix/src/config/cache/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion gix/src/config/tree/sections/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
Expand Down
5 changes: 3 additions & 2 deletions gix/src/object/tree/diff/for_each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
Expand Down

0 comments on commit 5044c3b

Please sign in to comment.