diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index 8ea3bc520..dbe938fd1 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -290,7 +290,7 @@ impl Compiler { fn load_name(&mut self, name: &str) { let scope = self.scope_for_name(name); self.emit(Instruction::LoadName { - name: name.to_string(), + name: name.to_owned(), scope, }); } @@ -298,7 +298,7 @@ impl Compiler { fn store_name(&mut self, name: &str) { let scope = self.scope_for_name(name); self.emit(Instruction::StoreName { - name: name.to_string(), + name: name.to_owned(), scope, }); } @@ -359,7 +359,7 @@ impl Compiler { for name in names { // import symbol from module: self.emit(Instruction::ImportFrom { - name: name.symbol.to_string(), + name: name.symbol.to_owned(), }); // Store module under proper name: @@ -619,13 +619,13 @@ impl Compiler { match &expression.node { ast::ExpressionType::Identifier { name } => { self.emit(Instruction::DeleteName { - name: name.to_string(), + name: name.to_owned(), }); } ast::ExpressionType::Attribute { value, name } => { self.compile_expression(value)?; self.emit(Instruction::DeleteAttr { - name: name.to_string(), + name: name.to_owned(), }); } ast::ExpressionType::Subscript { a, b } => { @@ -701,7 +701,7 @@ impl Compiler { compile_varargs(&args.kwarg), self.source_path.clone().unwrap(), line_number, - name.to_string(), + name.to_owned(), )); self.enter_scope(); @@ -909,7 +909,7 @@ impl Compiler { if let Some(annotation) = &arg.annotation { self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: arg.arg.to_string(), + value: arg.arg.to_owned(), }, }); self.compile_expression(&annotation)?; @@ -982,7 +982,7 @@ impl Compiler { Varargs::None, self.source_path.clone().unwrap(), line_number, - name.to_string(), + name.to_owned(), )); self.enter_scope(); @@ -1022,7 +1022,7 @@ impl Compiler { }); self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }, }); @@ -1044,7 +1044,7 @@ impl Compiler { for keyword in keywords { if let Some(name) = &keyword.name { kwarg_names.push(bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }); } else { // This means **kwargs! @@ -1308,7 +1308,7 @@ impl Compiler { }); self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }, }); self.emit(Instruction::StoreSubscript); @@ -1332,7 +1332,7 @@ impl Compiler { ast::ExpressionType::Attribute { value, name } => { self.compile_expression(value)?; self.emit(Instruction::StoreAttr { - name: name.to_string(), + name: name.to_owned(), }); } ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => { @@ -1605,7 +1605,7 @@ impl Compiler { Attribute { value, name } => { self.compile_expression(value)?; self.emit(Instruction::LoadAttr { - name: name.to_string(), + name: name.to_owned(), }); } Compare { vals, ops } => { @@ -1795,7 +1795,7 @@ impl Compiler { if let Some(name) = &keyword.name { self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }, }); self.compile_expression(&keyword.value)?; @@ -1858,7 +1858,7 @@ impl Compiler { for keyword in keywords { if let Some(name) = &keyword.name { kwarg_names.push(bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }); } else { // This means **kwargs! @@ -1927,7 +1927,7 @@ impl Compiler { ast::ComprehensionKind::Set { .. } => "", ast::ComprehensionKind::Dict { .. } => "", } - .to_string(); + .to_owned(); let line_number = self.get_source_line_number(); // Create magnificent function : @@ -2099,7 +2099,7 @@ impl Compiler { ast::StringGroup::Constant { value } => { self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: value.to_string(), + value: value.to_owned(), }, }); } @@ -2266,7 +2266,7 @@ mod tests { let mut compiler: Compiler = Default::default(); compiler.source_path = Some("source_path".to_owned()); compiler.push_new_code_object("".to_owned()); - let ast = parser::parse_program(&source.to_string()).unwrap(); + let ast = parser::parse_program(source).unwrap(); let symbol_scope = make_symbol_table(&ast).unwrap(); compiler.compile_program(&ast, symbol_scope).unwrap(); compiler.pop_code_object() diff --git a/compiler/src/symboltable.rs b/compiler/src/symboltable.rs index c3e2099bc..d08aa4f2e 100644 --- a/compiler/src/symboltable.rs +++ b/compiler/src/symboltable.rs @@ -105,7 +105,7 @@ pub struct Symbol { impl Symbol { fn new(name: &str) -> Self { Symbol { - name: name.to_string(), + name: name.to_owned(), // table, scope: SymbolScope::Unknown, is_param: false, @@ -304,7 +304,7 @@ impl SymbolTableBuilder { } fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) { - let table = SymbolTable::new(name.to_string(), typ, line_number); + let table = SymbolTable::new(name.to_owned(), typ, line_number); self.tables.push(table); } @@ -793,7 +793,7 @@ impl SymbolTableBuilder { // Insert symbol when required: if !containing { let symbol = Symbol::new(name); - table.symbols.insert(name.to_string(), symbol); + table.symbols.insert(name.to_owned(), symbol); } // Set proper flags on symbol: diff --git a/derive/src/compile_bytecode.rs b/derive/src/compile_bytecode.rs index 01f5226d6..1206469fa 100644 --- a/derive/src/compile_bytecode.rs +++ b/derive/src/compile_bytecode.rs @@ -128,7 +128,7 @@ impl CompilationSource { let module_name = if is_init { parent.clone() } else if parent.is_empty() { - stem.to_string() + stem.to_owned() } else { format!("{}.{}", parent, stem) }; diff --git a/derive/src/pyclass.rs b/derive/src/pyclass.rs index fb6ac4b04..006bd4e60 100644 --- a/derive/src/pyclass.rs +++ b/derive/src/pyclass.rs @@ -620,7 +620,7 @@ fn generate_class_def( let meta = attr.parse_meta().expect("expected doc attr to be a meta"); if let Meta::NameValue(name_value) = meta { if let Lit::Str(s) = name_value.lit { - let val = s.value().trim().to_string(); + let val = s.value().trim().to_owned(); match doc { Some(ref mut doc) => doc.push(val), None => doc = Some(vec![val]), diff --git a/parser/src/fstring.rs b/parser/src/fstring.rs index 7ecd8a123..5ca92c484 100644 --- a/parser/src/fstring.rs +++ b/parser/src/fstring.rs @@ -83,7 +83,7 @@ impl<'a> FStringParser<'a> { })) } else { spec = Some(Box::new(Constant { - value: spec_expression.to_string(), + value: spec_expression.to_owned(), })) } } diff --git a/src/main.rs b/src/main.rs index 9253e7f65..4b82077b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -364,7 +364,7 @@ fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> { // Figure out if a -c option was given: if let Some(command) = matches.value_of("c") { - run_command(&vm, scope, command.to_string())?; + run_command(&vm, scope, command.to_owned())?; } else if let Some(module) = matches.value_of("m") { run_module(&vm, module)?; } else if let Some(filename) = matches.value_of("script") { @@ -426,13 +426,13 @@ fn run_script(vm: &VirtualMachine, scope: Scope, script_file: &str) -> PyResult< process::exit(1); }; - let dir = file_path.parent().unwrap().to_str().unwrap().to_string(); + let dir = file_path.parent().unwrap().to_str().unwrap().to_owned(); let sys_path = vm.get_attribute(vm.sys_module.clone(), "path").unwrap(); vm.call_method(&sys_path, "insert", vec![vm.new_int(0), vm.new_str(dir)])?; match util::read_file(&file_path) { Ok(source) => { - _run_string(vm, scope, &source, file_path.to_str().unwrap().to_string())?; + _run_string(vm, scope, &source, file_path.to_str().unwrap().to_owned())?; } Err(err) => { error!( diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 3f545a79e..72891812c 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -146,7 +146,7 @@ fn builtin_compile(args: CompileArgs, vm: &VirtualMachine) -> PyResult { .parse::() .map_err(|err| vm.new_value_error(err.to_string()))?; - vm.compile(&source, mode, args.filename.as_str().to_string()) + vm.compile(&source, mode, args.filename.as_str().to_owned()) .map(|o| o.into_object()) .map_err(|err| vm.new_syntax_error(&err)) } @@ -920,7 +920,7 @@ pub fn builtin_build_class_( vm: &VirtualMachine, ) -> PyResult { let name = qualified_name.as_str().split('.').next_back().unwrap(); - let name_obj = vm.new_str(name.to_string()); + let name_obj = vm.new_str(name.to_owned()); let mut metaclass = if let Some(metaclass) = kwargs.pop_kwarg("metaclass") { PyClassRef::try_from_object(vm, metaclass)? diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index d7dcb8fc3..5541f1758 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -344,7 +344,7 @@ impl DictKey for &PyObjectRef { impl DictKey for &str { fn do_hash(self, _vm: &VirtualMachine) -> PyResult { // follow a similar route as the hashing of PyStringRef - let raw_hash = pyhash::hash_value(&self.to_string()).to_bigint().unwrap(); + let raw_hash = pyhash::hash_value(&self.to_owned()).to_bigint().unwrap(); let raw_hash = pyhash::hash_bigint(&raw_hash); let mut hasher = DefaultHasher::new(); raw_hash.hash(&mut hasher); @@ -362,7 +362,7 @@ impl DictKey for &str { Ok(py_str_value.as_str() == self) } else { // Fall back to PyString implementation. - let s = vm.new_str(self.to_string()); + let s = vm.new_str(self.to_owned()); s.do_eq(vm, other_key) } } @@ -438,7 +438,7 @@ mod tests { fn check_hash_equivalence(text: &str) { let vm: VirtualMachine = Default::default(); let value1 = text; - let value2 = vm.new_str(value1.to_string()); + let value2 = vm.new_str(value1.to_owned()); let hash1 = value1.do_hash(&vm).expect("Hash should not fail."); let hash2 = value2.do_hash(&vm).expect("Hash should not fail."); diff --git a/vm/src/eval.rs b/vm/src/eval.rs index 3d998f8b4..68255302b 100644 --- a/vm/src/eval.rs +++ b/vm/src/eval.rs @@ -4,7 +4,7 @@ use crate::vm::VirtualMachine; use rustpython_compiler::compile; pub fn eval(vm: &VirtualMachine, source: &str, scope: Scope, source_path: &str) -> PyResult { - match vm.compile(source, compile::Mode::Eval, source_path.to_string()) { + match vm.compile(source, compile::Mode::Eval, source_path.to_owned()) { Ok(bytecode) => { debug!("Code object: {:?}", bytecode); vm.run_code_obj(bytecode, scope) diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 208272bb1..135cb0d6f 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -225,7 +225,7 @@ fn print_source_line(output: &mut W, filename: &str, lineno: usize) -> /// Print exception occurrence location from traceback element fn write_traceback_entry(output: &mut W, tb_entry: &PyTracebackRef) -> io::Result<()> { - let filename = tb_entry.frame.code.source_path.to_string(); + let filename = tb_entry.frame.code.source_path.to_owned(); writeln!( output, r##" File "{}", line {}, in {}"##, diff --git a/vm/src/format.rs b/vm/src/format.rs index 39c6ac2e7..73d444a8e 100644 --- a/vm/src/format.rs +++ b/vm/src/format.rs @@ -614,7 +614,7 @@ impl FormatString { let arg_part = parts[0]; let format_spec = if parts.len() > 1 { - parts[1].to_string() + parts[1].to_owned() } else { String::new() }; @@ -638,7 +638,7 @@ impl FormatString { if let Ok(index) = arg_part.parse::() { Ok(FormatPart::IndexSpec(index, format_spec)) } else { - Ok(FormatPart::KeywordSpec(arg_part.to_string(), format_spec)) + Ok(FormatPart::KeywordSpec(arg_part.to_owned(), format_spec)) } } diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 82b76b32d..4466bc881 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -1154,7 +1154,7 @@ impl Frame { .new_pyfunction(code_obj, scope, defaults, kw_only_defaults); let name = qualified_name.as_str().split('.').next_back().unwrap(); - vm.set_attr(&func_obj, "__name__", vm.new_str(name.to_string()))?; + vm.set_attr(&func_obj, "__name__", vm.new_str(name.to_owned()))?; vm.set_attr(&func_obj, "__qualname__", qualified_name)?; let module = self .scope @@ -1319,13 +1319,13 @@ impl Frame { fn store_attr(&self, vm: &VirtualMachine, attr_name: &str) -> FrameResult { let parent = self.pop_value(); let value = self.pop_value(); - vm.set_attr(&parent, vm.new_str(attr_name.to_string()), value)?; + vm.set_attr(&parent, vm.new_str(attr_name.to_owned()), value)?; Ok(None) } fn delete_attr(&self, vm: &VirtualMachine, attr_name: &str) -> FrameResult { let parent = self.pop_value(); - let name = vm.ctx.new_str(attr_name.to_string()); + let name = vm.ctx.new_str(attr_name.to_owned()); vm.del_attr(&parent, name)?; Ok(None) } diff --git a/vm/src/import.rs b/vm/src/import.rs index 866d8c04f..bcfe4ba22 100644 --- a/vm/src/import.rs +++ b/vm/src/import.rs @@ -91,7 +91,7 @@ pub fn import_codeobj( set_file_attr: bool, ) -> PyResult { let attrs = vm.ctx.new_dict(); - attrs.set_item("__name__", vm.new_str(module_name.to_string()), vm)?; + attrs.set_item("__name__", vm.new_str(module_name.to_owned()), vm)?; if set_file_attr { attrs.set_item("__file__", vm.new_str(code_obj.source_path.to_owned()), vm)?; } diff --git a/vm/src/obj/objbool.rs b/vm/src/obj/objbool.rs index a4b751c7e..264d30599 100644 --- a/vm/src/obj/objbool.rs +++ b/vm/src/obj/objbool.rs @@ -96,7 +96,7 @@ The class bool is a subclass of the class int, and cannot be subclassed."; "__rand__" => context.new_method(bool_and), "__xor__" => context.new_method(bool_xor), "__rxor__" => context.new_method(bool_xor), - "__doc__" => context.new_str(bool_doc.to_string()), + "__doc__" => context.new_str(bool_doc.to_owned()), }); } diff --git a/vm/src/obj/objbyteinner.rs b/vm/src/obj/objbyteinner.rs index 6a21f461f..a507900e8 100644 --- a/vm/src/obj/objbyteinner.rs +++ b/vm/src/obj/objbyteinner.rs @@ -442,7 +442,7 @@ impl PyByteInner { i @ PyMemoryView => Ok(i.try_value().unwrap()), _ => Err(vm.new_index_error( "can assign only bytes, buffers, or iterables of ints in range(0, 256)" - .to_string() + .to_owned() )), }), }; diff --git a/vm/src/obj/objdict.rs b/vm/src/obj/objdict.rs index d00e404a4..8eca81299 100644 --- a/vm/src/obj/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -524,7 +524,7 @@ macro_rules! dict_iterator { let mut str_parts = vec![]; for (key, value) in zelf.dict.clone() { let s = vm.to_repr(&$result_fn(vm, &key, &value))?; - str_parts.push(s.as_str().to_string()); + str_parts.push(s.as_str().to_owned()); } format!("{}([{}])", $class_name, str_parts.join(", ")) } else { diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index a54833528..acb2cc70c 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -94,7 +94,7 @@ macro_rules! impl_try_from_object_int { vm.new_overflow_error(concat!( "Int value cannot fit into Rust ", stringify!($t) - ).to_string()) + ).to_owned()) ), } } diff --git a/vm/src/obj/objlist.rs b/vm/src/obj/objlist.rs index 5dc58f26c..94b854873 100644 --- a/vm/src/obj/objlist.rs +++ b/vm/src/obj/objlist.rs @@ -453,7 +453,7 @@ impl PyList { let mut str_parts = Vec::with_capacity(zelf.elements.borrow().len()); for elem in zelf.elements.borrow().iter() { let s = vm.to_repr(elem)?; - str_parts.push(s.as_str().to_string()); + str_parts.push(s.as_str().to_owned()); } format!("[{}]", str_parts.join(", ")) } else { diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 10e6eba69..9be051230 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -61,7 +61,7 @@ impl PyString { impl From<&str> for PyString { fn from(s: &str) -> PyString { - s.to_string().into() + s.to_owned().into() } } @@ -277,7 +277,7 @@ impl PyString { Either::B(slice) => { let string = self .value - .to_string() + .to_owned() .get_slice_items(vm, slice.as_object())?; Ok(vm.new_str(string)) } @@ -419,21 +419,21 @@ impl PyString { let elements: Vec<_> = match (pattern, num_splits.is_negative()) { (Some(pattern), true) => value .split(pattern) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), (Some(pattern), false) => value .splitn(num_splits as usize + 1, pattern) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), (None, true) => value .split(|c: char| c.is_ascii_whitespace()) .filter(|s| !s.is_empty()) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), (None, false) => value .splitn(num_splits as usize + 1, |c: char| c.is_ascii_whitespace()) .filter(|s| !s.is_empty()) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), }; vm.ctx.new_list(elements) @@ -447,21 +447,21 @@ impl PyString { let mut elements: Vec<_> = match (pattern, num_splits.is_negative()) { (Some(pattern), true) => value .rsplit(pattern) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), (Some(pattern), false) => value .rsplitn(num_splits as usize + 1, pattern) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), (None, true) => value .rsplit(|c: char| c.is_ascii_whitespace()) .filter(|s| !s.is_empty()) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), (None, false) => value .rsplitn(num_splits as usize + 1, |c: char| c.is_ascii_whitespace()) .filter(|s| !s.is_empty()) - .map(|o| vm.ctx.new_str(o.to_string())) + .map(|o| vm.ctx.new_str(o.to_owned())) .collect(), }; // Unlike Python rsplit, Rust rsplitn returns an iterator that @@ -474,31 +474,31 @@ impl PyString { fn strip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> String { let chars = match chars { OptionalArg::Present(ref chars) => &chars.value, - OptionalArg::Missing => return self.value.trim().to_string(), + OptionalArg::Missing => return self.value.trim().to_owned(), }; - self.value.trim_matches(|c| chars.contains(c)).to_string() + self.value.trim_matches(|c| chars.contains(c)).to_owned() } #[pymethod] fn lstrip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> String { let chars = match chars { OptionalArg::Present(ref chars) => &chars.value, - OptionalArg::Missing => return self.value.trim_start().to_string(), + OptionalArg::Missing => return self.value.trim_start().to_owned(), }; self.value .trim_start_matches(|c| chars.contains(c)) - .to_string() + .to_owned() } #[pymethod] fn rstrip(&self, chars: OptionalArg, _vm: &VirtualMachine) -> String { let chars = match chars { OptionalArg::Present(ref chars) => &chars.value, - OptionalArg::Missing => return self.value.trim_end().to_string(), + OptionalArg::Missing => return self.value.trim_end().to_owned(), }; self.value .trim_end_matches(|c| chars.contains(c)) - .to_string() + .to_owned() } #[pymethod] @@ -904,7 +904,7 @@ impl PyString { if value.contains(sub) { new_tup = value .splitn(2, sub) - .map(|s| vm.ctx.new_str(s.to_string())) + .map(|s| vm.ctx.new_str(s.to_owned())) .collect(); new_tup.insert(1, vm.ctx.new_str(sub.clone())); } else { @@ -923,7 +923,7 @@ impl PyString { if value.contains(sub) { new_tup = value .rsplitn(2, sub) - .map(|s| vm.ctx.new_str(s.to_string())) + .map(|s| vm.ctx.new_str(s.to_owned())) .collect(); new_tup.swap(0, 1); // so it's in the right order new_tup.insert(1, vm.ctx.new_str(sub.clone())); @@ -985,7 +985,7 @@ impl PyString { fn zfill(&self, len: usize, _vm: &VirtualMachine) -> String { let value = &self.value; if len <= value.len() { - value.to_string() + value.to_owned() } else { format!("{}{}", "0".repeat(len - value.len()), value) } @@ -1017,7 +1017,7 @@ impl PyString { let value = &self.value; let rep_char = Self::get_fill_char(&rep, vm)?; if len <= value.len() { - Ok(value.to_string()) + Ok(value.to_owned()) } else { Ok(format!("{}{}", value, rep_char.repeat(len - value.len()))) } @@ -1033,7 +1033,7 @@ impl PyString { let value = &self.value; let rep_char = Self::get_fill_char(&rep, vm)?; if len <= value.len() { - Ok(value.to_string()) + Ok(value.to_owned()) } else { Ok(format!("{}{}", rep_char.repeat(len - value.len()), value)) } @@ -1051,7 +1051,7 @@ impl PyString { let value_len = self.value.chars().count(); if len <= value_len { - return Ok(value.to_string()); + return Ok(value.to_owned()); } let diff: usize = len - value_len; let mut left_buff: usize = diff / 2; @@ -1264,7 +1264,7 @@ impl IntoPyObject for String { impl IntoPyObject for &str { fn into_pyobject(self, vm: &VirtualMachine) -> PyResult { - Ok(vm.ctx.new_str(self.to_string())) + Ok(vm.ctx.new_str(self.to_owned())) } } @@ -1314,7 +1314,7 @@ fn call_object_format(vm: &VirtualMachine, argument: PyObjectRef, format_spec: & Some(FormatPreconversor::Bytes) => vm.call_method(&argument, "decode", vec![])?, None => argument, }; - let returned_type = vm.ctx.new_str(new_format_spec.to_string()); + let returned_type = vm.ctx.new_str(new_format_spec.to_owned()); let result = vm.call_method(&argument, "__format__", vec![returned_type])?; if !objtype::isinstance(&result, &vm.ctx.str_type()) { @@ -1485,7 +1485,7 @@ pub fn do_cformat_string( let obj: PyObjectRef = match &format_spec.mapping_key { Some(key) => { // TODO: change the KeyError message to match the one in cpython - call_getitem(vm, &values, &vm.ctx.new_str(key.to_string()))? + call_getitem(vm, &values, &vm.ctx.new_str(key.to_owned()))? } None => { let mut elements = objtuple::get_value(&values) @@ -1555,8 +1555,7 @@ fn perform_format( && format_string.format_parts.iter().any(FormatPart::is_index) { return Err(vm.new_value_error( - "cannot switch from automatic field numbering to manual field specification" - .to_string(), + "cannot switch from automatic field numbering to manual field specification".to_owned(), )); } let mut auto_argument_index: usize = 1; @@ -1585,7 +1584,7 @@ fn perform_format( let result = match arguments.get_optional_kwarg(&keyword) { Some(argument) => call_object_format(vm, argument.clone(), &format_spec)?, None => { - return Err(vm.new_key_error(vm.new_str(keyword.to_string()))); + return Err(vm.new_key_error(vm.new_str(keyword.to_owned()))); } }; clone_value(&result) diff --git a/vm/src/obj/objsuper.rs b/vm/src/obj/objsuper.rs index c47c64057..a9b5aed07 100644 --- a/vm/src/obj/objsuper.rs +++ b/vm/src/obj/objsuper.rs @@ -92,7 +92,7 @@ impl PySuper { _ => { return Err(vm.new_type_error( "super must be called with 1 argument or from inside class method" - .to_string(), + .to_owned(), )); } } @@ -172,6 +172,6 @@ pub fn init(context: &PyContext) { super().cmeth(arg)\n"; extend_class!(context, super_type, { - "__doc__" => context.new_str(super_doc.to_string()), + "__doc__" => context.new_str(super_doc.to_owned()), }); } diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index e7465e6cc..b4a016941 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -101,7 +101,7 @@ impl PyClassRef { let attributes = self.get_attributes(); let attributes: Vec = attributes .keys() - .map(|k| vm.ctx.new_str(k.to_string())) + .map(|k| vm.ctx.new_str(k.to_owned())) .collect(); PyList::from(attributes) } @@ -220,7 +220,7 @@ impl PyClassRef { self.attributes.borrow_mut().remove(attr_name.as_str()); Ok(()) } else { - Err(vm.new_attribute_error(attr_name.as_str().to_string())) + Err(vm.new_attribute_error(attr_name.as_str().to_owned())) } } @@ -228,7 +228,7 @@ impl PyClassRef { pub fn set_str_attr>(&self, attr_name: &str, value: V) { self.attributes .borrow_mut() - .insert(attr_name.to_string(), value.into()); + .insert(attr_name.to_owned(), value.into()); } #[pymethod(magic)] @@ -448,7 +448,7 @@ impl PyClassRef { for bc in base_classes { for (name, value) in bc.attributes.borrow().iter() { - attributes.insert(name.to_string(), value.clone()); + attributes.insert(name.to_owned(), value.clone()); } } @@ -548,7 +548,7 @@ fn calculate_meta_class( return Err(vm.new_type_error( "metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass \ of the metaclasses of all its bases" - .to_string(), + .to_owned(), )); } Ok(winner) diff --git a/vm/src/py_serde.rs b/vm/src/py_serde.rs index 3bd8bedbf..47520bb13 100644 --- a/vm/src/py_serde.rs +++ b/vm/src/py_serde.rs @@ -176,7 +176,7 @@ impl<'de> Visitor<'de> for PyObjectDeserializer<'de> { E: serde::de::Error, { // Owned value needed anyway, delegate to visit_string - self.visit_string(value.to_string()) + self.visit_string(value.to_owned()) } fn visit_string(self, value: String) -> Result diff --git a/vm/src/stdlib/ast.rs b/vm/src/stdlib/ast.rs index d25429dcb..33b3ea622 100644 --- a/vm/src/stdlib/ast.rs +++ b/vm/src/stdlib/ast.rs @@ -35,7 +35,7 @@ macro_rules! node { $( let field_name = stringify!($attr_name); $vm.set_attr(node.as_object(), field_name, $attr_value)?; - field_names.push($vm.ctx.new_str(field_name.to_string())); + field_names.push($vm.ctx.new_str(field_name.to_owned())); )* $vm.set_attr(node.as_object(), "_fields", $vm.ctx.new_tuple(field_names))?; node @@ -81,7 +81,7 @@ fn statement_to_ast(vm: &VirtualMachine, statement: &ast::Statement) -> PyResult decorator_list, .. } => node!(vm, ClassDef, { - name => vm.ctx.new_str(name.to_string()), + name => vm.ctx.new_str(name.to_owned()), keywords => map_ast(keyword_to_ast, vm, keywords)?, body => statements_to_ast(vm, body)?, decorator_list => expressions_to_ast(vm, decorator_list)?, @@ -96,7 +96,7 @@ fn statement_to_ast(vm: &VirtualMachine, statement: &ast::Statement) -> PyResult } => { if *is_async { node!(vm, AsyncFunctionDef, { - name => vm.ctx.new_str(name.to_string()), + name => vm.ctx.new_str(name.to_owned()), args => parameters_to_ast(vm, args)?, body => statements_to_ast(vm, body)?, decorator_list => expressions_to_ast(vm, decorator_list)?, @@ -104,7 +104,7 @@ fn statement_to_ast(vm: &VirtualMachine, statement: &ast::Statement) -> PyResult }) } else { node!(vm, FunctionDef, { - name => vm.ctx.new_str(name.to_string()), + name => vm.ctx.new_str(name.to_owned()), args => parameters_to_ast(vm, args)?, body => statements_to_ast(vm, body)?, decorator_list => expressions_to_ast(vm, decorator_list)?, @@ -245,7 +245,7 @@ fn statement_to_ast(vm: &VirtualMachine, statement: &ast::Statement) -> PyResult fn alias_to_ast(vm: &VirtualMachine, alias: &ast::ImportSymbol) -> PyResult { Ok(node!(vm, alias, { - name => vm.ctx.new_str(alias.symbol.to_string()), + name => vm.ctx.new_str(alias.symbol.to_owned()), asname => optional_string_to_py_obj(vm, &alias.alias) })) } @@ -280,12 +280,8 @@ fn handler_to_ast(vm: &VirtualMachine, handler: &ast::ExceptHandler) -> PyResult } fn make_string_list(vm: &VirtualMachine, names: &[String]) -> PyObjectRef { - vm.ctx.new_list( - names - .iter() - .map(|x| vm.ctx.new_str(x.to_string())) - .collect(), - ) + vm.ctx + .new_list(names.iter().map(|x| vm.ctx.new_str(x.to_owned())).collect()) } fn optional_expressions_to_ast( @@ -344,7 +340,7 @@ fn expression_to_ast(vm: &VirtualMachine, expression: &ast::Expression) -> PyRes ast::UnaryOperator::Pos => "UAdd", }; node!(vm, UnaryOp, { - op => vm.ctx.new_str(op.to_string()), + op => vm.ctx.new_str(op.to_owned()), operand => expression_to_ast(vm, a)?, }) } @@ -355,7 +351,7 @@ fn expression_to_ast(vm: &VirtualMachine, expression: &ast::Expression) -> PyRes ast::BooleanOperator::And => "And", ast::BooleanOperator::Or => "Or", }; - let py_op = vm.ctx.new_str(str_op.to_string()); + let py_op = vm.ctx.new_str(str_op.to_owned()); node!(vm, BoolOp, { op => py_op, @@ -380,7 +376,7 @@ fn expression_to_ast(vm: &VirtualMachine, expression: &ast::Expression) -> PyRes }; let ops = vm.ctx.new_list( ops.iter() - .map(|x| vm.ctx.new_str(to_operator(x).to_string())) + .map(|x| vm.ctx.new_str(to_operator(x).to_owned())) .collect(), ); @@ -510,7 +506,7 @@ fn expression_to_ast(vm: &VirtualMachine, expression: &ast::Expression) -> PyRes }), Attribute { value, name } => node!(vm, Attribute, { value => expression_to_ast(vm, value)?, - attr => vm.ctx.new_str(name.to_string()), + attr => vm.ctx.new_str(name.to_owned()), ctx => vm.ctx.none() }), Starred { value } => node!(vm, Starred, { @@ -545,7 +541,7 @@ fn operator_string(op: &ast::Operator) -> String { BitAnd => "BitAnd", FloorDiv => "FloorDiv", } - .to_string() + .to_owned() } fn parameters_to_ast(vm: &VirtualMachine, args: &ast::Parameters) -> PyResult { @@ -576,7 +572,7 @@ fn parameter_to_ast(vm: &VirtualMachine, parameter: &ast::Parameter) -> PyResult }; let py_node = node!(vm, arg, { - arg => vm.ctx.new_str(parameter.arg.to_string()), + arg => vm.ctx.new_str(parameter.arg.to_owned()), annotation => py_annotation }); @@ -588,7 +584,7 @@ fn parameter_to_ast(vm: &VirtualMachine, parameter: &ast::Parameter) -> PyResult fn optional_string_to_py_obj(vm: &VirtualMachine, name: &Option) -> PyObjectRef { if let Some(name) = name { - vm.ctx.new_str(name.to_string()) + vm.ctx.new_str(name.to_owned()) } else { vm.ctx.none() } diff --git a/vm/src/stdlib/csv.rs b/vm/src/stdlib/csv.rs index 5ed4d71ff..fc42643a2 100644 --- a/vm/src/stdlib/csv.rs +++ b/vm/src/stdlib/csv.rs @@ -35,7 +35,7 @@ impl ReaderOption { 1 => bytes[0], _ => { let msg = r#""delimiter" must be a 1-character string"#; - return Err(vm.new_type_error(msg.to_string())); + return Err(vm.new_type_error(msg.to_owned())); } } } else { @@ -48,7 +48,7 @@ impl ReaderOption { 1 => bytes[0], _ => { let msg = r#""quotechar" must be a 1-character string"#; - return Err(vm.new_type_error(msg.to_string())); + return Err(vm.new_type_error(msg.to_owned())); } } } else { diff --git a/vm/src/stdlib/dis.rs b/vm/src/stdlib/dis.rs index a3f035985..adc31ff17 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_owned()), vm, ) .unwrap(); diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index 4b8f6b412..98a7ce9dd 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -36,7 +36,7 @@ impl PyValue for PyHasher { impl PyHasher { fn new(name: &str, d: HashWrapper) -> Self { PyHasher { - name: name.to_string(), + name: name.to_owned(), buffer: RefCell::new(d), } } diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index ee4ec13d4..378fe5f4f 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -770,7 +770,7 @@ fn text_io_wrapper_write( return Err(vm.new_value_error("not writable".to_owned())); } - let bytes = obj.as_str().to_string().into_bytes(); + let bytes = obj.as_str().to_owned().into_bytes(); let len = vm.call_method(&raw, "write", vec![vm.ctx.new_bytes(bytes.clone())])?; let len = objint::get_value(&len) @@ -858,7 +858,7 @@ fn split_mode_string(mode_string: &str) -> Result<(String, String), String> { if mode == '\0' { return Err( "Must have exactly one of create/read/write/append mode and at most one plus" - .to_string(), + .to_owned(), ); } let mut mode = mode.to_string(); @@ -1102,21 +1102,21 @@ mod tests { split_mode_string(""), Err( "Must have exactly one of create/read/write/append mode and at most one plus" - .to_string() + .to_owned() ) ); assert_eq!( split_mode_string("b"), Err( "Must have exactly one of create/read/write/append mode and at most one plus" - .to_string() + .to_owned() ) ); assert_eq!( split_mode_string("t"), Err( "Must have exactly one of create/read/write/append mode and at most one plus" - .to_string() + .to_owned() ) ); } diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index 79253a36d..e0a104041 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -553,7 +553,7 @@ impl PyItertoolsIslice { Some(pyobject_to_opt_usize(stop, &vm).ok_or_else(|| { vm.new_value_error( "Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize." - .to_string(), + .to_owned(), ) })?) } else { diff --git a/vm/src/stdlib/keyword.rs b/vm/src/stdlib/keyword.rs index cede07e88..e22590ab4 100644 --- a/vm/src/stdlib/keyword.rs +++ b/vm/src/stdlib/keyword.rs @@ -21,7 +21,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { let keyword_kwlist = ctx.new_list( lexer::get_keywords() .keys() - .map(|k| ctx.new_str(k.to_string())) + .map(|k| ctx.new_str(k.to_owned())) .collect(), ); diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index a5b35ecac..a6be3e526 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -312,7 +312,7 @@ fn os_access(path: PyStringRef, mode: u8, vm: &VirtualMachine) -> PyResult let flags = AccessFlags::from_bits(mode).ok_or_else(|| { vm.new_value_error( "One of the flags is wrong, there are only 4 possibilities F_OK, R_OK, W_OK and X_OK" - .to_string(), + .to_owned(), ) })?; @@ -340,7 +340,7 @@ fn os_access(path: PyStringRef, mode: u8, vm: &VirtualMachine) -> PyResult } fn os_error(message: OptionalArg, vm: &VirtualMachine) -> PyResult { - let msg = message.map_or("".to_owned(), |msg| msg.as_str().to_string()); + let msg = message.map_or("".to_owned(), |msg| msg.as_str().to_owned()); Err(vm.new_os_error(msg)) } @@ -524,7 +524,7 @@ impl DirEntryRef { } fn path(self, _vm: &VirtualMachine) -> String { - self.entry.path().to_str().unwrap().to_string() + self.entry.path().to_str().unwrap().to_owned() } #[allow(clippy::match_bool)] @@ -877,7 +877,7 @@ fn os_getcwd(vm: &VirtualMachine) -> PyResult { .as_path() .to_str() .unwrap() - .to_string()) + .to_owned()) } fn os_chdir(path: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { diff --git a/vm/src/stdlib/re.rs b/vm/src/stdlib/re.rs index 9de904e41..25203ba1c 100644 --- a/vm/src/stdlib/re.rs +++ b/vm/src/stdlib/re.rs @@ -283,7 +283,7 @@ fn make_regex(vm: &VirtualMachine, pattern: &str, flags: PyRegexFlags) -> PyResu })?; Ok(PyPattern { regex: r, - pattern: pattern.to_string(), + pattern: pattern.to_owned(), }) } diff --git a/vm/src/stdlib/subprocess.rs b/vm/src/stdlib/subprocess.rs index 57ddfc780..78e8bfafc 100644 --- a/vm/src/stdlib/subprocess.rs +++ b/vm/src/stdlib/subprocess.rs @@ -106,7 +106,7 @@ impl PopenRef { let stdout = convert_redirection(args.stdout, vm)?; let stderr = convert_redirection(args.stderr, vm)?; let command_list = match &args.args { - Either::A(command) => vec![command.as_str().to_string()], + Either::A(command) => vec![command.as_str().to_owned()], Either::B(command_list) => command_list .borrow_elements() .iter() diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 0591b8749..d32afd44a 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -110,7 +110,7 @@ impl PySymbolTable { } .into_ref(vm)) } else { - Err(vm.new_lookup_error(name.to_string())) + Err(vm.new_lookup_error(name.to_owned())) } } @@ -120,7 +120,7 @@ impl PySymbolTable { .symtable .symbols .keys() - .map(|s| vm.ctx.new_str(s.to_string())) + .map(|s| vm.ctx.new_str(s.to_owned())) .collect(); Ok(vm.ctx.new_list(symbols)) } diff --git a/vm/src/stdlib/zlib.rs b/vm/src/stdlib/zlib.rs index cebef22ad..b1b44b2bc 100644 --- a/vm/src/stdlib/zlib.rs +++ b/vm/src/stdlib/zlib.rs @@ -121,5 +121,5 @@ fn zlib_error(message: &str, vm: &VirtualMachine) -> PyBaseExceptionRef { let zlib_error = vm.get_attribute(module, "error").unwrap(); let zlib_error = zlib_error.downcast().unwrap(); - vm.new_exception_msg(zlib_error, message.to_string()) + vm.new_exception_msg(zlib_error, message.to_owned()) } diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index 072fa59b8..fdb04de47 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -345,7 +345,7 @@ settrace() -- set the global debug tracing function "argv" => argv(vm), "builtin_module_names" => builtin_module_names, "byteorder" => ctx.new_str(bytorder), - "copyright" => ctx.new_str(copyright.to_string()), + "copyright" => ctx.new_str(copyright.to_owned()), "executable" => executable(ctx), "flags" => flags, "getrefcount" => ctx.new_function(sys_getrefcount), @@ -363,7 +363,7 @@ settrace() -- set the global debug tracing function "path" => path, "ps1" => ctx.new_str(">>>>> ".to_owned()), "ps2" => ctx.new_str("..... ".to_owned()), - "__doc__" => ctx.new_str(sys_doc.to_string()), + "__doc__" => ctx.new_str(sys_doc.to_owned()), "_getframe" => ctx.new_function(getframe), "modules" => modules.clone(), "warnoptions" => ctx.new_list(vec![]), @@ -381,10 +381,10 @@ settrace() -- set the global debug tracing function "version_info" => version_info, "_git" => sys_git_info(vm), "exc_info" => ctx.new_function(sys_exc_info), - "prefix" => ctx.new_str(prefix.to_string()), - "base_prefix" => ctx.new_str(base_prefix.to_string()), - "exec_prefix" => ctx.new_str(exec_prefix.to_string()), - "base_exec_prefix" => ctx.new_str(base_exec_prefix.to_string()), + "prefix" => ctx.new_str(prefix.to_owned()), + "base_prefix" => ctx.new_str(base_prefix.to_owned()), + "exec_prefix" => ctx.new_str(exec_prefix.to_owned()), + "base_exec_prefix" => ctx.new_str(base_exec_prefix.to_owned()), "exit" => ctx.new_function(sys_exit), "abiflags" => ctx.new_str("".to_owned()), }); diff --git a/vm/src/version.rs b/vm/src/version.rs index c14f6c294..5981d17c5 100644 --- a/vm/src/version.rs +++ b/vm/src/version.rs @@ -71,17 +71,17 @@ pub fn get_build_info() -> String { } pub fn get_git_revision() -> String { - option_env!("RUSTPYTHON_GIT_HASH").unwrap_or("").to_string() + option_env!("RUSTPYTHON_GIT_HASH").unwrap_or("").to_owned() } pub fn get_git_tag() -> String { - option_env!("RUSTPYTHON_GIT_TAG").unwrap_or("").to_string() + option_env!("RUSTPYTHON_GIT_TAG").unwrap_or("").to_owned() } pub fn get_git_branch() -> String { option_env!("RUSTPYTHON_GIT_BRANCH") .unwrap_or("") - .to_string() + .to_owned() } pub fn get_git_identifier() -> String { @@ -98,7 +98,7 @@ pub fn get_git_identifier() -> String { fn get_git_timestamp_datetime() -> DateTime { let timestamp = option_env!("RUSTPYTHON_GIT_TIMESTAMP") .unwrap_or("") - .to_string(); + .to_owned(); let timestamp = timestamp.parse::().unwrap_or(0); let datetime = UNIX_EPOCH + Duration::from_secs(timestamp); diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 7ea7215fb..8d573327d 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -576,7 +576,7 @@ impl VirtualMachine { let from_list = self.ctx.new_tuple( from_list .iter() - .map(|name| self.new_str(name.to_string())) + .map(|name| self.new_str(name.to_owned())) .collect(), ); self.invoke( @@ -908,7 +908,7 @@ impl VirtualMachine { compile::compile(source, mode, source_path, self.settings.optimize) .map(|codeobj| PyCode::new(codeobj).into_ref(self)) .map_err(|mut compile_error| { - compile_error.update_statement_info(source.trim_end().to_string()); + compile_error.update_statement_info(source.trim_end().to_owned()); compile_error }) }