Skip to content

Commit 7f2f4c6

Browse files
authored
Merge pull request RustPython#4047 from youknowone/fix-clippy
Fix clippy
2 parents 1fcd1f4 + 33ab949 commit 7f2f4c6

File tree

7 files changed

+177
-81
lines changed

7 files changed

+177
-81
lines changed

ast/asdl_rs.py

Lines changed: 157 additions & 68 deletions
Large diffs are not rendered by default.

ast/src/ast_gen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// File automatically generated by ast/asdl_rs.py.
2+
3+
#![allow(clippy::derive_partial_eq_without_eq)]
4+
25
pub use crate::constant::*;
36
pub use crate::location::Location;
47

stdlib/src/binascii.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,16 @@ mod decl {
566566
let trailing_garbage_error = || Err(vm.new_value_error("Trailing garbage".to_string()));
567567

568568
for chunk in b.get(1..).unwrap_or_default().chunks(4) {
569-
let char_a = chunk.get(0).map_or(Ok(0), |x| uu_a2b_read(x, vm))?;
570-
let char_b = chunk.get(1).map_or(Ok(0), |x| uu_a2b_read(x, vm))?;
571-
let char_c = chunk.get(2).map_or(Ok(0), |x| uu_a2b_read(x, vm))?;
572-
let char_d = chunk.get(3).map_or(Ok(0), |x| uu_a2b_read(x, vm))?;
569+
let (char_a, char_b, char_c, char_d) = {
570+
let mut chunk = chunk
571+
.iter()
572+
.map(|x| uu_a2b_read(x, vm))
573+
.collect::<Result<Vec<_>, _>>()?;
574+
while chunk.len() < 4 {
575+
chunk.push(0);
576+
}
577+
(chunk[0], chunk[1], chunk[2], chunk[3])
578+
};
573579

574580
if res.len() < length {
575581
res.push(char_a << 2 | char_b >> 4);
@@ -628,7 +634,7 @@ mod decl {
628634
res.push(uu_b2a(length as u8, backtick));
629635

630636
for chunk in b.chunks(3) {
631-
let char_a = *chunk.get(0).unwrap_or(&0);
637+
let char_a = *chunk.first().unwrap();
632638
let char_b = *chunk.get(1).unwrap_or(&0);
633639
let char_c = *chunk.get(2).unwrap_or(&0);
634640

vm/src/cformat.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl CFormatSpec {
354354
_ => unreachable!(),
355355
};
356356

357-
let formatted = if self.flags.contains(CConversionFlags::ZERO_PAD) {
357+
if self.flags.contains(CConversionFlags::ZERO_PAD) {
358358
let fill_char = if !self.flags.contains(CConversionFlags::LEFT_ADJUST) {
359359
'0'
360360
} else {
@@ -377,9 +377,7 @@ impl CFormatSpec {
377377
None,
378378
false,
379379
)
380-
};
381-
382-
formatted
380+
}
383381
}
384382

385383
fn bytes_format(&self, vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Vec<u8>> {

vm/src/dictdatatype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct DictEntry<T> {
9999
}
100100
static_assertions::assert_eq_size!(DictEntry<PyObjectRef>, Option<DictEntry<PyObjectRef>>);
101101

102-
#[derive(Debug, PartialEq)]
102+
#[derive(Debug, PartialEq, Eq)]
103103
pub struct DictSize {
104104
indices_size: usize,
105105
pub entries_size: usize,

vm/src/stdlib/marshal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ mod decl {
179179
buf.push(Type::Bytes as u8);
180180
let data = bytes.as_bytes();
181181
write_size(buf, data.len(), vm)?;
182-
buf.extend(&*data);
182+
buf.extend(data);
183183
}
184184
bytes @ PyByteArray => {
185185
buf.push(Type::Bytes as u8);

vm/src/vm/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl Context {
327327
#[inline]
328328
pub fn new_int<T: Into<BigInt> + ToPrimitive>(&self, i: T) -> PyIntRef {
329329
if let Some(i) = i.to_i32() {
330-
if i >= Self::INT_CACHE_POOL_MIN && i <= Self::INT_CACHE_POOL_MAX {
330+
if (Self::INT_CACHE_POOL_MIN..=Self::INT_CACHE_POOL_MAX).contains(&i) {
331331
let inner_idx = (i - Self::INT_CACHE_POOL_MIN) as usize;
332332
return self.int_cache_pool[inner_idx].clone();
333333
}
@@ -338,7 +338,7 @@ impl Context {
338338
#[inline]
339339
pub fn new_bigint(&self, i: &BigInt) -> PyIntRef {
340340
if let Some(i) = i.to_i32() {
341-
if i >= Self::INT_CACHE_POOL_MIN && i <= Self::INT_CACHE_POOL_MAX {
341+
if (Self::INT_CACHE_POOL_MIN..=Self::INT_CACHE_POOL_MAX).contains(&i) {
342342
let inner_idx = (i - Self::INT_CACHE_POOL_MIN) as usize;
343343
return self.int_cache_pool[inner_idx].clone();
344344
}

0 commit comments

Comments
 (0)