Skip to content

Applied clippy cloned->copied, and cleanup #3014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bindgen/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub(crate) mod attributes {
pub(crate) fn repr_list(which_ones: &[&str]) -> TokenStream {
let which_ones = which_ones
.iter()
.cloned()
.map(|one| TokenStream::from_str(one).expect("repr to be valid"));
quote! {
#[repr( #( #which_ones ),* )]
Expand All @@ -29,7 +28,6 @@ pub(crate) mod attributes {
pub(crate) fn derives(which_ones: &[&str]) -> TokenStream {
let which_ones = which_ones
.iter()
.cloned()
.map(|one| TokenStream::from_str(one).expect("derive to be valid"));
quote! {
#[derive( #( #which_ones ),* )]
Expand Down
10 changes: 5 additions & 5 deletions bindgen/ir/analysis/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl CannotDerive<'_> {
// Complex cases need more information
TypeKind::Array(t, len) => {
let inner_type =
self.can_derive.get(&t.into()).cloned().unwrap_or_default();
self.can_derive.get(&t.into()).copied().unwrap_or_default();
if inner_type != CanDerive::Yes {
trace!(
" arrays of T for which we cannot derive {} \
Expand Down Expand Up @@ -273,7 +273,7 @@ impl CannotDerive<'_> {
}
TypeKind::Vector(t, len) => {
let inner_type =
self.can_derive.get(&t.into()).cloned().unwrap_or_default();
self.can_derive.get(&t.into()).copied().unwrap_or_default();
if inner_type != CanDerive::Yes {
trace!(
" vectors of T for which we cannot derive {} \
Expand Down Expand Up @@ -428,7 +428,7 @@ impl CannotDerive<'_> {

let can_derive = self.can_derive
.get(&sub_id)
.cloned()
.copied()
.unwrap_or_default();

match can_derive {
Expand Down Expand Up @@ -642,7 +642,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
self.ctx
.allowlisted_items()
.iter()
.cloned()
.copied()
.flat_map(|i| {
let mut reachable = vec![i];
i.trace(
Expand All @@ -660,7 +660,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
fn constrain(&mut self, id: ItemId) -> ConstrainResult {
trace!("constrain: {:?}", id);

if let Some(CanDerive::No) = self.can_derive.get(&id).cloned() {
if let Some(CanDerive::No) = self.can_derive.get(&id) {
trace!(" already know it cannot derive {}", self.derive_trait);
return ConstrainResult::Same;
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/has_destructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
}

fn initial_worklist(&self) -> Vec<ItemId> {
self.ctx.allowlisted_items().iter().cloned().collect()
self.ctx.allowlisted_items().iter().copied().collect()
}

fn constrain(&mut self, id: ItemId) -> ConstrainResult {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/has_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
}

fn initial_worklist(&self) -> Vec<ItemId> {
self.ctx.allowlisted_items().iter().cloned().collect()
self.ctx.allowlisted_items().iter().copied().collect()
}

fn constrain(&mut self, id: ItemId) -> ConstrainResult {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/has_type_param_in_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
}

fn initial_worklist(&self) -> Vec<ItemId> {
self.ctx.allowlisted_items().iter().cloned().collect()
self.ctx.allowlisted_items().iter().copied().collect()
}

fn constrain(&mut self, id: ItemId) -> ConstrainResult {
Expand Down
6 changes: 3 additions & 3 deletions bindgen/ir/analysis/has_vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl HasVtableAnalysis<'_> {
let from = from.into();
let to = to.into();

match self.have_vtable.get(&from).cloned() {
match self.have_vtable.get(&from) {
None => ConstrainResult::Same,
Some(r) => self.insert(to, r),
Some(r) => self.insert(to, *r),
}
}
}
Expand All @@ -142,7 +142,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
}

fn initial_worklist(&self) -> Vec<ItemId> {
self.ctx.allowlisted_items().iter().cloned().collect()
self.ctx.allowlisted_items().iter().copied().collect()
}

fn constrain(&mut self, id: ItemId) -> ConstrainResult {
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ mod tests {
}

fn initial_worklist(&self) -> Vec<Node> {
self.graph.0.keys().cloned().collect()
self.graph.0.keys().copied().collect()
}

fn constrain(&mut self, node: Node) -> ConstrainResult {
Expand Down Expand Up @@ -376,7 +376,7 @@ mod tests {
where
A: AsRef<[usize]>,
{
nodes.as_ref().iter().cloned().map(Node).collect()
nodes.as_ref().iter().copied().map(Node).collect()
}

let mut expected = HashMap::default();
Expand Down
9 changes: 3 additions & 6 deletions bindgen/ir/analysis/sizedness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ impl SizednessAnalysis<'_> {
}

fn forward(&mut self, from: TypeId, to: TypeId) -> ConstrainResult {
match self.sized.get(&from).cloned() {
match self.sized.get(&from) {
None => ConstrainResult::Same,
Some(r) => self.insert(to, r),
Some(r) => self.insert(to, *r),
}
}
}
Expand Down Expand Up @@ -191,17 +191,14 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> {
self.ctx
.allowlisted_items()
.iter()
.cloned()
.filter_map(|id| id.as_type_id(self.ctx))
.collect()
}

fn constrain(&mut self, id: TypeId) -> ConstrainResult {
trace!("constrain {:?}", id);

if let Some(SizednessResult::NonZeroSized) =
self.sized.get(&id).cloned()
{
if let Some(SizednessResult::NonZeroSized) = self.sized.get(&id) {
trace!(" already know it is not zero-sized");
return ConstrainResult::Same;
}
Expand Down
13 changes: 5 additions & 8 deletions bindgen/ir/analysis/template_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ impl UsedTemplateParameters<'_> {
a's used template param set should be `Some`",
)
.iter()
.cloned()
});

used_by_this_id.extend(args);
Expand Down Expand Up @@ -322,8 +321,7 @@ impl UsedTemplateParameters<'_> {
arg's used template param set should be \
`Some`",
)
.iter()
.cloned();
.iter();
used_by_this_id.extend(used_by_arg);
}
}
Expand Down Expand Up @@ -355,8 +353,7 @@ impl UsedTemplateParameters<'_> {
sub_id's used template param set should be \
`Some`",
)
.iter()
.cloned();
.iter();

trace!(
" union with {:?}'s usage: {:?}",
Expand All @@ -380,11 +377,11 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
let mut used = HashMap::default();
let mut dependencies = HashMap::default();
let allowlisted_items: HashSet<_> =
ctx.allowlisted_items().iter().cloned().collect();
ctx.allowlisted_items().iter().copied().collect();

let allowlisted_and_blocklisted_items: ItemSet = allowlisted_items
.iter()
.cloned()
.copied()
.flat_map(|i| {
let mut reachable = vec![i];
i.trace(
Expand Down Expand Up @@ -498,7 +495,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
self.ctx
.allowlisted_items()
.iter()
.cloned()
.copied()
.flat_map(|i| {
let mut reachable = vec![i];
i.trace(
Expand Down
13 changes: 6 additions & 7 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
definition.kind(),
clang_sys::CXCursor_TemplateTypeParameter
);
self.type_params.get(definition).cloned()
self.type_params.get(definition).copied()
}

// TODO: Move all this syntax crap to other part of the code.
Expand Down Expand Up @@ -1317,7 +1317,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.as_ref()
.unwrap()
.get(&id)
.cloned()
.copied()
.unwrap_or(SizednessResult::ZeroSized)
}

Expand All @@ -1341,7 +1341,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.as_ref()
.unwrap()
.get(&id.into())
.cloned()
.copied()
.unwrap_or(HasVtableResult::No)
}

Expand Down Expand Up @@ -1541,7 +1541,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
&self,
definition: clang::Cursor,
) -> Option<ItemId> {
self.semantic_parents.get(&definition).cloned()
self.semantic_parents.get(&definition).copied()
}

/// Given a cursor pointing to the location of a template instantiation,
Expand Down Expand Up @@ -1589,7 +1589,6 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.currently_parsed_types()
.iter()
.find(|partial_ty| *partial_ty.decl() == referenced)
.cloned()
})
.and_then(|template_decl| {
let num_template_params =
Expand Down Expand Up @@ -1861,7 +1860,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.usr()
.and_then(|usr| self.types.get(&TypeKey::Usr(usr)))
})
.cloned()
.copied()
}

/// Looks up for an already resolved type, either because it's builtin, or
Expand Down Expand Up @@ -2865,7 +2864,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.as_ref()
.unwrap()
.get(&id)
.cloned()
.copied()
.unwrap_or(CanDerive::Yes)
}

Expand Down
Loading