Skip to content

Commit 2645bfd

Browse files
Merge pull request #448 from ZapAnton/fix_clippy_warnings
Fixed several clippy warnings
2 parents a75eea5 + 604883d commit 2645bfd

File tree

14 files changed

+50
-40
lines changed

14 files changed

+50
-40
lines changed

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
195195
debug!("You entered {:?}", input);
196196
if shell_exec(vm, &input, vars.clone()) {
197197
// Line was complete.
198-
rl.add_history_entry(input.trim_end().as_ref());
198+
rl.add_history_entry(input.trim_end());
199199
input = String::new();
200200
} else {
201201
loop {
@@ -206,9 +206,9 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
206206
//};
207207
match rl.readline(&ps2) {
208208
Ok(line) => {
209-
if line.len() == 0 {
209+
if line.is_empty() {
210210
if shell_exec(vm, &input, vars.clone()) {
211-
rl.add_history_entry(input.trim_end().as_ref());
211+
rl.add_history_entry(input.trim_end());
212212
input = String::new();
213213
break;
214214
}

vm/src/format.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,12 @@ impl FormatString {
496496
None => Err(FormatParseError::UnmatchedBracket),
497497
}
498498
}
499+
}
500+
501+
impl FromStr for FormatString {
502+
type Err = FormatParseError;
499503

500-
pub fn from_str(text: &str) -> Result<FormatString, FormatParseError> {
504+
fn from_str(text: &str) -> Result<Self, Self::Err> {
501505
let mut cur_text: &str = text;
502506
let mut parts: Vec<FormatPart> = Vec::new();
503507
while !cur_text.is_empty() {

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl Frame {
197197
}
198198
bytecode::Instruction::Rotate { amount } => {
199199
// Shuffles top of stack amount down
200-
if amount < &2 {
200+
if *amount < 2 {
201201
panic!("Can only rotate two or more values");
202202
}
203203

vm/src/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn import(
7777
let import_error = vm.context().exceptions.import_error.clone();
7878
Err(vm.new_exception(import_error, format!("cannot import name '{}'", symbol)))
7979
},
80-
|obj| Ok(obj),
80+
Ok,
8181
)
8282
} else {
8383
Ok(module)

vm/src/obj/objbytearray.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,10 @@ fn bytearray_istitle(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
214214
let current = char::from(*c);
215215
let next = if let Some(k) = iter.peek() {
216216
char::from(**k)
217+
} else if current.is_uppercase() {
218+
return Ok(vm.new_bool(!prev_cased));
217219
} else {
218-
if current.is_uppercase() {
219-
return Ok(vm.new_bool(!prev_cased));
220-
} else {
221-
return Ok(vm.new_bool(prev_cased));
222-
}
220+
return Ok(vm.new_bool(prev_cased));
223221
};
224222

225223
if (is_cased(current) && next.is_uppercase() && !prev_cased)

vm/src/obj/objcode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn init(context: &PyContext) {
1414
context.set_attr(code_type, "__new__", context.new_rustfunc(code_new));
1515
context.set_attr(code_type, "__repr__", context.new_rustfunc(code_repr));
1616

17-
for (name, f) in vec![
17+
for (name, f) in &[
1818
(
1919
"co_argcount",
2020
code_co_argcount as fn(&mut VirtualMachine, PyFuncArgs) -> PyResult,

vm/src/obj/objmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1414
let function = &args.args[1];
1515
let iterables = &args.args[2..];
1616
let iterators = iterables
17-
.into_iter()
17+
.iter()
1818
.map(|iterable| objiter::get_iter(vm, iterable))
1919
.collect::<Result<Vec<_>, _>>()?;
2020
Ok(PyObject::new(

vm/src/obj/objrange.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ impl RangeType {
4242
#[inline]
4343
fn offset(&self, value: &BigInt) -> Option<BigInt> {
4444
match self.step.sign() {
45-
Sign::Plus if value >= &self.start && value < &self.end => Some(value - &self.start),
46-
Sign::Minus if value <= &self.start && value > &self.end => Some(&self.start - value),
45+
Sign::Plus if *value >= self.start && *value < self.end => Some(value - &self.start),
46+
Sign::Minus if *value <= self.start && *value > self.end => Some(&self.start - value),
4747
_ => None,
4848
}
4949
}
@@ -68,9 +68,10 @@ impl RangeType {
6868

6969
#[inline]
7070
pub fn count(&self, value: &BigInt) -> usize {
71-
match self.index_of(value).is_some() {
72-
true => 1,
73-
false => 0,
71+
if self.index_of(value).is_some() {
72+
1
73+
} else {
74+
0
7475
}
7576
}
7677

@@ -145,7 +146,7 @@ pub fn get_value(obj: &PyObjectRef) -> RangeType {
145146
}
146147

147148
pub fn init(context: &PyContext) {
148-
let ref range_type = context.range_type;
149+
let range_type = &context.range_type;
149150

150151
let range_doc = "range(stop) -> range object\n\
151152
range(start, stop[, step]) -> range object\n\n\
@@ -198,7 +199,7 @@ fn range_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
198199
]
199200
);
200201

201-
let start = if let Some(_) = second {
202+
let start = if second.is_some() {
202203
objint::get_value(first)
203204
} else {
204205
BigInt::zero()

vm/src/obj/objsequence.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub trait PySliceableSequence {
1515
fn do_stepped_slice_reverse(&self, range: Range<usize>, step: usize) -> Self;
1616
fn empty() -> Self;
1717
fn len(&self) -> usize;
18+
fn is_empty(&self) -> bool;
1819
fn get_pos(&self, p: i32) -> Option<usize> {
1920
if p < 0 {
2021
if -p as usize > self.len() {
@@ -127,6 +128,10 @@ impl<T: Clone> PySliceableSequence for Vec<T> {
127128
fn len(&self) -> usize {
128129
self.len()
129130
}
131+
132+
fn is_empty(&self) -> bool {
133+
self.is_empty()
134+
}
130135
}
131136

132137
pub fn get_item(
@@ -288,7 +293,7 @@ pub fn seq_mul(elements: &[PyObjectRef], product: &PyObjectRef) -> Vec<PyObjectR
288293
let mut new_elements = Vec::with_capacity(new_len);
289294

290295
for _ in 0..counter {
291-
new_elements.extend(elements.clone().to_owned());
296+
new_elements.extend(elements.to_owned());
292297
}
293298

294299
new_elements

vm/src/obj/objset.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,48 +180,48 @@ pub fn set_contains(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
180180
}
181181

182182
fn set_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
183-
return set_compare_inner(
183+
set_compare_inner(
184184
vm,
185185
args,
186186
&|zelf: usize, other: usize| -> bool { zelf != other },
187187
false,
188-
);
188+
)
189189
}
190190

191191
fn set_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
192-
return set_compare_inner(
192+
set_compare_inner(
193193
vm,
194194
args,
195195
&|zelf: usize, other: usize| -> bool { zelf < other },
196196
false,
197-
);
197+
)
198198
}
199199

200200
fn set_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
201-
return set_compare_inner(
201+
set_compare_inner(
202202
vm,
203203
args,
204204
&|zelf: usize, other: usize| -> bool { zelf <= other },
205205
false,
206-
);
206+
)
207207
}
208208

209209
fn set_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
210-
return set_compare_inner(
210+
set_compare_inner(
211211
vm,
212212
args,
213213
&|zelf: usize, other: usize| -> bool { zelf < other },
214214
true,
215-
);
215+
)
216216
}
217217

218218
fn set_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
219-
return set_compare_inner(
219+
set_compare_inner(
220220
vm,
221221
args,
222222
&|zelf: usize, other: usize| -> bool { zelf <= other },
223223
true,
224-
);
224+
)
225225
}
226226

227227
fn set_compare_inner(

0 commit comments

Comments
 (0)