Skip to content

Commit

Permalink
chore: Add clippy::redundant-closure-for-method-calls lint
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Jun 11, 2023
1 parent 8d2e6a9 commit bcad5c2
Show file tree
Hide file tree
Showing 97 changed files with 189 additions and 175 deletions.
2 changes: 1 addition & 1 deletion cargo-smart-release/src/changelog/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Section {
},
) => {
assert!(src_unknown.is_empty(), "shouldn't ever generate 'unknown' portions");
let has_no_read_only_segments = !dest_segments.iter().any(|s| s.is_read_only());
let has_no_read_only_segments = !dest_segments.iter().any(Segment::is_read_only);
let mode = if has_no_read_only_segments {
ReplaceMode::ReplaceAllOrAppend
} else {
Expand Down
4 changes: 2 additions & 2 deletions cargo-smart-release/src/changelog/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl<'a> TryFrom<&'a str> for Headline {

fn headline<'a, E: ParseError<&'a str> + FromExternalError<&'a str, ()>>(i: &'a str) -> IResult<&'a str, Headline, E> {
let hashes = take_while(|c: char| c == '#');
let greedy_whitespace = |i| take_while(|c: char| c.is_whitespace())(i);
let greedy_whitespace = |i| take_while(char::is_whitespace)(i);
let take_n_digits = |n: usize| {
map_res(take_while_m_n(n, n, |c: char| c.is_ascii_digit()), |num| {
u32::from_str(num).map_err(|_| ())
Expand All @@ -488,7 +488,7 @@ fn headline<'a, E: ParseError<&'a str> + FromExternalError<&'a str, ()>>(i: &'a
alt((
tuple((
opt(tag("v")),
map_res(take_till(|c: char| c.is_whitespace()), |v| {
map_res(take_till(char::is_whitespace), |v| {
semver::Version::parse(v).map_err(|_| ()).map(Some)
}),
)),
Expand Down
2 changes: 1 addition & 1 deletion cargo-smart-release/src/command/release/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ fn set_version_and_update_package_dependency(
{
if let Some(current_version_req) = dep_table
.get_mut(name_to_find)
.and_then(|name| name.as_inline_table_mut())
.and_then(toml_edit::Item::as_inline_table_mut)
.and_then(|name_table| name_table.get_mut("version"))
{
let version_req = VersionReq::parse(current_version_req.as_str().expect("versions are strings"))?;
Expand Down
4 changes: 3 additions & 1 deletion cargo-smart-release/src/commit/message.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use gix::bstr::ByteSlice;

use crate::commit::Message;
Expand Down Expand Up @@ -107,7 +109,7 @@ impl From<&'_ str> for Message {
Message {
title: title.into_owned(),
kind: as_static_str(kind),
body: body.map(|b| b.into_owned()),
body: body.map(Cow::into_owned),
breaking,
breaking_description: breaking_description.map(ToOwned::to_owned),
additions,
Expand Down
5 changes: 3 additions & 2 deletions cargo-smart-release/src/git/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use gix::{
bstr::ByteSlice,
head,
prelude::{ObjectIdExt, ReferenceExt},
Reference,
};

use crate::{
Expand Down Expand Up @@ -106,7 +107,7 @@ pub fn crate_ref_segments<'h>(
Some(prefix) => BTreeMap::from_iter(
refs.prefixed(PathBuf::from(format!("refs/tags/{prefix}-")))?
.peeled()
.filter_map(|r| r.ok().map(|r| r.detach()))
.filter_map(|r| r.ok().map(Reference::detach))
.filter(|r| is_tag_name(prefix, strip_tag_path(r.name.as_ref())))
.map(|r| {
let t = r.peeled.expect("already peeled");
Expand All @@ -116,7 +117,7 @@ pub fn crate_ref_segments<'h>(
None => BTreeMap::from_iter(
refs.prefixed("refs/tags")?
.peeled()
.filter_map(|r| r.ok().map(|r| r.detach()))
.filter_map(|r| r.ok().map(Reference::detach))
.filter(|r| is_tag_version(strip_tag_path(r.name.as_ref())))
.map(|r| {
let t = r.peeled.expect("already peeled");
Expand Down
2 changes: 1 addition & 1 deletion cargo-smart-release/src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ pub fn strip_tag_path(name: &FullNameRef) -> &BStr {
}

pub fn try_strip_tag_path(name: &FullNameRef) -> Option<&BStr> {
name.as_bstr().strip_prefix(b"refs/tags/").map(|b| b.as_bstr())
name.as_bstr().strip_prefix(b"refs/tags/").map(ByteSlice::as_bstr)
}
3 changes: 1 addition & 2 deletions cargo-smart-release/src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ fn forward_propagate_breaking_changes_for_manifest_updates<'meta>(
let crate_is_known_already = crates
.iter()
.find_map(|c| {
(c.package.id == dependant.id)
.then(|| c.mode.version_adjustment_bump().map(|b| b.is_breaking()))
(c.package.id == dependant.id).then(|| c.mode.version_adjustment_bump().map(Bump::is_breaking))
})
.flatten();

Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/index/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod serde_only {
name: t.name.as_bstr().to_string(),
id: t.id.to_hex().to_string(),
num_entries: t.num_entries,
children: t.children.iter().map(|t| t.into()).collect(),
children: t.children.iter().map(Into::into).collect(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/pack/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where
ObjectId::from_hex(&Vec::from_os_str_lossy(tip.as_ref())).or_else(|_| {
easy.find_reference(tip.as_ref())
.map_err(anyhow::Error::from)
.and_then(|r| r.into_fully_peeled_id().map(|oid| oid.detach()).map_err(Into::into))
.and_then(|r| r.into_fully_peeled_id().map(gix::Id::detach).map_err(Into::into))
})
}
})
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/pack/verify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io, path::Path, str::FromStr, sync::atomic::AtomicBool};
use std::{ffi::OsStr, io, path::Path, str::FromStr, sync::atomic::AtomicBool};

use anyhow::{anyhow, Context as AnyhowContext, Result};
use bytesize::ByteSize;
Expand Down Expand Up @@ -104,7 +104,7 @@ where
W2: io::Write,
{
let path = path.as_ref();
let ext = path.extension().and_then(|ext| ext.to_str()).unwrap_or("");
let ext = path.extension().and_then(OsStr::to_str).unwrap_or("");
const CACHE_SIZE: usize = 64;
let cache = || -> EitherCache<CACHE_SIZE> {
if matches!(algorithm, Algorithm::LessMemory) {
Expand Down
3 changes: 2 additions & 1 deletion gitoxide-core/src/repository/attributes/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Options {

pub(crate) mod function {
use std::io;
use std::path::Path;

use anyhow::bail;
use gix::prelude::FindExt;
Expand Down Expand Up @@ -43,7 +44,7 @@ pub(crate) mod function {
writeln!(
out,
"{}:{}:{}\t{}\t{}",
m.location.source.map(|p| p.to_string_lossy()).unwrap_or_default(),
m.location.source.map(Path::to_string_lossy).unwrap_or_default(),
m.location.sequence_number,
m.pattern,
path,
Expand Down
6 changes: 3 additions & 3 deletions gitoxide-core/src/repository/attributes/validate_baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) mod function {
};

use anyhow::{anyhow, bail};
use gix::{odb::FindExt, Progress};
use gix::{attrs::Assignment, odb::FindExt, Progress};

use crate::{
repository::attributes::{query::attributes_cache, validate_baseline::Options},
Expand Down Expand Up @@ -207,11 +207,11 @@ pub(crate) mod function {
let fast_path_mismatch = matches
.iter()
.map(|m| m.assignment)
.zip(expected.iter().map(|a| a.as_ref()))
.zip(expected.iter().map(Assignment::as_ref))
.any(|(a, b)| a != b);
if fast_path_mismatch {
let actual_set = BTreeSet::from_iter(matches.iter().map(|m| m.assignment));
let expected_set = BTreeSet::from_iter(expected.iter().map(|a| a.as_ref()));
let expected_set = BTreeSet::from_iter(expected.iter().map(Assignment::as_ref));
let too_few_or_too_many =
!(expected_set.sub(&actual_set).is_empty() && actual_set.sub(&expected_set).is_empty());
if too_few_or_too_many {
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn query(
Some(m) => writeln!(
out,
"{}:{}:{}\t{}",
m.source.map(|p| p.to_string_lossy()).unwrap_or_default(),
m.source.map(std::path::Path::to_string_lossy).unwrap_or_default(),
m.sequence_number,
m.pattern,
path
Expand Down
4 changes: 2 additions & 2 deletions gitoxide-core/src/repository/revision/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a> delegate::Revision for Explain<'a> {
fn reflog(&mut self, query: ReflogLookup) -> Option<()> {
self.prefix()?;
self.has_implicit_anchor = true;
let ref_name: &BStr = self.ref_name.as_ref().map_or_else(|| "HEAD".into(), |n| n.as_ref());
let ref_name: &BStr = self.ref_name.as_ref().map_or_else(|| "HEAD".into(), AsRef::as_ref);
match query {
ReflogLookup::Entry(no) => writeln!(self.out, "Find entry {no} in reflog of '{ref_name}' reference").ok(),
ReflogLookup::Date(time) => writeln!(
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<'a> delegate::Navigate for Explain<'a> {
match self
.ref_name
.as_ref()
.map(|n| n.to_string())
.map(ToString::to_string)
.or_else(|| self.oid_prefix.map(|p| p.to_string()))
{
Some(obj_name) => format!(
Expand Down
5 changes: 3 additions & 2 deletions gitoxide-core/src/repository/revision/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) mod function {
use std::ffi::OsString;

use anyhow::Context;
use gix::revision::Spec;

use super::Options;
use crate::{repository::revision, OutputFormat};
Expand Down Expand Up @@ -53,7 +54,7 @@ pub(crate) mod function {
gix::path::os_str_into_bstr(&spec)
.map_err(anyhow::Error::from)
.and_then(|spec| repo.rev_parse(spec).map_err(Into::into))
.map(|spec| spec.detach())
.map(Spec::detach)
})
.collect::<Result<Vec<_>, _>>()?,
)?;
Expand All @@ -62,7 +63,7 @@ pub(crate) mod function {
Ok(())
}

fn display_object(spec: gix::revision::Spec<'_>, mut out: impl std::io::Write) -> anyhow::Result<()> {
fn display_object(spec: Spec<'_>, mut out: impl std::io::Write) -> anyhow::Result<()> {
let id = spec.single().context("rev-spec must resolve to a single object")?;
let object = id.object()?;
match object.kind {
Expand Down
2 changes: 1 addition & 1 deletion gix-attributes/src/search/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl MatchLocation {
crate::search::MatchLocation {
source: self
.source
.and_then(|source| out.source_paths.resolve(source).map(|p| p.as_path())),
.and_then(|source| out.source_paths.resolve(source).map(AsRef::as_ref)),
sequence_number: self.sequence_number,
}
}
Expand Down
6 changes: 3 additions & 3 deletions gix-commitgraph/src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ impl Graph {

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion gix-commitgraph/src/file/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl File {
fn verify_split_chain_filename_hash(path: impl AsRef<Path>, expected: &gix_hash::oid) -> Result<(), String> {
let path = path.as_ref();
path.file_name()
.and_then(|filename| filename.to_str())
.and_then(std::ffi::OsStr::to_str)
.and_then(|filename| filename.strip_suffix(".graph"))
.and_then(|stem| stem.strip_prefix("graph-"))
.map_or(Ok(()), |hex| match gix_hash::ObjectId::from_hex(hex.as_bytes()) {
Expand Down
2 changes: 1 addition & 1 deletion gix-commitgraph/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Graph {

for (base_graph_index, (expected, actual)) in self.files[..file_index]
.iter()
.map(|base_file| base_file.checksum())
.map(crate::File::checksum)
.zip(file.iter_base_graph_ids())
.enumerate()
{
Expand Down
4 changes: 2 additions & 2 deletions gix-commitgraph/tests/commitgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa

assert_eq!(
cg.iter_ids().collect::<HashSet<_>>(),
expected.values().map(|x| x.id()).collect::<HashSet<_>>()
expected.values().map(RefInfo::id).collect::<HashSet<_>>()
);
}

Expand Down Expand Up @@ -99,7 +99,7 @@ impl RefInfo {
}

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

pub fn root_tree_id(&self) -> &gix_hash::oid {
Expand Down
2 changes: 1 addition & 1 deletion gix-config/src/file/access/comfort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'event> File<'event> {
continue;
}
match section.value_implicit(key) {
Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(|b| b.into())),
Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(Into::into)),
Some(None) => return Some(Ok(true)),
None => continue,
}
Expand Down
4 changes: 3 additions & 1 deletion gix-config/src/file/init/comfort.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use crate::{
file::{init, Metadata},
path, source, File, Source,
Expand Down Expand Up @@ -30,7 +32,7 @@ impl File<'static> {
let path = source
.storage_location(&mut gix_path::env::var)
.and_then(|p| p.is_file().then_some(p))
.map(|p| p.into_owned());
.map(Cow::into_owned);

Metadata {
path,
Expand Down
4 changes: 2 additions & 2 deletions gix-config/src/file/mutable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub(crate) mod section;
pub(crate) mod value;

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

Expand Down
2 changes: 1 addition & 1 deletion gix-config/src/file/mutable/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<'a, 'event> SectionMut<'a, 'event> {
assert!(
whitespace
.as_deref()
.map_or(true, |ws| ws.iter().all(|b| b.is_ascii_whitespace())),
.map_or(true, |ws| ws.iter().all(u8::is_ascii_whitespace)),
"input whitespace must only contain whitespace characters."
);
self.whitespace.pre_key = whitespace;
Expand Down
2 changes: 1 addition & 1 deletion gix-config/src/file/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) fn ends_with_newline(e: &[crate::parse::Event<'_>], nl: impl AsRef<[u
}
e.iter()
.rev()
.take_while(|e| e.to_bstr_lossy().iter().all(|b| b.is_ascii_whitespace()))
.take_while(|e| e.to_bstr_lossy().iter().all(u8::is_ascii_whitespace))
.find_map(|e| e.to_bstr_lossy().contains_str(nl.as_ref()).then_some(true))
.unwrap_or(false)
}
Expand Down
2 changes: 1 addition & 1 deletion gix-config/tests/file/init/from_paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn frontmatter_is_maintained_in_multiple_files() -> crate::Result {
config
.frontmatter()
.expect("present")
.map(|e| e.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(""),
";before a\n"
Expand Down
2 changes: 1 addition & 1 deletion gix-config/tests/file/mutable/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod push {
let (pre_sep, post_sep) = expected_sep;
assert_eq!(
section.separator_whitespace(),
(pre_sep.map(|s| s.into()), post_sep.map(|s| s.into())),
(pre_sep.map(Into::into), post_sep.map(Into::into)),
"{input:?} should find {expected_sep:?} as sep whitespace"
);
}
Expand Down
9 changes: 5 additions & 4 deletions gix-credentials/src/protocol/context/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ pub mod decode {
let mut ctx = Context::default();
for res in input.lines().take_while(|line| !line.is_empty()).map(|line| {
let mut it = line.splitn(2, |b| *b == b'=');
match (it.next().and_then(|k| k.to_str().ok()), it.next().map(|v| v.as_bstr())) {
match (
it.next().and_then(|k| k.to_str().ok()),
it.next().map(ByteSlice::as_bstr),
) {
(Some(key), Some(value)) => validate(key, value)
.map(|_| (key, value.to_owned()))
.map_err(Into::into),
Expand All @@ -99,9 +102,7 @@ pub mod decode {
"url" => ctx.url = Some(value),
"path" => ctx.path = Some(value),
"quit" => {
ctx.quit = gix_config_value::Boolean::try_from(value.as_ref())
.ok()
.map(|b| b.into());
ctx.quit = gix_config_value::Boolean::try_from(value.as_ref()).ok().map(Into::into);
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion gix-date/src/time/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Time {
// TODO: make this work without cfg(unsound_local_offset), see
// https://github.com/time-rs/time/issues/293#issuecomment-909158529
let offset = time::UtcOffset::local_offset_at(now)
.map(|ofs| ofs.whole_seconds())
.map(time::UtcOffset::whole_seconds)
.unwrap_or(0);
Self {
seconds,
Expand Down
Loading

0 comments on commit bcad5c2

Please sign in to comment.