Skip to content

Commit

Permalink
thanks clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 6, 2023
1 parent 6aa63b1 commit 345712d
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 41 deletions.
23 changes: 11 additions & 12 deletions gix-attributes/src/search/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,11 @@ impl Outcome {
source: Option<&std::path::PathBuf>,
sequence_number: usize,
) -> bool {
self.attrs_stack.extend(attrs.filter_map(|attr| {
self.matches_by_id[attr.id.0]
.r#match
.is_none()
.then(|| (attr.id, attr.inner.clone(), None))
}));
self.attrs_stack.extend(
attrs
.filter(|attr| self.matches_by_id[attr.id.0].r#match.is_none())
.map(|attr| (attr.id, attr.inner.clone(), None)),
);
while let Some((id, assignment, parent_order)) = self.attrs_stack.pop() {
let slot = &mut self.matches_by_id[id.0];
if slot.r#match.is_some() {
Expand Down Expand Up @@ -212,12 +211,12 @@ impl Outcome {
if is_macro {
// TODO(borrowchk): one fine day we should be able to re-borrow `slot` without having to redo the array access.
let slot = &self.matches_by_id[id.0];
self.attrs_stack.extend(slot.macro_attributes.iter().filter_map(|attr| {
self.matches_by_id[attr.id.0]
.r#match
.is_none()
.then(|| (attr.id, attr.inner.clone(), Some(id)))
}));
self.attrs_stack.extend(
slot.macro_attributes
.iter()
.filter(|attr| self.matches_by_id[attr.id.0].r#match.is_none())
.map(|attr| (attr.id, attr.inner.clone(), Some(id))),
);
}
}
false
Expand Down
2 changes: 1 addition & 1 deletion gix-config/src/parse/section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod types {

impl PartialOrd for $name<'_> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.cmp(other).into()
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion gix-filter/src/eol/convert_to_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub(crate) mod function {
return Ok(false);
}

if let Some(()) = index_object(buf).map_err(|err| Error::FetchObjectFromIndex(err))? {
if let Some(()) = index_object(buf).map_err(Error::FetchObjectFromIndex)? {
let has_crlf_in_index = buf
.find_byte(b'\r')
.map(|_| Stats::from_bytes(buf))
Expand Down
2 changes: 1 addition & 1 deletion gix-odb/src/store_impls/dynamic/load_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ impl PartialEq<Self> for Either {

impl PartialOrd<Self> for Either {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.path().partial_cmp(other.path())
Some(self.path().cmp(other.path()))
}
}

Expand Down
3 changes: 1 addition & 2 deletions gix-pack/tests/pack/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ fn pack_lookup() -> Result<(), Box<dyn std::error::Error>> {
"iteration should yield the same pack offsets as the index"
);

let mut buf = Vec::new();
buf.resize(entry.decompressed_size as usize, 0);
let mut buf = vec![0u8; entry.decompressed_size as usize];
let pack_entry = pack.entry(offset_from_index);
assert_eq!(
pack_entry.pack_offset(),
Expand Down
4 changes: 1 addition & 3 deletions gix-packetline/tests/encode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ mod data_to_write {
#[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))]
async fn error_if_data_exceeds_limit() {
fn vec_sized(size: usize) -> Vec<u8> {
let mut v = Vec::new();
v.resize(size, 0);
v
vec![0; size]
}

let res = data_to_write(&vec_sized(65516 + 1), io::sink()).await;
Expand Down
6 changes: 1 addition & 5 deletions gix-packetline/tests/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ async fn write_text_and_write_binary() -> crate::Result {
#[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))]
async fn huge_writes_are_split_into_lines() -> crate::Result {
let buf = {
let data = {
let mut v = Vec::new();
v.resize(MAX_DATA_LEN * 2, 0);
v
};
let data = vec![0u8; MAX_DATA_LEN * 2];
let mut w = Writer::new(Vec::new());
w.write(&data).await?;
w.into_inner()
Expand Down
4 changes: 2 additions & 2 deletions gix-pathspec/tests/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ mod baseline {
is_inconsistent = spec.as_bstr() == "git-inconsistency";
!is_inconsistent
})
.filter_map(|s| (!s.trim().is_empty()).then(|| s.trim()))
.map(|pathspec| gix_pathspec::parse(pathspec, Default::default()).expect("valid pathspec"))
.filter(|s| !s.trim().is_empty())
.map(|pathspec| gix_pathspec::parse(pathspec.trim(), Default::default()).expect("valid pathspec"))
.collect();
Expected {
pathspecs,
Expand Down
2 changes: 1 addition & 1 deletion gix-ref/src/store/packed/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl packed::Transaction {
edit.peeled = loop {
let kind = find(next_id, &mut buf)?;
match kind {
Some(kind) if kind == gix_object::Kind::Tag => {
Some(gix_object::Kind::Tag) => {
next_id = gix_object::TagRefIter::from_bytes(&buf).target_id().map_err(|_| {
prepare::Error::Resolve(
format!("Couldn't get target object id from tag {next_id}").into(),
Expand Down
4 changes: 2 additions & 2 deletions gix-refspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ mod impls {

impl PartialOrd for RefSpecRef<'_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.instruction().partial_cmp(&other.instruction())
Some(self.cmp(other))
}
}

impl PartialOrd for RefSpec {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.to_ref().partial_cmp(&other.to_ref())
Some(self.to_ref().cmp(&other.to_ref()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion gix-revwalk/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<K: Ord, T> Eq for Item<K, T> {}

impl<K: Ord, T> PartialOrd<Self> for Item<K, T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Ord::cmp(self, other).into()
Some(Ord::cmp(self, other))
}
}

Expand Down
4 changes: 2 additions & 2 deletions gix/src/clone/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl PrepareFetch {
.expect("valid static spec");
let mut clone_fetch_tags = None;
if let Some(f) = self.configure_remote.as_mut() {
remote = f(remote).map_err(|err| Error::RemoteConfiguration(err))?;
remote = f(remote).map_err(Error::RemoteConfiguration)?;
} else {
clone_fetch_tags = remote::fetch::Tags::All.into();
}
Expand All @@ -117,7 +117,7 @@ impl PrepareFetch {
let pending_pack: remote::fetch::Prepare<'_, '_, _> = {
let mut connection = remote.connect(remote::Direction::Fetch).await?;
if let Some(f) = self.configure_connection.as_mut() {
f(&mut connection).map_err(|err| Error::RemoteConnection(err))?;
f(&mut connection).map_err(Error::RemoteConnection)?;
}
connection
.prepare_fetch(&mut *progress, {
Expand Down
2 changes: 1 addition & 1 deletion gix/src/clone/fetch/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn setup_branch_config(
remote_name: &BStr,
) -> Result<(), Error> {
let short_name = match branch.category_and_short_name() {
Some((cat, shortened)) if cat == gix_ref::Category::LocalBranch => match shortened.to_str() {
Some((gix_ref::Category::LocalBranch, shortened)) => match shortened.to_str() {
Ok(s) => s,
Err(_) => return Ok(()),
},
Expand Down
2 changes: 1 addition & 1 deletion gix/src/config/cache/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl Cache {
&gitoxide::Pathspec::LITERAL,
]
.iter()
.find_map(|key| (key.environment_override().expect("set") == name).then_some(key))
.find(|key| key.environment_override().expect("set") == name)
.expect("we must know all possible input variable names");

let val = self
Expand Down
2 changes: 1 addition & 1 deletion gix/src/config/tree/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod lock_timeout {
let value = value.map_err(|err| config::lock_timeout::Error::from(self).with_source(err))?;
Ok(match value {
val if val < 0 => Fail::AfterDurationWithBackoff(Duration::from_secs(u64::MAX)),
val if val == 0 => Fail::Immediately,
0 => Fail::Immediately,
val => Fail::AfterDurationWithBackoff(Duration::from_millis(
val.try_into().expect("i64 to u64 always works if positive"),
)),
Expand Down
2 changes: 1 addition & 1 deletion gix/src/repository/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl crate::Repository {
pub fn object_cache_size(&mut self, bytes: impl Into<Option<usize>>) {
let bytes = bytes.into();
match bytes {
Some(bytes) if bytes == 0 => self.objects.unset_object_cache(),
Some(0) => self.objects.unset_object_cache(),
Some(bytes) => self
.objects
.set_object_cache(move || Box::new(crate::object::cache::MemoryCappedHashmap::new(bytes))),
Expand Down
6 changes: 2 additions & 4 deletions gix/tests/clone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mod blocking_io {
let mut prepare = gix::prepare_clone_bare(remote::repo("base").path(), tmp.path())?
.with_remote_name(remote_name)?
.configure_remote({
let called_configure_remote = called_configure_remote;
move |r| {
called_configure_remote.store(true, std::sync::atomic::Ordering::Relaxed);
let mut r = r.with_fetch_tags(desired_fetch_tags);
Expand Down Expand Up @@ -372,14 +371,13 @@ mod blocking_io {
.updates
.iter()
.enumerate()
.filter_map(|(idx, update)| {
.filter(|(_, update)| {
matches!(
update.mode,
gix::remote::fetch::refs::update::Mode::ImplicitTagNotSentByRemote
)
.then(|| idx)
})
.map(|idx| &out.ref_map.mappings[idx])
.map(|(idx, _)| &out.ref_map.mappings[idx])
{
out_of_graph_tags.push(
mapping
Expand Down

0 comments on commit 345712d

Please sign in to comment.