Skip to content

Commit 6650ad8

Browse files
committed
Fix a bunch of clippy warnings
1 parent 1f8181b commit 6650ad8

File tree

12 files changed

+24
-31
lines changed

12 files changed

+24
-31
lines changed

vm/src/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,8 @@ impl Compiler {
871871
vals: &[ast::Expression],
872872
ops: &[ast::Comparison],
873873
) -> Result<(), CompileError> {
874-
assert!(ops.len() > 0);
875-
assert!(vals.len() == ops.len() + 1);
874+
assert!(!ops.is_empty());
875+
assert_eq!(vals.len(), ops.len() + 1);
876876

877877
let to_operator = |op: &ast::Comparison| match op {
878878
ast::Comparison::Equal => bytecode::ComparisonOperator::Equal,

vm/src/frame.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,9 @@ impl Frame {
12151215

12161216
fn get_exception(&self, vm: &VirtualMachine, none_allowed: bool) -> PyResult {
12171217
let exception = self.pop_value();
1218-
if none_allowed && vm.get_none().is(&exception) {
1219-
Ok(exception)
1220-
} else if objtype::isinstance(&exception, &vm.ctx.exceptions.base_exception_type) {
1218+
if none_allowed && vm.get_none().is(&exception)
1219+
|| objtype::isinstance(&exception, &vm.ctx.exceptions.base_exception_type)
1220+
{
12211221
Ok(exception)
12221222
} else if let Ok(exception) = PyClassRef::try_from_object(vm, exception) {
12231223
if objtype::issubclass(&exception, &vm.ctx.exceptions.base_exception_type) {

vm/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub struct Args<T = PyObjectRef>(Vec<T>);
286286
impl<T: PyValue> Args<PyRef<T>> {
287287
pub fn into_tuple(self, vm: &VirtualMachine) -> PyObjectRef {
288288
vm.ctx
289-
.new_tuple(self.0.into_iter().map(|obj| obj.into_object()).collect())
289+
.new_tuple(self.0.into_iter().map(PyRef::into_object).collect())
290290
}
291291
}
292292

vm/src/obj/objbyteinner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ impl PyByteInner {
356356
.collect::<Vec<char>>()
357357
.chunks(2)
358358
.map(|x| x.to_vec().iter().collect::<String>())
359-
.map(|x| u8::from_str_radix(&x, 16))
360-
.map(|x| x.unwrap())
359+
.map(|x| u8::from_str_radix(&x, 16).unwrap())
361360
.collect::<Vec<u8>>())
362361
}
363362

vm/src/obj/objdict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl PyDictRef {
118118
}
119119
}
120120
}
121-
return Ok(true);
121+
Ok(true)
122122
}
123123

124124
fn eq(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {

vm/src/obj/objint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub fn to_int(vm: &VirtualMachine, obj: &PyObjectRef, base: u32) -> PyResult<Big
518518
f @ PyFloat => Ok(f.to_f64().to_bigint().unwrap()),
519519
s @ PyString => {
520520
i32::from_str_radix(s.as_str(), base)
521-
.map(|i| BigInt::from(i))
521+
.map(BigInt::from)
522522
.map_err(|_|vm.new_value_error(format!(
523523
"invalid literal for int() with base {}: '{}'",
524524
base, s

vm/src/obj/objrange.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ impl PyRange {
144144
vm: &VirtualMachine,
145145
) -> PyResult<PyRangeRef> {
146146
PyRange {
147-
start: start,
148-
stop: stop,
147+
start,
148+
stop,
149149
step: step
150150
.into_option()
151151
.unwrap_or_else(|| PyInt::new(BigInt::one()).into_ref(vm)),

vm/src/obj/objset.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl PySetInner {
262262
perform_action_with_hash(vm, &mut self.elements, &item, &discard)
263263
}
264264

265-
fn clear(&mut self) -> () {
265+
fn clear(&mut self) {
266266
self.elements.clear();
267267
}
268268

@@ -449,11 +449,11 @@ impl PySetRef {
449449
fn repr(self, vm: &VirtualMachine) -> PyResult {
450450
let inner = self.inner.borrow();
451451
let s = if inner.len() == 0 {
452-
format!("set()")
452+
"set()".to_string()
453453
} else if let Some(_guard) = ReprGuard::enter(self.as_object()) {
454454
inner.repr(vm)?
455455
} else {
456-
format!("set(...)")
456+
"set(...)".to_string()
457457
};
458458
Ok(vm.new_str(s))
459459
}
@@ -470,7 +470,7 @@ impl PySetRef {
470470
self.inner.borrow_mut().discard(&item, vm)
471471
}
472472

473-
fn clear(self, _vm: &VirtualMachine) -> () {
473+
fn clear(self, _vm: &VirtualMachine) {
474474
self.inner.borrow_mut().clear()
475475
}
476476

@@ -656,11 +656,11 @@ impl PyFrozenSetRef {
656656
fn repr(self, vm: &VirtualMachine) -> PyResult {
657657
let inner = &self.inner;
658658
let s = if inner.len() == 0 {
659-
format!("frozenset()")
659+
"frozenset()".to_string()
660660
} else if let Some(_guard) = ReprGuard::enter(self.as_object()) {
661661
format!("frozenset({})", inner.repr(vm)?)
662662
} else {
663-
format!("frozenset(...)")
663+
"frozenset(...)".to_string()
664664
};
665665
Ok(vm.new_str(s))
666666
}

vm/src/obj/objslice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn slice_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
6363
step: step.map(|x| objint::get_value(x).clone()),
6464
}
6565
.into_ref_with_type(vm, cls.clone().downcast().unwrap())
66-
.map(|x| x.into_object())
66+
.map(PyRef::into_object)
6767
}
6868

6969
fn get_property_value(vm: &VirtualMachine, value: &Option<BigInt>) -> PyObjectRef {

vm/src/obj/objtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn type_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
235235
Ok(args.args[1].class().into_object())
236236
} else if args.args.len() == 4 {
237237
let (typ, name, bases, dict) = args.bind(vm)?;
238-
type_new_class(vm, typ, name, bases, dict).map(|x| x.into_object())
238+
type_new_class(vm, typ, name, bases, dict).map(PyRef::into_object)
239239
} else {
240240
Err(vm.new_type_error(format!(": type_new: {:?}", args)))
241241
}

vm/src/pyobject.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ pub type PyAttributes = HashMap<String, PyObjectRef>;
8787

8888
impl fmt::Display for PyObject<dyn PyObjectPayload> {
8989
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90-
use self::TypeProtocol;
9190
if let Some(PyClass { ref name, .. }) = self.payload::<PyClass>() {
9291
let type_name = self.class().name.clone();
9392
// We don't have access to a vm, so just assume that if its parent's name
@@ -698,7 +697,7 @@ impl PyContext {
698697
pub fn new_instance(&self, class: PyClassRef, dict: Option<PyDictRef>) -> PyObjectRef {
699698
PyObject {
700699
typ: class,
701-
dict: dict,
700+
dict,
702701
payload: objobject::PyInstance,
703702
}
704703
.into_ref()
@@ -1065,7 +1064,7 @@ where
10651064
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
10661065
if let Ok(method) = vm.get_method(obj.clone(), "__iter__") {
10671066
Ok(PyIterable {
1068-
method: method,
1067+
method,
10691068
_item: std::marker::PhantomData,
10701069
})
10711070
} else if vm.get_method(obj.clone(), "__getitem__").is_ok() {
@@ -1170,12 +1169,7 @@ where
11701169
T: Sized + PyObjectPayload,
11711170
{
11721171
pub fn new(payload: T, typ: PyClassRef, dict: Option<PyDictRef>) -> PyObjectRef {
1173-
PyObject {
1174-
typ,
1175-
dict: dict,
1176-
payload,
1177-
}
1178-
.into_ref()
1172+
PyObject { typ, dict, payload }.into_ref()
11791173
}
11801174

11811175
// Move this object into a reference object, transferring ownership.

vm/src/stdlib/os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ fn os_listdir(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
174174
}
175175
}
176176

177-
fn os_putenv(key: PyStringRef, value: PyStringRef, _vm: &VirtualMachine) -> () {
177+
fn os_putenv(key: PyStringRef, value: PyStringRef, _vm: &VirtualMachine) {
178178
env::set_var(&key.value, &value.value)
179179
}
180180

181-
fn os_unsetenv(key: PyStringRef, _vm: &VirtualMachine) -> () {
181+
fn os_unsetenv(key: PyStringRef, _vm: &VirtualMachine) {
182182
env::remove_var(&key.value)
183183
}
184184

0 commit comments

Comments
 (0)