Skip to content

Commit ca51f2d

Browse files
authored
Merge pull request RustPython#438 from ZapAnton/fix_clippy
Fixed several small clippy warnings
2 parents 45f45bf + e51c75e commit ca51f2d

File tree

9 files changed

+22
-40
lines changed

9 files changed

+22
-40
lines changed

vm/src/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl Compiler {
163163
_ => {
164164
self.emit(Instruction::Import {
165165
name: module.clone(),
166-
symbol: symbol.clone().map(|s| s.clone()),
166+
symbol: symbol.clone(),
167167
});
168168
self.emit(Instruction::StoreName {
169169
name: match alias {

vm/src/obj/objsequence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub trait PySliceableSequence {
4949
let stop = stop
5050
.as_ref()
5151
.map(|x| self.get_slice_pos(x))
52-
.unwrap_or(self.len());
52+
.unwrap_or_else(|| self.len());
5353

5454
start..stop
5555
}
@@ -65,7 +65,7 @@ pub trait PySliceableSequence {
6565
// TODO: we could potentially avoid this copy and use slice
6666
match &(slice.borrow()).payload {
6767
PyObjectPayload::Slice { start, stop, step } => {
68-
let step = step.clone().unwrap_or(BigInt::one());
68+
let step = step.clone().unwrap_or_else(BigInt::one);
6969
if step.is_zero() {
7070
Err(vm.new_value_error("slice step cannot be zero".to_string()))
7171
} else if step.is_positive() {

vm/src/obj/objstr.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -823,18 +823,13 @@ fn str_ljust(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
823823
fn str_istitle(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
824824
arg_check!(vm, args, required = [(s, Some(vm.ctx.str_type()))]);
825825
let value = get_value(&s);
826-
let mut is_titled = true;
827826

828-
if value.is_empty() {
829-
is_titled = false;
827+
let is_titled = if value.is_empty() {
828+
false
830829
} else {
831-
for word in value.split(' ') {
832-
if word != make_title(&word) {
833-
is_titled = false;
834-
break;
835-
}
836-
}
837-
}
830+
value.split(' ').all(|word| word == make_title(word))
831+
};
832+
838833
Ok(vm.ctx.new_bool(is_titled))
839834
}
840835

@@ -974,24 +969,15 @@ fn str_isdigit(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
974969
let valid_unicodes: [u16; 10] = [
975970
0x2070, 0x00B9, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079,
976971
];
977-
let mut is_digit: bool = true;
978972

979-
if value.is_empty() {
980-
is_digit = false;
973+
let is_digit = if value.is_empty() {
974+
false
981975
} else {
982-
for c in value.chars() {
983-
if !c.is_digit(10) {
984-
// checking if char is exponent
985-
let char_as_uni: u16 = c as u16;
986-
if valid_unicodes.contains(&char_as_uni) {
987-
continue;
988-
} else {
989-
is_digit = false;
990-
break;
991-
}
992-
}
993-
}
994-
}
976+
value
977+
.chars()
978+
.filter(|c| !c.is_digit(10))
979+
.all(|c| valid_unicodes.contains(&(c as u16)))
980+
};
995981

996982
Ok(vm.ctx.new_bool(is_digit))
997983
}

vm/src/obj/objzip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn zip_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1010
let cls = &args.args[0];
1111
let iterables = &args.args[1..];
1212
let iterators = iterables
13-
.into_iter()
13+
.iter()
1414
.map(|iterable| objiter::get_iter(vm, iterable))
1515
.collect::<Result<Vec<_>, _>>()?;
1616
Ok(PyObject::new(

vm/src/pyobject.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ pub trait AttributeProtocol {
736736
fn class_get_item(class: &PyObjectRef, attr_name: &str) -> Option<PyObjectRef> {
737737
let class = class.borrow();
738738
match class.payload {
739-
PyObjectPayload::Class { ref dict, .. } => dict.borrow().get(attr_name).map(|v| v.clone()),
739+
PyObjectPayload::Class { ref dict, .. } => dict.borrow().get(attr_name).cloned(),
740740
_ => panic!("Only classes should be in MRO!"),
741741
}
742742
}
@@ -765,9 +765,7 @@ impl AttributeProtocol for PyObjectRef {
765765
}
766766
None
767767
}
768-
PyObjectPayload::Instance { ref dict } => {
769-
dict.borrow().get(attr_name).map(|v| v.clone())
770-
}
768+
PyObjectPayload::Instance { ref dict } => dict.borrow().get(attr_name).cloned(),
771769
_ => None,
772770
}
773771
}

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::super::vm::VirtualMachine;
2020
pub fn raw_file_number(handle: File) -> i64 {
2121
use std::os::unix::io::IntoRawFd;
2222

23-
handle.into_raw_fd() as i64
23+
i64::from(handle.into_raw_fd())
2424
}
2525

2626
#[cfg(target_family = "unix")]

vm/src/stdlib/pystruct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn unpack_u64(vm: &mut VirtualMachine, rdr: &mut Read) -> PyResult {
287287
fn unpack_f32(vm: &mut VirtualMachine, rdr: &mut Read) -> PyResult {
288288
match rdr.read_f32::<LittleEndian>() {
289289
Err(err) => panic!("Error in reading {:?}", err),
290-
Ok(v) => Ok(vm.ctx.new_float(v as f64)),
290+
Ok(v) => Ok(vm.ctx.new_float(f64::from(v))),
291291
}
292292
}
293293

vm/src/stdlib/time_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn time_sleep(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1717
}
1818

1919
fn duration_to_f64(d: Duration) -> f64 {
20-
(d.as_secs() as f64) + ((d.subsec_nanos() as f64) / 1e9)
20+
(d.as_secs() as f64) + (f64::from(d.subsec_nanos()) / 1e9)
2121
}
2222

2323
fn time_time(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/vm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,12 @@ impl VirtualMachine {
430430

431431
// We have sufficient defaults, so iterate over the corresponding names and use
432432
// the default if we don't already have a value
433-
let mut default_index = 0;
434-
for i in required_args..nexpected_args {
433+
for (default_index, i) in (required_args..nexpected_args).enumerate() {
435434
let arg_name = &code_object.arg_names[i];
436435
if !scope.contains_key(arg_name) {
437436
self.ctx
438437
.set_item(scope, arg_name, available_defaults[default_index].clone());
439438
}
440-
default_index += 1;
441439
}
442440
};
443441

0 commit comments

Comments
 (0)