Skip to content

Commit f364ea5

Browse files
committed
Fix a bunch of clippy lints
1 parent 387c21f commit f364ea5

File tree

15 files changed

+51
-50
lines changed

15 files changed

+51
-50
lines changed

vm/src/bytecode.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl CodeObject {
269269
}
270270
}
271271

272-
pub fn get_constants<'a>(&'a self) -> impl Iterator<Item = &'a Constant> {
272+
pub fn get_constants(&self) -> impl Iterator<Item = &Constant> {
273273
self.instructions.iter().filter_map(|x| {
274274
if let Instruction::LoadConst { value } = x {
275275
Some(value)
@@ -362,10 +362,7 @@ impl Instruction {
362362
UnpackSequence { size } => w!(UnpackSequence, size),
363363
UnpackEx { before, after } => w!(UnpackEx, before, after),
364364
Unpack => w!(Unpack),
365-
FormatValue {
366-
conversion: _,
367-
spec,
368-
} => w!(FormatValue, spec), // TODO: write conversion
365+
FormatValue { spec, .. } => w!(FormatValue, spec), // TODO: write conversion
369366
}
370367
}
371368
}

vm/src/compile.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ pub fn compile(
4848

4949
let code = compiler.pop_code_object();
5050
trace!("Compilation completed: {:?}", code);
51-
Ok(PyObject::new(
52-
PyObjectPayload::Code { code: code },
53-
code_type,
54-
))
51+
Ok(PyObject::new(PyObjectPayload::Code { code }, code_type))
5552
}
5653

5754
pub enum Mode {

vm/src/frame.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Frame {
9494
let run_obj_name = &self.code.obj_name.to_string();
9595

9696
// Execute until return or exception:
97-
let value = loop {
97+
loop {
9898
let lineno = self.get_lineno();
9999
let result = self.execute_instruction(vm);
100100
match result {
@@ -136,9 +136,7 @@ impl Frame {
136136
}
137137
}
138138
}
139-
};
140-
141-
value
139+
}
142140
}
143141

144142
pub fn fetch_instruction(&self) -> &bytecode::Instruction {

vm/src/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn find_source(vm: &VirtualMachine, current_path: PathBuf, name: &str) -> Result
105105
}
106106
}
107107

108-
match file_paths.iter().filter(|p| p.exists()).next() {
108+
match file_paths.iter().find(|p| p.exists()) {
109109
Some(path) => Ok(path.to_path_buf()),
110110
None => Err(format!("No module named '{}'", name)),
111111
}

vm/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//! - Import mechanics
66
//! - Base objects
77
8+
// for methods like vm.to_str(), not the typical use of 'to' as a method prefix
9+
#![allow(clippy::wrong_self_convention)]
10+
811
#[macro_use]
912
extern crate bitflags;
1013
#[macro_use]

vm/src/obj/objbool.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ pub fn boolval(vm: &mut VirtualMachine, obj: PyObjectRef) -> Result<bool, PyObje
2222
_ => {
2323
if let Ok(f) = vm.get_method(obj.clone(), "__bool__") {
2424
let bool_res = vm.invoke(f, PyFuncArgs::default())?;
25-
let v = match bool_res.payload {
25+
match bool_res.payload {
2626
PyObjectPayload::Integer { ref value } => !value.is_zero(),
2727
_ => return Err(vm.new_type_error(String::from("TypeError"))),
28-
};
29-
30-
v
28+
}
3129
} else {
3230
true
3331
}

vm/src/obj/objcomplex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ fn complex_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8484

8585
fn complex_real(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8686
arg_check!(vm, args, required = [(zelf, Some(vm.ctx.complex_type()))]);
87-
let Complex64 { re, im: _ } = get_value(zelf);
87+
let Complex64 { re, .. } = get_value(zelf);
8888
Ok(vm.ctx.new_float(re))
8989
}
9090

9191
fn complex_imag(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9292
arg_check!(vm, args, required = [(zelf, Some(vm.ctx.complex_type()))]);
93-
let Complex64 { re: _, im } = get_value(zelf);
93+
let Complex64 { im, .. } = get_value(zelf);
9494
Ok(vm.ctx.new_float(im))
9595
}
9696

vm/src/obj/objgenerator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn init(context: &PyContext) {
2929

3030
pub fn new_generator(vm: &mut VirtualMachine, frame: PyObjectRef) -> PyResult {
3131
Ok(PyObject::new(
32-
PyObjectPayload::Generator { frame: frame },
32+
PyObjectPayload::Generator { frame },
3333
vm.ctx.generator_type.clone(),
3434
))
3535
}

vm/src/obj/objset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ fn set_ixor(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
547547
fn set_iter(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
548548
arg_check!(vm, args, required = [(zelf, Some(vm.ctx.set_type()))]);
549549

550-
let items = get_elements(zelf).values().map(|x| x.clone()).collect();
550+
let items = get_elements(zelf).values().cloned().collect();
551551
let set_list = vm.ctx.new_list(items);
552552
let iter_obj = PyObject::new(
553553
PyObjectPayload::Iterator {

vm/src/obj/objstr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ fn str_isupper(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
518518
&& value
519519
.chars()
520520
.filter(|x| !x.is_ascii_whitespace())
521-
.all(|c| c.is_uppercase()),
521+
.all(char::is_uppercase),
522522
))
523523
}
524524

@@ -530,7 +530,7 @@ fn str_islower(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
530530
&& value
531531
.chars()
532532
.filter(|x| !x.is_ascii_whitespace())
533-
.all(|c| c.is_lowercase()),
533+
.all(char::is_lowercase),
534534
))
535535
}
536536

@@ -895,7 +895,7 @@ fn str_isalnum(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
895895
let value = get_value(&s);
896896
Ok(vm
897897
.ctx
898-
.new_bool(!value.is_empty() && value.chars().all(|c| c.is_alphanumeric())))
898+
.new_bool(!value.is_empty() && value.chars().all(char::is_alphanumeric)))
899899
}
900900

901901
fn str_isascii(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
@@ -959,15 +959,15 @@ fn str_isnumeric(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
959959
let value = get_value(&s);
960960
Ok(vm
961961
.ctx
962-
.new_bool(!value.is_empty() && value.chars().all(|c| c.is_numeric())))
962+
.new_bool(!value.is_empty() && value.chars().all(char::is_numeric)))
963963
}
964964

965965
fn str_isalpha(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
966966
arg_check!(vm, args, required = [(s, Some(vm.ctx.str_type()))]);
967967
let value = get_value(&s);
968968
Ok(vm
969969
.ctx
970-
.new_bool(!value.is_empty() && value.chars().all(|c| c.is_alphanumeric())))
970+
.new_bool(!value.is_empty() && value.chars().all(char::is_alphanumeric)))
971971
}
972972

973973
fn str_isdigit(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

0 commit comments

Comments
 (0)