Skip to content

Commit c130672

Browse files
committed
Fix clippy warnings
1 parent f3b073a commit c130672

19 files changed

Lines changed: 58 additions & 66 deletions

compiler/src/compile.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,7 @@ impl<O: OutputStream> Compiler<O> {
10831083
// Doc string value:
10841084
self.emit(Instruction::LoadConst {
10851085
value: match doc_str {
1086-
Some(doc) => bytecode::Constant::String {
1087-
value: doc.to_string(),
1088-
},
1086+
Some(doc) => bytecode::Constant::String { value: doc },
10891087
None => bytecode::Constant::None, // set docstring None if not declared
10901088
},
10911089
});
@@ -2199,7 +2197,7 @@ fn get_doc(body: &[ast::Statement]) -> (&[ast::Statement], Option<String>) {
21992197
if let ast::StatementType::Expression { ref expression } = val.node {
22002198
if let ast::ExpressionType::String { value } = &expression.node {
22012199
if let Some(value) = try_get_constant_string(value) {
2202-
return (body_rest, Some(value.to_string()));
2200+
return (body_rest, Some(value));
22032201
}
22042202
}
22052203
}

derive/src/compile_bytecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ impl CompilationSource {
6666
})?;
6767
hashmap! {
6868
module_name.clone() => FrozenModule {
69-
code: self.compile_string(&source, mode, module_name.clone())?,
69+
code: self.compile_string(&source, mode, module_name)?,
7070
package: false,
7171
},
7272
}
7373
}
7474
CompilationSourceKind::SourceCode(code) => {
7575
hashmap! {
7676
module_name.clone() => FrozenModule {
77-
code: self.compile_string(code, mode, module_name.clone())?,
77+
code: self.compile_string(code, mode, module_name)?,
7878
package: false,
7979
},
8080
}

parser/src/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn parse_params(params: Vec<ParameterDef>) -> Result<ParameterDefs, LexicalE
2020
// have defaults
2121
return Err(LexicalError {
2222
error: LexicalErrorType::DefaultArgumentError,
23-
location: name.location.clone(),
23+
location: name.location,
2424
});
2525
}
2626
}
@@ -44,7 +44,7 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
4444
if keyword_names.contains(&keyword_name) {
4545
return Err(LexicalError {
4646
error: LexicalErrorType::DuplicateKeywordArgumentError,
47-
location: value.location.clone(),
47+
location: value.location,
4848
});
4949
}
5050

@@ -58,7 +58,7 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
5858
if !keywords.is_empty() && !is_starred(&value) {
5959
return Err(LexicalError {
6060
error: LexicalErrorType::PositionalArgumentError,
61-
location: value.location.clone(),
61+
location: value.location,
6262
});
6363
}
6464

parser/src/lexer.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,28 @@ impl IndentationLevel {
3333
// We only know for sure that we're smaller or bigger if tabs
3434
// and spaces both differ in the same direction. Otherwise we're
3535
// dependent on the size of tabs.
36-
if self.tabs < other.tabs {
37-
if self.spaces <= other.spaces {
38-
Ok(Ordering::Less)
39-
} else {
40-
Err(LexicalError {
41-
location,
42-
error: LexicalErrorType::TabError,
43-
})
36+
match self.tabs.cmp(&other.tabs) {
37+
Ordering::Less => {
38+
if self.spaces <= other.spaces {
39+
Ok(Ordering::Less)
40+
} else {
41+
Err(LexicalError {
42+
location,
43+
error: LexicalErrorType::TabError,
44+
})
45+
}
4446
}
45-
} else if self.tabs > other.tabs {
46-
if self.spaces >= other.spaces {
47-
Ok(Ordering::Greater)
48-
} else {
49-
Err(LexicalError {
50-
location,
51-
error: LexicalErrorType::TabError,
52-
})
47+
Ordering::Greater => {
48+
if self.spaces >= other.spaces {
49+
Ok(Ordering::Greater)
50+
} else {
51+
Err(LexicalError {
52+
location,
53+
error: LexicalErrorType::TabError,
54+
})
55+
}
5356
}
54-
} else {
55-
Ok(self.spaces.cmp(&other.spaces))
57+
Ordering::Equal => Ok(self.spaces.cmp(&other.spaces)),
5658
}
5759
}
5860
}

vm/src/builtins.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ fn builtin_locals(vm: &VirtualMachine) -> PyDictRef {
396396
}
397397

398398
fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
399-
let candidates = if args.args.len() > 1 {
400-
args.args.clone()
401-
} else if args.args.len() == 1 {
402-
vm.extract_elements(&args.args[0])?
403-
} else {
404-
// zero arguments means type error:
405-
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
399+
let candidates = match args.args.len().cmp(&1) {
400+
std::cmp::Ordering::Greater => args.args.clone(),
401+
std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?,
402+
std::cmp::Ordering::Less => {
403+
// zero arguments means type error:
404+
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
405+
}
406406
};
407407

408408
if candidates.is_empty() {
@@ -442,13 +442,13 @@ fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
442442
}
443443

444444
fn builtin_min(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
445-
let candidates = if args.args.len() > 1 {
446-
args.args.clone()
447-
} else if args.args.len() == 1 {
448-
vm.extract_elements(&args.args[0])?
449-
} else {
450-
// zero arguments means type error:
451-
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
445+
let candidates = match args.args.len().cmp(&1) {
446+
std::cmp::Ordering::Greater => args.args.clone(),
447+
std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?,
448+
std::cmp::Ordering::Less => {
449+
// zero arguments means type error:
450+
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
451+
}
452452
};
453453

454454
if candidates.is_empty() {

vm/src/cformat.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,15 @@ fn parse_literal(text: &str) -> Result<(CFormatPart, &str, usize), ParsingError>
379379
}
380380
Err(err) => {
381381
if !result_string.is_empty() {
382-
return Ok((
383-
CFormatPart::Literal(result_string.to_string()),
384-
cur_text,
385-
consumed,
386-
));
382+
return Ok((CFormatPart::Literal(result_string), cur_text, consumed));
387383
} else {
388384
return Err((err, consumed));
389385
}
390386
}
391387
}
392388
}
393389
Ok((
394-
CFormatPart::Literal(result_string.to_string()),
390+
CFormatPart::Literal(result_string),
395391
"",
396392
text.chars().count(),
397393
))

vm/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl FormatString {
500500
}
501501
Err(err) => {
502502
if !result_string.is_empty() {
503-
return Ok((FormatPart::Literal(result_string.to_string()), cur_text));
503+
return Ok((FormatPart::Literal(result_string), cur_text));
504504
} else {
505505
return Err(err);
506506
}

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ impl Frame {
736736
BlockType::Finally { handler } => {
737737
self.pop_block();
738738
self.push_block(BlockType::FinallyHandler {
739-
reason: Some(reason.clone()),
739+
reason: Some(reason),
740740
});
741741
self.jump(handler);
742742
return Ok(None);

vm/src/obj/objbyteinner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl ByteInnerSplitOptions {
260260
-1
261261
};
262262

263-
Ok((sep.clone(), maxsplit))
263+
Ok((sep, maxsplit))
264264
}
265265
}
266266

vm/src/obj/objenumerate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl PyEnumerate {
4141

4242
let iterator = objiter::get_iter(vm, &iterable)?;
4343
PyEnumerate {
44-
counter: RefCell::new(counter.clone()),
44+
counter: RefCell::new(counter),
4545
iterator,
4646
}
4747
.into_ref_with_type(vm, cls)

0 commit comments

Comments
 (0)