Skip to content

Commit fe59956

Browse files
committed
Merge branch 'help-874-redundant-closures'
2 parents 2213321 + cd747f9 commit fe59956

File tree

97 files changed

+191
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+191
-174
lines changed

cargo-smart-release/src/changelog/merge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Section {
9090
},
9191
) => {
9292
assert!(src_unknown.is_empty(), "shouldn't ever generate 'unknown' portions");
93-
let has_no_read_only_segments = !dest_segments.iter().any(|s| s.is_read_only());
93+
let has_no_read_only_segments = !dest_segments.iter().any(Segment::is_read_only);
9494
let mode = if has_no_read_only_segments {
9595
ReplaceMode::ReplaceAllOrAppend
9696
} else {

cargo-smart-release/src/changelog/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl<'a> TryFrom<&'a str> for Headline {
473473

474474
fn headline<'a, E: ParseError<&'a str> + FromExternalError<&'a str, ()>>(i: &'a str) -> IResult<&'a str, Headline, E> {
475475
let hashes = take_while(|c: char| c == '#');
476-
let greedy_whitespace = |i| take_while(|c: char| c.is_whitespace())(i);
476+
let greedy_whitespace = |i| take_while(char::is_whitespace)(i);
477477
let take_n_digits = |n: usize| {
478478
map_res(take_while_m_n(n, n, |c: char| c.is_ascii_digit()), |num| {
479479
u32::from_str(num).map_err(|_| ())
@@ -488,7 +488,7 @@ fn headline<'a, E: ParseError<&'a str> + FromExternalError<&'a str, ()>>(i: &'a
488488
alt((
489489
tuple((
490490
opt(tag("v")),
491-
map_res(take_till(|c: char| c.is_whitespace()), |v| {
491+
map_res(take_till(char::is_whitespace), |v| {
492492
semver::Version::parse(v).map_err(|_| ()).map(Some)
493493
}),
494494
)),

cargo-smart-release/src/command/release/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ fn set_version_and_update_package_dependency(
527527
{
528528
if let Some(current_version_req) = dep_table
529529
.get_mut(name_to_find)
530-
.and_then(|name| name.as_inline_table_mut())
530+
.and_then(toml_edit::Item::as_inline_table_mut)
531531
.and_then(|name_table| name_table.get_mut("version"))
532532
{
533533
let version_req = VersionReq::parse(current_version_req.as_str().expect("versions are strings"))?;

cargo-smart-release/src/commit/message.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use gix::bstr::ByteSlice;
24

35
use crate::commit::Message;
@@ -107,7 +109,7 @@ impl From<&'_ str> for Message {
107109
Message {
108110
title: title.into_owned(),
109111
kind: as_static_str(kind),
110-
body: body.map(|b| b.into_owned()),
112+
body: body.map(Cow::into_owned),
111113
breaking,
112114
breaking_description: breaking_description.map(ToOwned::to_owned),
113115
additions,

cargo-smart-release/src/git/history.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use gix::{
1111
bstr::ByteSlice,
1212
head,
1313
prelude::{ObjectIdExt, ReferenceExt},
14+
Reference,
1415
};
1516

1617
use crate::{
@@ -106,7 +107,7 @@ pub fn crate_ref_segments<'h>(
106107
Some(prefix) => BTreeMap::from_iter(
107108
refs.prefixed(PathBuf::from(format!("refs/tags/{prefix}-")))?
108109
.peeled()
109-
.filter_map(|r| r.ok().map(|r| r.detach()))
110+
.filter_map(|r| r.ok().map(Reference::detach))
110111
.filter(|r| is_tag_name(prefix, strip_tag_path(r.name.as_ref())))
111112
.map(|r| {
112113
let t = r.peeled.expect("already peeled");
@@ -116,7 +117,7 @@ pub fn crate_ref_segments<'h>(
116117
None => BTreeMap::from_iter(
117118
refs.prefixed("refs/tags")?
118119
.peeled()
119-
.filter_map(|r| r.ok().map(|r| r.detach()))
120+
.filter_map(|r| r.ok().map(Reference::detach))
120121
.filter(|r| is_tag_version(strip_tag_path(r.name.as_ref())))
121122
.map(|r| {
122123
let t = r.peeled.expect("already peeled");

cargo-smart-release/src/git/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ pub fn strip_tag_path(name: &FullNameRef) -> &BStr {
110110
}
111111

112112
pub fn try_strip_tag_path(name: &FullNameRef) -> Option<&BStr> {
113-
name.as_bstr().strip_prefix(b"refs/tags/").map(|b| b.as_bstr())
113+
name.as_bstr().strip_prefix(b"refs/tags/").map(ByteSlice::as_bstr)
114114
}

cargo-smart-release/src/traverse.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ fn forward_propagate_breaking_changes_for_manifest_updates<'meta>(
281281
let crate_is_known_already = crates
282282
.iter()
283283
.find_map(|c| {
284-
(c.package.id == dependant.id)
285-
.then(|| c.mode.version_adjustment_bump().map(|b| b.is_breaking()))
284+
(c.package.id == dependant.id).then(|| c.mode.version_adjustment_bump().map(Bump::is_breaking))
286285
})
287286
.flatten();
288287

gitoxide-core/src/index/information.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod serde_only {
2828
name: t.name.as_bstr().to_string(),
2929
id: t.id.to_hex().to_string(),
3030
num_entries: t.num_entries,
31-
children: t.children.iter().map(|t| t.into()).collect(),
31+
children: t.children.iter().map(Into::into).collect(),
3232
}
3333
}
3434
}

gitoxide-core/src/pack/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ where
130130
ObjectId::from_hex(&Vec::from_os_str_lossy(tip.as_ref())).or_else(|_| {
131131
easy.find_reference(tip.as_ref())
132132
.map_err(anyhow::Error::from)
133-
.and_then(|r| r.into_fully_peeled_id().map(|oid| oid.detach()).map_err(Into::into))
133+
.and_then(|r| r.into_fully_peeled_id().map(gix::Id::detach).map_err(Into::into))
134134
})
135135
}
136136
})

gitoxide-core/src/pack/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{io, path::Path, str::FromStr, sync::atomic::AtomicBool};
1+
use std::{ffi::OsStr, io, path::Path, str::FromStr, sync::atomic::AtomicBool};
22

33
use anyhow::{anyhow, Context as AnyhowContext, Result};
44
use bytesize::ByteSize;
@@ -104,7 +104,7 @@ where
104104
W2: io::Write,
105105
{
106106
let path = path.as_ref();
107-
let ext = path.extension().and_then(|ext| ext.to_str()).unwrap_or("");
107+
let ext = path.extension().and_then(OsStr::to_str).unwrap_or("");
108108
const CACHE_SIZE: usize = 64;
109109
let cache = || -> EitherCache<CACHE_SIZE> {
110110
if matches!(algorithm, Algorithm::LessMemory) {

gitoxide-core/src/repository/attributes/query.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Options {
77

88
pub(crate) mod function {
99
use std::io;
10+
use std::path::Path;
1011

1112
use anyhow::bail;
1213
use gix::prelude::FindExt;
@@ -43,7 +44,7 @@ pub(crate) mod function {
4344
writeln!(
4445
out,
4546
"{}:{}:{}\t{}\t{}",
46-
m.location.source.map(|p| p.to_string_lossy()).unwrap_or_default(),
47+
m.location.source.map(Path::to_string_lossy).unwrap_or_default(),
4748
m.location.sequence_number,
4849
m.pattern,
4950
path,

gitoxide-core/src/repository/attributes/validate_baseline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) mod function {
1818
};
1919

2020
use anyhow::{anyhow, bail};
21-
use gix::{odb::FindExt, Progress};
21+
use gix::{attrs::Assignment, odb::FindExt, Progress};
2222

2323
use crate::{
2424
repository::attributes::{query::attributes_cache, validate_baseline::Options},
@@ -207,11 +207,11 @@ pub(crate) mod function {
207207
let fast_path_mismatch = matches
208208
.iter()
209209
.map(|m| m.assignment)
210-
.zip(expected.iter().map(|a| a.as_ref()))
210+
.zip(expected.iter().map(Assignment::as_ref))
211211
.any(|(a, b)| a != b);
212212
if fast_path_mismatch {
213213
let actual_set = BTreeSet::from_iter(matches.iter().map(|m| m.assignment));
214-
let expected_set = BTreeSet::from_iter(expected.iter().map(|a| a.as_ref()));
214+
let expected_set = BTreeSet::from_iter(expected.iter().map(Assignment::as_ref));
215215
let too_few_or_too_many =
216216
!(expected_set.sub(&actual_set).is_empty() && actual_set.sub(&expected_set).is_empty());
217217
if too_few_or_too_many {

gitoxide-core/src/repository/exclude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn query(
5656
Some(m) => writeln!(
5757
out,
5858
"{}:{}:{}\t{}",
59-
m.source.map(|p| p.to_string_lossy()).unwrap_or_default(),
59+
m.source.map(std::path::Path::to_string_lossy).unwrap_or_default(),
6060
m.sequence_number,
6161
m.pattern,
6262
path

gitoxide-core/src/repository/revision/explain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a> delegate::Revision for Explain<'a> {
8282
fn reflog(&mut self, query: ReflogLookup) -> Option<()> {
8383
self.prefix()?;
8484
self.has_implicit_anchor = true;
85-
let ref_name: &BStr = self.ref_name.as_ref().map_or_else(|| "HEAD".into(), |n| n.as_ref());
85+
let ref_name: &BStr = self.ref_name.as_ref().map_or_else(|| "HEAD".into(), AsRef::as_ref);
8686
match query {
8787
ReflogLookup::Entry(no) => writeln!(self.out, "Find entry {no} in reflog of '{ref_name}' reference").ok(),
8888
ReflogLookup::Date(time) => writeln!(
@@ -161,7 +161,7 @@ impl<'a> delegate::Navigate for Explain<'a> {
161161
match self
162162
.ref_name
163163
.as_ref()
164-
.map(|n| n.to_string())
164+
.map(ToString::to_string)
165165
.or_else(|| self.oid_prefix.map(|p| p.to_string()))
166166
{
167167
Some(obj_name) => format!(

gitoxide-core/src/repository/revision/resolve.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) mod function {
1010
use std::ffi::OsString;
1111

1212
use anyhow::Context;
13+
use gix::revision::Spec;
1314

1415
use super::Options;
1516
use crate::{repository::revision, OutputFormat};
@@ -53,7 +54,7 @@ pub(crate) mod function {
5354
gix::path::os_str_into_bstr(&spec)
5455
.map_err(anyhow::Error::from)
5556
.and_then(|spec| repo.rev_parse(spec).map_err(Into::into))
56-
.map(|spec| spec.detach())
57+
.map(Spec::detach)
5758
})
5859
.collect::<Result<Vec<_>, _>>()?,
5960
)?;
@@ -62,7 +63,7 @@ pub(crate) mod function {
6263
Ok(())
6364
}
6465

65-
fn display_object(spec: gix::revision::Spec<'_>, mut out: impl std::io::Write) -> anyhow::Result<()> {
66+
fn display_object(spec: Spec<'_>, mut out: impl std::io::Write) -> anyhow::Result<()> {
6667
let id = spec.single().context("rev-spec must resolve to a single object")?;
6768
let object = id.object()?;
6869
match object.kind {

gix-attributes/src/search/outcome.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl MatchLocation {
357357
crate::search::MatchLocation {
358358
source: self
359359
.source
360-
.and_then(|source| out.source_paths.resolve(source).map(|p| p.as_path())),
360+
.and_then(|source| out.source_paths.resolve(source).map(AsRef::as_ref)),
361361
sequence_number: self.sequence_number,
362362
}
363363
}

gix-commitgraph/src/access.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ impl Graph {
2828

2929
/// Iterate over commits in unsorted order.
3030
pub fn iter_commits(&self) -> impl Iterator<Item = Commit<'_>> {
31-
self.files.iter().flat_map(|file| file.iter_commits())
31+
self.files.iter().flat_map(File::iter_commits)
3232
}
3333

3434
/// Iterate over commit IDs in unsorted order.
3535
pub fn iter_ids(&self) -> impl Iterator<Item = &gix_hash::oid> {
36-
self.files.iter().flat_map(|file| file.iter_ids())
36+
self.files.iter().flat_map(File::iter_ids)
3737
}
3838

3939
/// Translate the given `id` to its position in the file.
@@ -43,7 +43,7 @@ impl Graph {
4343

4444
/// Returns the number of commits stored in this file.
4545
pub fn num_commits(&self) -> u32 {
46-
self.files.iter().map(|f| f.num_commits()).sum()
46+
self.files.iter().map(File::num_commits).sum()
4747
}
4848
}
4949

gix-commitgraph/src/file/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl File {
163163
fn verify_split_chain_filename_hash(path: impl AsRef<Path>, expected: &gix_hash::oid) -> Result<(), String> {
164164
let path = path.as_ref();
165165
path.file_name()
166-
.and_then(|filename| filename.to_str())
166+
.and_then(std::ffi::OsStr::to_str)
167167
.and_then(|filename| filename.strip_suffix(".graph"))
168168
.and_then(|stem| stem.strip_prefix("graph-"))
169169
.map_or(Ok(()), |hex| match gix_hash::ObjectId::from_hex(hex.as_bytes()) {

gix-commitgraph/src/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Graph {
111111

112112
for (base_graph_index, (expected, actual)) in self.files[..file_index]
113113
.iter()
114-
.map(|base_file| base_file.checksum())
114+
.map(crate::File::checksum)
115115
.zip(file.iter_base_graph_ids())
116116
.enumerate()
117117
{

gix-commitgraph/tests/commitgraph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa
5757

5858
assert_eq!(
5959
cg.iter_ids().collect::<HashSet<_>>(),
60-
expected.values().map(|x| x.id()).collect::<HashSet<_>>()
60+
expected.values().map(RefInfo::id).collect::<HashSet<_>>()
6161
);
6262
}
6363

@@ -99,7 +99,7 @@ impl RefInfo {
9999
}
100100

101101
pub fn parent_ids(&self) -> impl Iterator<Item = &gix_hash::oid> {
102-
self.parent_ids.iter().map(|x| x.as_ref())
102+
self.parent_ids.iter().map(AsRef::as_ref)
103103
}
104104

105105
pub fn root_tree_id(&self) -> &gix_hash::oid {

gix-config/src/file/access/comfort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'event> File<'event> {
127127
continue;
128128
}
129129
match section.value_implicit(key) {
130-
Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(|b| b.into())),
130+
Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(Into::into)),
131131
Some(None) => return Some(Ok(true)),
132132
None => continue,
133133
}

gix-config/src/file/init/comfort.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use crate::{
24
file::{init, Metadata},
35
path, source, File, Source,
@@ -30,7 +32,7 @@ impl File<'static> {
3032
let path = source
3133
.storage_location(&mut gix_path::env::var)
3234
.and_then(|p| p.is_file().then_some(p))
33-
.map(|p| p.into_owned());
35+
.map(Cow::into_owned);
3436

3537
Metadata {
3638
path,

gix-config/src/file/mutable/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ pub(crate) mod section;
99
pub(crate) mod value;
1010

1111
fn escape_value(value: &BStr) -> BString {
12-
let starts_with_whitespace = value.first().map_or(false, |b| b.is_ascii_whitespace());
12+
let starts_with_whitespace = value.first().map_or(false, u8::is_ascii_whitespace);
1313
let ends_with_whitespace = value
1414
.get(value.len().saturating_sub(1))
15-
.map_or(false, |b| b.is_ascii_whitespace());
15+
.map_or(false, u8::is_ascii_whitespace);
1616
let contains_comment_indicators = value.find_byteset(b";#").is_some();
1717
let quote = starts_with_whitespace || ends_with_whitespace || contains_comment_indicators;
1818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'a, 'event> SectionMut<'a, 'event> {
185185
assert!(
186186
whitespace
187187
.as_deref()
188-
.map_or(true, |ws| ws.iter().all(|b| b.is_ascii_whitespace())),
188+
.map_or(true, |ws| ws.iter().all(u8::is_ascii_whitespace)),
189189
"input whitespace must only contain whitespace characters."
190190
);
191191
self.whitespace.pre_key = whitespace;

gix-config/src/file/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(crate) fn ends_with_newline(e: &[crate::parse::Event<'_>], nl: impl AsRef<[u
7676
}
7777
e.iter()
7878
.rev()
79-
.take_while(|e| e.to_bstr_lossy().iter().all(|b| b.is_ascii_whitespace()))
79+
.take_while(|e| e.to_bstr_lossy().iter().all(u8::is_ascii_whitespace))
8080
.find_map(|e| e.to_bstr_lossy().contains_str(nl.as_ref()).then_some(true))
8181
.unwrap_or(false)
8282
}

gix-config/tests/file/init/from_paths/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn frontmatter_is_maintained_in_multiple_files() -> crate::Result {
118118
config
119119
.frontmatter()
120120
.expect("present")
121-
.map(|e| e.to_string())
121+
.map(ToString::to_string)
122122
.collect::<Vec<_>>()
123123
.join(""),
124124
";before a\n"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod push {
169169
let (pre_sep, post_sep) = expected_sep;
170170
assert_eq!(
171171
section.separator_whitespace(),
172-
(pre_sep.map(|s| s.into()), post_sep.map(|s| s.into())),
172+
(pre_sep.map(Into::into), post_sep.map(Into::into)),
173173
"{input:?} should find {expected_sep:?} as sep whitespace"
174174
);
175175
}

gix-credentials/src/protocol/context/serde.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ pub mod decode {
7474
let mut ctx = Context::default();
7575
for res in input.lines().take_while(|line| !line.is_empty()).map(|line| {
7676
let mut it = line.splitn(2, |b| *b == b'=');
77-
match (it.next().and_then(|k| k.to_str().ok()), it.next().map(|v| v.as_bstr())) {
77+
match (
78+
it.next().and_then(|k| k.to_str().ok()),
79+
it.next().map(ByteSlice::as_bstr),
80+
) {
7881
(Some(key), Some(value)) => validate(key, value)
7982
.map(|_| (key, value.to_owned()))
8083
.map_err(Into::into),
@@ -99,9 +102,7 @@ pub mod decode {
99102
"url" => ctx.url = Some(value),
100103
"path" => ctx.path = Some(value),
101104
"quit" => {
102-
ctx.quit = gix_config_value::Boolean::try_from(value.as_ref())
103-
.ok()
104-
.map(|b| b.into());
105+
ctx.quit = gix_config_value::Boolean::try_from(value.as_ref()).ok().map(Into::into);
105106
}
106107
_ => {}
107108
}

gix-date/src/time/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Time {
5757
// TODO: make this work without cfg(unsound_local_offset), see
5858
// https://github.com/time-rs/time/issues/293#issuecomment-909158529
5959
let offset = time::UtcOffset::local_offset_at(now)
60-
.map(|ofs| ofs.whole_seconds())
60+
.map(time::UtcOffset::whole_seconds)
6161
.unwrap_or(0);
6262
Self {
6363
seconds,

0 commit comments

Comments
 (0)