diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index 39f550d0e..24df923b7 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -1083,9 +1083,7 @@ impl Compiler { // Doc string value: self.emit(Instruction::LoadConst { value: match doc_str { - Some(doc) => bytecode::Constant::String { - value: doc.to_string(), - }, + Some(doc) => bytecode::Constant::String { value: doc }, None => bytecode::Constant::None, // set docstring None if not declared }, }); @@ -2199,7 +2197,7 @@ fn get_doc(body: &[ast::Statement]) -> (&[ast::Statement], Option) { if let ast::StatementType::Expression { ref expression } = val.node { if let ast::ExpressionType::String { value } = &expression.node { if let Some(value) = try_get_constant_string(value) { - return (body_rest, Some(value.to_string())); + return (body_rest, Some(value)); } } } diff --git a/derive/src/compile_bytecode.rs b/derive/src/compile_bytecode.rs index a14589caf..b1c1c9cbe 100644 --- a/derive/src/compile_bytecode.rs +++ b/derive/src/compile_bytecode.rs @@ -66,7 +66,7 @@ impl CompilationSource { })?; hashmap! { module_name.clone() => FrozenModule { - code: self.compile_string(&source, mode, module_name.clone())?, + code: self.compile_string(&source, mode, module_name)?, package: false, }, } @@ -74,7 +74,7 @@ impl CompilationSource { CompilationSourceKind::SourceCode(code) => { hashmap! { module_name.clone() => FrozenModule { - code: self.compile_string(code, mode, module_name.clone())?, + code: self.compile_string(code, mode, module_name)?, package: false, }, } diff --git a/parser/src/function.rs b/parser/src/function.rs index f60689786..de6529d8a 100644 --- a/parser/src/function.rs +++ b/parser/src/function.rs @@ -20,7 +20,7 @@ pub fn parse_params(params: Vec) -> Result) -> Result) -> Result { + if self.spaces <= other.spaces { + Ok(Ordering::Less) + } else { + Err(LexicalError { + location, + error: LexicalErrorType::TabError, + }) + } } - } else if self.tabs > other.tabs { - if self.spaces >= other.spaces { - Ok(Ordering::Greater) - } else { - Err(LexicalError { - location, - error: LexicalErrorType::TabError, - }) + Ordering::Greater => { + if self.spaces >= other.spaces { + Ok(Ordering::Greater) + } else { + Err(LexicalError { + location, + error: LexicalErrorType::TabError, + }) + } } - } else { - Ok(self.spaces.cmp(&other.spaces)) + Ordering::Equal => Ok(self.spaces.cmp(&other.spaces)), } } } diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index e33a3bd8b..3ff72416e 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -396,13 +396,13 @@ fn builtin_locals(vm: &VirtualMachine) -> PyDictRef { } fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { - let candidates = if args.args.len() > 1 { - args.args.clone() - } else if args.args.len() == 1 { - vm.extract_elements(&args.args[0])? - } else { - // zero arguments means type error: - return Err(vm.new_type_error("Expected 1 or more arguments".to_string())); + let candidates = match args.args.len().cmp(&1) { + std::cmp::Ordering::Greater => args.args.clone(), + std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?, + std::cmp::Ordering::Less => { + // zero arguments means type error: + return Err(vm.new_type_error("Expected 1 or more arguments".to_string())); + } }; if candidates.is_empty() { @@ -442,13 +442,13 @@ fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { } fn builtin_min(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { - let candidates = if args.args.len() > 1 { - args.args.clone() - } else if args.args.len() == 1 { - vm.extract_elements(&args.args[0])? - } else { - // zero arguments means type error: - return Err(vm.new_type_error("Expected 1 or more arguments".to_string())); + let candidates = match args.args.len().cmp(&1) { + std::cmp::Ordering::Greater => args.args.clone(), + std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?, + std::cmp::Ordering::Less => { + // zero arguments means type error: + return Err(vm.new_type_error("Expected 1 or more arguments".to_string())); + } }; if candidates.is_empty() { diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index e816562d3..7b1b07120 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -379,11 +379,7 @@ fn parse_literal(text: &str) -> Result<(CFormatPart, &str, usize), ParsingError> } Err(err) => { if !result_string.is_empty() { - return Ok(( - CFormatPart::Literal(result_string.to_string()), - cur_text, - consumed, - )); + return Ok((CFormatPart::Literal(result_string), cur_text, consumed)); } else { return Err((err, consumed)); } @@ -391,7 +387,7 @@ fn parse_literal(text: &str) -> Result<(CFormatPart, &str, usize), ParsingError> } } Ok(( - CFormatPart::Literal(result_string.to_string()), + CFormatPart::Literal(result_string), "", text.chars().count(), )) diff --git a/vm/src/format.rs b/vm/src/format.rs index 6180dd3e9..ff4cad783 100644 --- a/vm/src/format.rs +++ b/vm/src/format.rs @@ -500,7 +500,7 @@ impl FormatString { } Err(err) => { if !result_string.is_empty() { - return Ok((FormatPart::Literal(result_string.to_string()), cur_text)); + return Ok((FormatPart::Literal(result_string), cur_text)); } else { return Err(err); } diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 02c669d33..307f93cc5 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -736,7 +736,7 @@ impl Frame { BlockType::Finally { handler } => { self.pop_block(); self.push_block(BlockType::FinallyHandler { - reason: Some(reason.clone()), + reason: Some(reason), }); self.jump(handler); return Ok(None); diff --git a/vm/src/obj/objbyteinner.rs b/vm/src/obj/objbyteinner.rs index 24768e464..d4748d985 100644 --- a/vm/src/obj/objbyteinner.rs +++ b/vm/src/obj/objbyteinner.rs @@ -260,7 +260,7 @@ impl ByteInnerSplitOptions { -1 }; - Ok((sep.clone(), maxsplit)) + Ok((sep, maxsplit)) } } diff --git a/vm/src/obj/objenumerate.rs b/vm/src/obj/objenumerate.rs index 481bbb60e..29617b7df 100644 --- a/vm/src/obj/objenumerate.rs +++ b/vm/src/obj/objenumerate.rs @@ -41,7 +41,7 @@ impl PyEnumerate { let iterator = objiter::get_iter(vm, &iterable)?; PyEnumerate { - counter: RefCell::new(counter.clone()), + counter: RefCell::new(counter), iterator, } .into_ref_with_type(vm, cls) diff --git a/vm/src/obj/objfunction.rs b/vm/src/obj/objfunction.rs index e780fc316..d1e1cb3f9 100644 --- a/vm/src/obj/objfunction.rs +++ b/vm/src/obj/objfunction.rs @@ -85,7 +85,7 @@ impl PyMethod { } fn getattribute(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult { - vm.get_attribute(self.function.clone(), name.clone()) + vm.get_attribute(self.function.clone(), name) } } diff --git a/vm/src/obj/objmap.rs b/vm/src/obj/objmap.rs index 7da6d181d..fde6b95cc 100644 --- a/vm/src/obj/objmap.rs +++ b/vm/src/obj/objmap.rs @@ -39,7 +39,7 @@ impl PyMap { mapper: function.clone(), iterators, } - .into_ref_with_type(vm, cls.clone()) + .into_ref_with_type(vm, cls) } #[pymethod(name = "__next__")] diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs index 2a5a0afef..3b899893d 100644 --- a/vm/src/obj/objobject.rs +++ b/vm/src/obj/objobject.rs @@ -134,7 +134,7 @@ pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { )?; } - let attributes: Vec<_> = dict.into_iter().map(|(k, _v)| k.clone()).collect(); + let attributes: Vec<_> = dict.into_iter().map(|(k, _v)| k).collect(); Ok(PyList::from(attributes)) } diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index 4cfa3aec4..b35b1701f 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -133,7 +133,7 @@ impl PyRange { fn new(cls: PyClassRef, stop: PyIntRef, vm: &VirtualMachine) -> PyResult { PyRange { start: PyInt::new(BigInt::zero()).into_ref(vm), - stop: stop.clone(), + stop, step: PyInt::new(BigInt::one()).into_ref(vm), } .into_ref_with_type(vm, cls) diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index cdbea2e68..ae839248f 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -221,11 +221,7 @@ impl PySlice { // Calculate Stop let mut stop: BigInt; if vm.is_none(&self.stop(vm)) { - stop = if backwards { - lower.clone() - } else { - upper.clone() - }; + stop = if backwards { lower } else { upper }; } else { let this_stop: PyRef = self.stop(vm).try_into_ref(vm)?; stop = this_stop.as_bigint().clone(); @@ -234,10 +230,10 @@ impl PySlice { // From end of array stop += length; if stop < lower { - stop = lower.clone(); + stop = lower; } } else if stop > upper { - stop = upper.clone(); + stop = upper; } } diff --git a/vm/src/obj/objsuper.rs b/vm/src/obj/objsuper.rs index 0768c7b53..157ff1032 100644 --- a/vm/src/obj/objsuper.rs +++ b/vm/src/obj/objsuper.rs @@ -85,7 +85,7 @@ impl PySuper { ) -> PyResult { // Get the type: let py_type = if let OptionalArg::Present(ty) = py_type { - ty.clone() + ty } else { match vm.current_scope().load_cell(vm, "__class__") { Some(obj) => PyClassRef::try_from_object(vm, obj)?, diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index a3f781284..696279b91 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -323,7 +323,7 @@ fn type_new_slot(metatype: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> let attributes = dict.to_attributes(); - let mut winner = metatype.clone(); + let mut winner = metatype; for base in &bases { let base_type = base.class(); if issubclass(&winner, &base_type) { diff --git a/vm/src/stdlib/dis.rs b/vm/src/stdlib/dis.rs index 8302ef919..5814b229b 100644 --- a/vm/src/stdlib/dis.rs +++ b/vm/src/stdlib/dis.rs @@ -23,7 +23,7 @@ fn dis_compiler_flag_names(vm: &VirtualMachine) -> PyObjectRef { for (name, flag) in CodeFlags::NAME_MAPPING { dict.set_item( &vm.ctx.new_int(flag.bits()), - vm.ctx.new_str(name.to_string()), + vm.ctx.new_str((*name).to_string()), vm, ) .unwrap(); diff --git a/vm/src/vm.rs b/vm/src/vm.rs index de48e3d46..ea045f858 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -450,7 +450,7 @@ impl VirtualMachine { } pub fn get_locals(&self) -> PyDictRef { - self.current_scope().get_locals().clone() + self.current_scope().get_locals() } pub fn context(&self) -> &PyContext {