Skip to content

Commit d2f0c6f

Browse files
committed
Enfore cloned_instead_of_copied
1 parent 938790a commit d2f0c6f

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ suspicious = { level = "warn", priority = -2 }
254254
perf = { level = "warn", priority = -2 }
255255
style = { level = "warn", priority = -2 }
256256
complexity = { level = "warn", priority = -2 }
257-
# pedantic = { level = "warn", priority = -2 }
257+
# pedantic = { level = "warn", priority = -2 } # TODO: Enable this
258258

259259
missing_errors_doc = "allow" # Too many errors. No auto-fix available
260260
missing_panics_doc = "allow" # Too many errors. No auto-fix available
@@ -263,8 +263,6 @@ if_not_else = "allow" # Not always more readable
263263
single_match_else = "allow"
264264
similar_names = "allow"
265265

266-
must_use_candidate = "warn"
267-
268266
alloc_instead_of_core = "warn"
269267
std_instead_of_alloc = "warn"
270268
std_instead_of_core = "warn"
@@ -277,3 +275,7 @@ unused_peekable = "warn"
277275
manual_is_variant_and = "warn"
278276
or_fun_call = "warn"
279277
unnested_or_patterns = "warn"
278+
279+
# pendantic lints to enforce gradually
280+
cloned_instead_of_copied = "warn"
281+
must_use_candidate = "warn"

crates/common/src/cformat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ pub type CFormatBytes = CFormatStrOrBytes<Vec<u8>>;
834834

835835
impl CFormatBytes {
836836
pub fn parse_from_bytes(bytes: &[u8]) -> Result<Self, CFormatError> {
837-
let mut iter = bytes.iter().cloned().enumerate().peekable();
837+
let mut iter = bytes.iter().copied().enumerate().peekable();
838838
Self::parse(&mut iter)
839839
}
840840
}

crates/stdlib/src/faulthandler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ mod decl {
10121012

10131013
pub fn get_user_signal(signum: usize) -> Option<UserSignal> {
10141014
let guard = USER_SIGNALS.lock();
1015-
guard.as_ref().and_then(|v| v.get(signum).cloned())
1015+
guard.as_ref().and_then(|v| v.get(signum).copied())
10161016
}
10171017

10181018
pub fn set_user_signal(signum: usize, signal: UserSignal) {

crates/vm/src/protocol/buffer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl BufferDescriptor {
222222
} else {
223223
let mut shape_product = 1;
224224
let has_zero_dim = self.dim_desc.iter().any(|(s, _, _)| *s == 0);
225-
for (shape, stride, suboffset) in self.dim_desc.iter().cloned() {
225+
for (shape, stride, suboffset) in self.dim_desc.iter().copied() {
226226
shape_product *= shape;
227227
assert!(suboffset >= 0);
228228
// For empty arrays (any dimension is 0), strides can be 0
@@ -251,7 +251,7 @@ impl BufferDescriptor {
251251
return true;
252252
}
253253
let mut sd = self.itemsize;
254-
for (shape, stride, _) in self.dim_desc.iter().cloned().rev() {
254+
for (shape, stride, _) in self.dim_desc.iter().copied().rev() {
255255
if shape > 1 && stride != sd as isize {
256256
return false;
257257
}
@@ -267,8 +267,8 @@ impl BufferDescriptor {
267267
let mut pos = 0;
268268
for (i, (_, stride, suboffset)) in indices
269269
.iter()
270-
.cloned()
271-
.zip_eq(self.dim_desc.iter().cloned())
270+
.copied()
271+
.zip_eq(self.dim_desc.iter().copied())
272272
{
273273
pos += i as isize * stride + suboffset;
274274
}
@@ -280,8 +280,8 @@ impl BufferDescriptor {
280280
let mut pos = 0;
281281
for (i, (shape, stride, suboffset)) in indices
282282
.iter()
283-
.cloned()
284-
.zip_eq(self.dim_desc.iter().cloned())
283+
.copied()
284+
.zip_eq(self.dim_desc.iter().copied())
285285
{
286286
let i = i.wrapped_at(shape).ok_or_else(|| {
287287
vm.new_index_error(format!("index out of bounds on dimension {i}"))

crates/vm/src/stdlib/_sre.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod _sre {
6666
impl SreStr for &[u8] {
6767
fn slice(&self, start: usize, end: usize, vm: &VirtualMachine) -> PyObjectRef {
6868
vm.ctx
69-
.new_bytes(self.iter().take(end).skip(start).cloned().collect())
69+
.new_bytes(self.iter().take(end).skip(start).copied().collect())
7070
.into()
7171
}
7272
}

0 commit comments

Comments
 (0)