Skip to content

Commit bc35a64

Browse files
committed
fix most of clippy warnings
1 parent 1949239 commit bc35a64

File tree

20 files changed

+68
-52
lines changed

20 files changed

+68
-52
lines changed

parser/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct Located<T> {
4444
pub type LocatedStatement = Located<Statement>;
4545

4646
/// Abstract syntax tree nodes for python statements.
47+
#[allow(clippy::large_enum_variant)]
4748
#[derive(Debug, PartialEq)]
4849
pub enum Statement {
4950
Break,

vm/src/builtins.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,12 @@ impl Printer for std::io::StdoutLock<'_> {
612612
}
613613
}
614614

615-
pub fn builtin_exit(object: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult<()> {
616-
match object {
617-
OptionalArg::Present(object) => match i32::try_from_object(&vm, object.clone()) {
615+
pub fn builtin_exit(exit_code_arg: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult<()> {
616+
if let OptionalArg::Present(exit_code_obj) = exit_code_arg {
617+
match i32::try_from_object(&vm, exit_code_obj.clone()) {
618618
Ok(code) => std::process::exit(code),
619-
_ => println!("{}", vm.to_str(&object)?.as_str()),
620-
},
621-
_ => {}
619+
_ => println!("{}", vm.to_str(&exit_code_obj)?.as_str()),
620+
}
622621
}
623622
std::process::exit(0);
624623
}

vm/src/dictdatatype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<T: Clone> Dict<T> {
193193
Box::new(
194194
self.entries
195195
.iter()
196-
.filter_map(|v| v.as_ref().map_or(None, |v| Some(v.key.clone()))),
196+
.filter_map(|v| v.as_ref().and_then(|v| Some(v.key.clone()))),
197197
)
198198
}
199199

vm/src/frame.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ impl NameProtocol for Scope {
173173
fn store_cell(&self, vm: &VirtualMachine, name: &str, value: PyObjectRef) {
174174
self.locals
175175
.iter()
176-
.skip(1)
177-
.next()
176+
.nth(1)
178177
.expect("no outer scope for non-local")
179178
.set_item(name, value, vm)
180179
.unwrap();

vm/src/obj/objbytearray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl PyByteArrayRef {
340340
let pos = bytes
341341
.iter()
342342
.position(|b| *b == x)
343-
.ok_or(vm.new_value_error("value not found in bytearray".to_string()))?;
343+
.ok_or_else(|| vm.new_value_error("value not found in bytearray".to_string()))?;
344344

345345
bytes.remove(pos);
346346

vm/src/obj/objcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl PyValue for PyCode {
3434
}
3535

3636
impl PyCodeRef {
37+
#[allow(clippy::new_ret_no_self)]
3738
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult {
3839
Err(vm.new_type_error("Cannot directly create code object".to_string()))
3940
}

vm/src/obj/objcomplex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ impl PyComplex {
126126

127127
#[pymethod(name = "__float__")]
128128
fn float(&self, vm: &VirtualMachine) -> PyResult {
129-
return Err(vm.new_type_error(String::from("Can't convert complex to float")));
129+
Err(vm.new_type_error(String::from("Can't convert complex to float")))
130130
}
131131

132132
#[pymethod(name = "__int__")]
133133
fn int(&self, vm: &VirtualMachine) -> PyResult {
134-
return Err(vm.new_type_error(String::from("Can't convert complex to int")));
134+
Err(vm.new_type_error(String::from("Can't convert complex to int")))
135135
}
136136

137137
#[pymethod(name = "__mul__")]

vm/src/obj/objfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ pub fn ufrexp(value: f64) -> (f64, i32) {
541541
} else {
542542
let bits = value.to_bits();
543543
let exponent: i32 = ((bits >> 52) & 0x7ff) as i32 - 1022;
544-
let mantissa_bits = bits & (0x000fffffffffffff) | (1022 << 52);
544+
let mantissa_bits = bits & (0x000f_ffff_ffff_ffff) | (1022 << 52);
545545
(f64::from_bits(mantissa_bits), exponent)
546546
}
547547
}

vm/src/obj/objframe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn init(context: &PyContext) {
1818
}
1919

2020
impl FrameRef {
21+
#[allow(clippy::new_ret_no_self)]
2122
fn new(_class: FrameRef, vm: &VirtualMachine) -> PyResult {
2223
Err(vm.new_type_error("Cannot directly create frame object".to_string()))
2324
}

vm/src/obj/objint.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ impl_try_from_object_int!(
112112
(u64, to_u64),
113113
);
114114

115+
#[allow(clippy::collapsible_if)]
115116
fn inner_pow(int1: &PyInt, int2: &PyInt, vm: &VirtualMachine) -> PyResult {
116-
Ok(if int2.value.is_negative() {
117+
let result = if int2.value.is_negative() {
117118
let v1 = int1.float(vm)?;
118119
let v2 = int2.float(vm)?;
119120
vm.ctx.new_float(v1.pow(v2))
@@ -133,7 +134,8 @@ fn inner_pow(int1: &PyInt, int2: &PyInt, vm: &VirtualMachine) -> PyResult {
133134
// practically, exp over u64 is not possible to calculate anyway
134135
vm.ctx.not_implemented()
135136
}
136-
})
137+
};
138+
Ok(result)
137139
}
138140

139141
#[pyimpl]
@@ -494,6 +496,7 @@ impl PyInt {
494496
}
495497

496498
#[pymethod]
499+
#[allow(clippy::match_bool)]
497500
fn from_bytes(
498501
bytes: PyByteInner,
499502
byteorder: PyStringRef,
@@ -529,6 +532,7 @@ impl PyInt {
529532
Ok(x)
530533
}
531534
#[pymethod]
535+
#[allow(clippy::match_bool)]
532536
fn to_bytes(
533537
&self,
534538
length: PyIntRef,
@@ -547,7 +551,7 @@ impl PyInt {
547551
);
548552
}
549553
}
550-
if value.sign() == Sign::Minus && signed == false {
554+
if value.sign() == Sign::Minus && !signed {
551555
return Err(vm.new_overflow_error("can't convert negative int to unsigned".to_string()));
552556
}
553557
let byte_len;

0 commit comments

Comments
 (0)