Skip to content

Commit 5044c3b

Browse files
committed
thanks clippy
For v1.72.0
1 parent 524000a commit 5044c3b

File tree

19 files changed

+53
-55
lines changed

19 files changed

+53
-55
lines changed

.cargo/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ rustflags = [
55

66
# Clippy lints
77
"-W", "clippy::cloned_instead_of_copied",
8-
"-W", "clippy::explicit_iter_loop",
98
"-W", "clippy::map_unwrap_or",
109
"-W", "clippy::redundant_closure_for_method_calls",
1110
"-W", "clippy::unnested_or_patterns",
@@ -14,6 +13,7 @@ rustflags = [
1413
# Rejected for now, and why
1514
# "-W" "clippy::default_trait_access" - sometimes makes imports necessary, just for a default value. It's good for more explicit typing though.
1615
# "-W" "clippy::range_plus_one" - useful, but caused too many false positives as we use range types directly quite a lot
16+
# "-W", "clippy::explicit_iter_loop", - the cases I saw turned `foo.iter_mut()` into `&mut *foo`
1717

1818

1919
# Rustdoc lints

gitoxide-core/src/corpus/db.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
9292
"#,
9393
)?;
9494
con.execute_batch(
95-
r#"
95+
r"
9696
CREATE TABLE if not exists repository(
9797
id integer PRIMARY KEY,
9898
rela_path text, -- the path to the repository on disk, relative to the corpus root path, without leading `./` or `.\`
@@ -103,7 +103,7 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
103103
FOREIGN KEY (corpus) REFERENCES corpus (id)
104104
UNIQUE (rela_path, corpus)
105105
)
106-
"#,
106+
",
107107
)?;
108108
con.execute_batch(
109109
r#"

gitoxide-core/src/repository/submodule.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ pub fn list(repo: Repository, mut out: impl std::io::Write, format: OutputFormat
99
bail!("Only human output is supported for now")
1010
}
1111

12-
let Some(submodules) = repo.submodules()? else { return Ok(()) };
12+
let Some(submodules) = repo.submodules()? else {
13+
return Ok(());
14+
};
1315
for sm in submodules {
1416
print_sm(sm, &mut out)?;
1517
}

gix-config/src/parse/nom/tests.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod section_headers {
6262
fn backslashes_in_subsections_do_not_escape_newlines_or_tabs() {
6363
assert_eq!(
6464
section_header.parse_peek(br#"[hello "single \ \\ \t \n \0"]"#).unwrap(),
65-
fully_consumed(parsed_section_header("hello", (" ", r#"single \ t n 0"#)))
65+
fully_consumed(parsed_section_header("hello", (" ", r"single \ t n 0")))
6666
);
6767
}
6868

@@ -756,6 +756,7 @@ mod value_no_continuation {
756756
}
757757

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

777778
#[test]
778779
fn invalid_escape() {
779-
assert!(value_impl(br#"\x"#, &mut Default::default()).is_err());
780+
assert!(value_impl(br"\x", &mut Default::default()).is_err());
780781
}
781782

782783
#[test]
@@ -786,7 +787,7 @@ mod value_no_continuation {
786787

787788
#[test]
788789
fn incomplete_escape() {
789-
assert!(value_impl(br#"hello world\"#, &mut Default::default()).is_err());
790+
assert!(value_impl(br"hello world\", &mut Default::default()).is_err());
790791
}
791792
}
792793

gix-config/src/parse/section/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn escape_subsection(name: &BStr) -> Cow<'_, BStr> {
147147
let mut buf = Vec::with_capacity(name.len());
148148
for b in name.iter().copied() {
149149
match b {
150-
b'\\' => buf.push_str(br#"\\"#),
150+
b'\\' => buf.push_str(br"\\"),
151151
b'"' => buf.push_str(br#"\""#),
152152
_ => buf.push(b),
153153
}

gix-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ fn case_insensitive_matches_any_case() -> crate::Result {
189189
#[test]
190190
fn pattern_with_escaped_backslash() -> crate::Result {
191191
assert_section_value(
192-
original_value_on_windows(Condition::new(r#"gitdir:\\work\\tree\\/"#)),
192+
original_value_on_windows(Condition::new(r"gitdir:\\work\\tree\\/")),
193193
GitEnv::repo_name("worktree")?,
194194
)
195195
}
196196

197197
#[test]
198198
fn pattern_with_backslash() -> crate::Result {
199-
assert_section_value(Condition::new(r#"gitdir:work\tree/"#), GitEnv::repo_name("worktree")?)
199+
assert_section_value(Condition::new(r"gitdir:work\tree/"), GitEnv::repo_name("worktree")?)
200200
}
201201

202202
#[test]

gix-config/tests/file/mutable/section.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ mod set_leading_whitespace {
260260
}
261261

262262
fn multi_value_section() -> gix_config::File<'static> {
263-
r#"
263+
r"
264264
[a]
265265
a = v
266266
b =
267267
c=
268268
d
269269
e =a \
270270
b \
271-
c"#
271+
c"
272272
.parse()
273273
.unwrap()
274274
}

gix-config/tests/parse/section.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod header {
2222
#[test]
2323
fn subsection_backslashes_and_quotes_are_escaped() -> crate::Result {
2424
assert_eq!(
25-
section::Header::new("core", cow_section(r#"a\b"#))?.to_bstring(),
25+
section::Header::new("core", cow_section(r"a\b"))?.to_bstring(),
2626
r#"[core "a\\b"]"#
2727
);
2828
assert_eq!(

gix-config/tests/value/normalize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn inner_quotes_are_removed() {
6969

7070
#[test]
7171
fn newline_tab_backspace_are_escapable() {
72-
assert_eq!(normalize_bstr(r#"\n\ta\b"#), cow_str("\n\t"));
72+
assert_eq!(normalize_bstr(r"\n\ta\b"), cow_str("\n\t"));
7373
}
7474

7575
#[test]
@@ -80,7 +80,7 @@ fn tabs_are_not_resolved_to_spaces_unlike_what_git_does() {
8080
#[test]
8181
fn other_escapes_are_ignored_entirely() {
8282
assert_eq!(
83-
normalize_bstr(r#"\x"#),
83+
normalize_bstr(r"\x"),
8484
cow_str("x"),
8585
"however, these would cause failure on parsing level so we ignore it similar to subsections"
8686
);

gix-date/tests/time/parse.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ mod relative {
148148

149149
#[test]
150150
fn various() {
151-
let now = Some(SystemTime::now());
152-
let two_weeks_ago = gix_date::parse("2 weeks ago", now).unwrap();
151+
let now = SystemTime::now();
152+
let two_weeks_ago = gix_date::parse("2 weeks ago", Some(now)).unwrap();
153153
assert_eq!(Sign::Plus, two_weeks_ago.sign);
154154
assert_eq!(0, two_weeks_ago.offset);
155-
let expected = OffsetDateTime::from(now.unwrap()).saturating_sub(Duration::weeks(2));
155+
let expected = OffsetDateTime::from(now).saturating_sub(Duration::weeks(2));
156156
// account for the loss of precision when creating `Time` with seconds
157157
let expected = expected.replace_nanosecond(0).unwrap();
158158
assert_eq!(

gix-mailmap/tests/snapshot/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn non_name_and_name_mappings_will_not_clash() {
6565
"old-email",
6666
),
6767
];
68-
for entries in vec![entries.clone().into_iter().rev().collect::<Vec<_>>(), entries] {
68+
for entries in [entries.clone().into_iter().rev().collect::<Vec<_>>(), entries] {
6969
let snapshot = Snapshot::new(entries);
7070

7171
assert_eq!(

gix-odb/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@ pub fn at_opts(
148148

149149
/// Create a new cached handle to the object store.
150150
pub fn at(objects_dir: impl Into<PathBuf>) -> std::io::Result<Handle> {
151-
at_opts(objects_dir, Vec::new().into_iter(), Default::default())
151+
at_opts(objects_dir, Vec::new(), Default::default())
152152
}

gix-packetline/tests/read/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub mod streaming_peek_iter {
174174
#[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))]
175175
async fn read_from_file_and_reader_advancement() -> crate::Result {
176176
let mut bytes = fixture_bytes("v1/fetch/01-many-refs.response");
177-
bytes.extend(fixture_bytes("v1/fetch/01-many-refs.response").into_iter());
177+
bytes.extend(fixture_bytes("v1/fetch/01-many-refs.response"));
178178
let mut rd = gix_packetline::StreamingPeekableIter::new(&bytes[..], &[PacketLineRef::Flush]);
179179
let res = rd.read_line().await;
180180
assert_eq!(res.expect("line")??, first_line());

gix-revision/tests/spec/parse/anchor/colon_symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn various_forms_of_regex() {
5555

5656
#[test]
5757
fn regex_do_not_get_any_backslash_processing() {
58-
for (spec, regex) in [(r#":/{"#, "{"), (r#":/\{\}"#, r#"\{\}"#), (r#":/\\\\\}"#, r#"\\\\\}"#)] {
58+
for (spec, regex) in [(r#":/{"#, "{"), (r":/\{\}", r"\{\}"), (r":/\\\\\}", r"\\\\\}")] {
5959
let rec = parse(spec);
6060

6161
assert_eq!(rec.patterns, vec![(regex.into(), false)]);

gix-revision/tests/spec/parse/navigate/caret_symbol.rs

+19-23
Original file line numberDiff line numberDiff line change
@@ -105,40 +105,36 @@ fn regex_backslash_rules() {
105105
"matching inner parens do not need escaping",
106106
),
107107
(
108-
r#"@^{/with count\{1\}}"#,
108+
r"@^{/with count\{1\}}",
109109
r#"with count{1}"#,
110110
"escaped parens are entirely ignored",
111111
),
112-
(r#"@^{/1\}}"#, r#"1}"#, "unmatched closing parens need to be escaped"),
113-
(r#"@^{/2\{}"#, r#"2{"#, "unmatched opening parens need to be escaped"),
112+
(r"@^{/1\}}", r#"1}"#, "unmatched closing parens need to be escaped"),
113+
(r"@^{/2\{}", r#"2{"#, "unmatched opening parens need to be escaped"),
114114
(
115-
r#"@^{/3{\{}}"#,
115+
r"@^{/3{\{}}",
116116
r#"3{{}"#,
117117
"unmatched nested opening parens need to be escaped",
118118
),
119119
(
120-
r#"@^{/4{\}}}"#,
120+
r"@^{/4{\}}}",
121121
r#"4{}}"#,
122122
"unmatched nested closing parens need to be escaped",
123123
),
124+
(r"@^{/a\b\c}", r"a\b\c", "single backslashes do not need to be escaped"),
124125
(
125-
r#"@^{/a\b\c}"#,
126-
r#"a\b\c"#,
127-
"single backslashes do not need to be escaped",
128-
),
129-
(
130-
r#"@^{/a\b\c\\}"#,
131-
r#"a\b\c\"#,
126+
r"@^{/a\b\c\\}",
127+
r"a\b\c\",
132128
"single backslashes do not need to be escaped, trailing",
133129
),
134130
(
135-
r#"@^{/a\\b\\c\\}"#,
136-
r#"a\b\c\"#,
131+
r"@^{/a\\b\\c\\}",
132+
r"a\b\c\",
137133
"backslashes can be escaped nonetheless, trailing",
138134
),
139135
(
140-
r#"@^{/5\\{}}"#,
141-
r#"5\{}"#,
136+
r"@^{/5\\{}}",
137+
r"5\{}",
142138
"backslashes in front of parens must be escaped or they would unbalance the brace pair",
143139
),
144140
] {
@@ -196,11 +192,11 @@ fn invalid_object_type() {
196192

197193
#[test]
198194
fn incomplete_escaped_braces_in_regex_are_invalid() {
199-
let err = try_parse(r#"@^{/a\{1}}"#).unwrap_err();
195+
let err = try_parse(r"@^{/a\{1}}").unwrap_err();
200196
assert!(matches!(err, spec::parse::Error::UnconsumedInput {input} if input == "}"));
201197

202-
let err = try_parse(r#"@^{/a{1\}}"#).unwrap_err();
203-
assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r#"{/a{1\}}"#));
198+
let err = try_parse(r"@^{/a{1\}}").unwrap_err();
199+
assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r"{/a{1\}}"));
204200
}
205201

206202
#[test]
@@ -211,11 +207,11 @@ fn regex_with_empty_exclamation_mark_prefix_is_invalid() {
211207

212208
#[test]
213209
fn bad_escapes_can_cause_brace_mismatch() {
214-
let err = try_parse(r#"@^{\}"#).unwrap_err();
215-
assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r#"{\}"#));
210+
let err = try_parse(r"@^{\}").unwrap_err();
211+
assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r"{\}"));
216212

217-
let err = try_parse(r#"@^{{\}}"#).unwrap_err();
218-
assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r#"{{\}}"#));
213+
let err = try_parse(r"@^{{\}}").unwrap_err();
214+
assert!(matches!(err, spec::parse::Error::UnclosedBracePair {input} if input == r"{{\}}"));
219215
}
220216

221217
#[test]

gix-worktree-state/tests/state/checkout.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,11 @@ fn keep_going_collects_results() {
281281
opts,
282282
"make_mixed_without_submodules",
283283
|_id| {
284-
!matches!(
285-
count.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |current| {
284+
count
285+
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |current| {
286286
(current < 2).then_some(current + 1)
287-
}),
288-
Ok(_)
289-
)
287+
})
288+
.is_err()
290289
},
291290
|_| Ok(()),
292291
)

gix/src/config/cache/access.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ impl Cache {
7575
const DEFAULT: bool = true;
7676
self.resolved
7777
.boolean_by_key("core.commitGraph")
78-
.map(|res| {
78+
.map_or(Ok(DEFAULT), |res| {
7979
Core::COMMIT_GRAPH
8080
.enrich_error(res)
8181
.with_lenient_default_value(self.lenient_config, DEFAULT)
8282
})
83-
.unwrap_or(Ok(DEFAULT))
8483
}
8584

8685
pub(crate) fn diff_renames(

gix/src/config/tree/sections/protocol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ mod validate {
127127
.to_decimal()
128128
.ok_or_else(|| format!("integer {value} cannot be represented as integer"))?;
129129
match value {
130-
0 | 1 | 2 => Ok(()),
130+
0..=2 => Ok(()),
131131
_ => Err(format!("protocol version {value} is unknown").into()),
132132
}
133133
}

gix/src/object/tree/diff/for_each.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ impl<'a, 'old> Platform<'a, 'old> {
7575
}
7676
Err(gix_diff::tree::changes::Error::Cancelled) => delegate
7777
.err
78-
.map(|err| Err(Error::ForEach(Box::new(err))))
79-
.unwrap_or(Err(Error::Diff(gix_diff::tree::changes::Error::Cancelled))),
78+
.map_or(Err(Error::Diff(gix_diff::tree::changes::Error::Cancelled)), |err| {
79+
Err(Error::ForEach(Box::new(err)))
80+
}),
8081
Err(err) => Err(err.into()),
8182
}
8283
}

0 commit comments

Comments
 (0)