Skip to content

Commit ff90dde

Browse files
committed
Applied clippy cloned->copied, and cleanup
Removed a few unneeded cloning
1 parent c4440b3 commit ff90dde

10 files changed

+27
-36
lines changed

bindgen/codegen/helpers.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub(crate) mod attributes {
1919
pub(crate) fn repr_list(which_ones: &[&str]) -> TokenStream {
2020
let which_ones = which_ones
2121
.iter()
22-
.cloned()
2322
.map(|one| TokenStream::from_str(one).expect("repr to be valid"));
2423
quote! {
2524
#[repr( #( #which_ones ),* )]
@@ -29,7 +28,6 @@ pub(crate) mod attributes {
2928
pub(crate) fn derives(which_ones: &[&str]) -> TokenStream {
3029
let which_ones = which_ones
3130
.iter()
32-
.cloned()
3331
.map(|one| TokenStream::from_str(one).expect("derive to be valid"));
3432
quote! {
3533
#[derive( #( #which_ones ),* )]

bindgen/ir/analysis/derive.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl CannotDerive<'_> {
234234
// Complex cases need more information
235235
TypeKind::Array(t, len) => {
236236
let inner_type =
237-
self.can_derive.get(&t.into()).cloned().unwrap_or_default();
237+
self.can_derive.get(&t.into()).copied().unwrap_or_default();
238238
if inner_type != CanDerive::Yes {
239239
trace!(
240240
" arrays of T for which we cannot derive {} \
@@ -273,7 +273,7 @@ impl CannotDerive<'_> {
273273
}
274274
TypeKind::Vector(t, len) => {
275275
let inner_type =
276-
self.can_derive.get(&t.into()).cloned().unwrap_or_default();
276+
self.can_derive.get(&t.into()).copied().unwrap_or_default();
277277
if inner_type != CanDerive::Yes {
278278
trace!(
279279
" vectors of T for which we cannot derive {} \
@@ -428,7 +428,7 @@ impl CannotDerive<'_> {
428428

429429
let can_derive = self.can_derive
430430
.get(&sub_id)
431-
.cloned()
431+
.copied()
432432
.unwrap_or_default();
433433

434434
match can_derive {
@@ -642,7 +642,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
642642
self.ctx
643643
.allowlisted_items()
644644
.iter()
645-
.cloned()
645+
.copied()
646646
.flat_map(|i| {
647647
let mut reachable = vec![i];
648648
i.trace(
@@ -660,7 +660,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
660660
fn constrain(&mut self, id: ItemId) -> ConstrainResult {
661661
trace!("constrain: {:?}", id);
662662

663-
if let Some(CanDerive::No) = self.can_derive.get(&id).cloned() {
663+
if let Some(CanDerive::No) = self.can_derive.get(&id) {
664664
trace!(" already know it cannot derive {}", self.derive_trait);
665665
return ConstrainResult::Same;
666666
}

bindgen/ir/analysis/has_destructor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
8282
}
8383

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

8888
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

bindgen/ir/analysis/has_float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
9393
}
9494

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

9999
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

bindgen/ir/analysis/has_type_param_in_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
9999
}
100100

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

105105
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

bindgen/ir/analysis/has_vtable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl HasVtableAnalysis<'_> {
118118
let from = from.into();
119119
let to = to.into();
120120

121-
match self.have_vtable.get(&from).cloned() {
121+
match self.have_vtable.get(&from) {
122122
None => ConstrainResult::Same,
123-
Some(r) => self.insert(to, r),
123+
Some(r) => self.insert(to, *r),
124124
}
125125
}
126126
}
@@ -142,7 +142,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
142142
}
143143

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

148148
fn constrain(&mut self, id: ItemId) -> ConstrainResult {

bindgen/ir/analysis/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ mod tests {
316316
}
317317

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

322322
fn constrain(&mut self, node: Node) -> ConstrainResult {
@@ -376,7 +376,7 @@ mod tests {
376376
where
377377
A: AsRef<[usize]>,
378378
{
379-
nodes.as_ref().iter().cloned().map(Node).collect()
379+
nodes.as_ref().iter().copied().map(Node).collect()
380380
}
381381

382382
let mut expected = HashMap::default();

bindgen/ir/analysis/sizedness.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ impl SizednessAnalysis<'_> {
150150
}
151151

152152
fn forward(&mut self, from: TypeId, to: TypeId) -> ConstrainResult {
153-
match self.sized.get(&from).cloned() {
153+
match self.sized.get(&from) {
154154
None => ConstrainResult::Same,
155-
Some(r) => self.insert(to, r),
155+
Some(r) => self.insert(to, *r),
156156
}
157157
}
158158
}
@@ -191,17 +191,14 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> {
191191
self.ctx
192192
.allowlisted_items()
193193
.iter()
194-
.cloned()
195194
.filter_map(|id| id.as_type_id(self.ctx))
196195
.collect()
197196
}
198197

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

202-
if let Some(SizednessResult::NonZeroSized) =
203-
self.sized.get(&id).cloned()
204-
{
201+
if let Some(SizednessResult::NonZeroSized) = self.sized.get(&id) {
205202
trace!(" already know it is not zero-sized");
206203
return ConstrainResult::Same;
207204
}

bindgen/ir/analysis/template_params.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ impl UsedTemplateParameters<'_> {
259259
a's used template param set should be `Some`",
260260
)
261261
.iter()
262-
.cloned()
263262
});
264263

265264
used_by_this_id.extend(args);
@@ -322,8 +321,7 @@ impl UsedTemplateParameters<'_> {
322321
arg's used template param set should be \
323322
`Some`",
324323
)
325-
.iter()
326-
.cloned();
324+
.iter();
327325
used_by_this_id.extend(used_by_arg);
328326
}
329327
}
@@ -355,8 +353,7 @@ impl UsedTemplateParameters<'_> {
355353
sub_id's used template param set should be \
356354
`Some`",
357355
)
358-
.iter()
359-
.cloned();
356+
.iter();
360357

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

385382
let allowlisted_and_blocklisted_items: ItemSet = allowlisted_items
386383
.iter()
387-
.cloned()
384+
.copied()
388385
.flat_map(|i| {
389386
let mut reachable = vec![i];
390387
i.trace(
@@ -498,7 +495,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
498495
self.ctx
499496
.allowlisted_items()
500497
.iter()
501-
.cloned()
498+
.copied()
502499
.flat_map(|i| {
503500
let mut reachable = vec![i];
504501
i.trace(

bindgen/ir/context.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
864864
definition.kind(),
865865
clang_sys::CXCursor_TemplateTypeParameter
866866
);
867-
self.type_params.get(definition).cloned()
867+
self.type_params.get(definition).copied()
868868
}
869869

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

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

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

15471547
/// Given a cursor pointing to the location of a template instantiation,
@@ -1589,7 +1589,6 @@ If you encounter an error missing from this list, please file an issue or a PR!"
15891589
self.currently_parsed_types()
15901590
.iter()
15911591
.find(|partial_ty| *partial_ty.decl() == referenced)
1592-
.cloned()
15931592
})
15941593
.and_then(|template_decl| {
15951594
let num_template_params =
@@ -1861,7 +1860,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
18611860
.usr()
18621861
.and_then(|usr| self.types.get(&TypeKey::Usr(usr)))
18631862
})
1864-
.cloned()
1863+
.copied()
18651864
}
18661865

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

0 commit comments

Comments
 (0)