Skip to content

Commit 7d0d313

Browse files
committed
&str::to_string -> &str::to_owned for variables
1 parent 1bac582 commit 7d0d313

37 files changed

+126
-131
lines changed

compiler/src/compile.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ impl<O: OutputStream> Compiler<O> {
290290
fn load_name(&mut self, name: &str) {
291291
let scope = self.scope_for_name(name);
292292
self.emit(Instruction::LoadName {
293-
name: name.to_string(),
293+
name: name.to_owned(),
294294
scope,
295295
});
296296
}
297297

298298
fn store_name(&mut self, name: &str) {
299299
let scope = self.scope_for_name(name);
300300
self.emit(Instruction::StoreName {
301-
name: name.to_string(),
301+
name: name.to_owned(),
302302
scope,
303303
});
304304
}
@@ -359,7 +359,7 @@ impl<O: OutputStream> Compiler<O> {
359359
for name in names {
360360
// import symbol from module:
361361
self.emit(Instruction::ImportFrom {
362-
name: name.symbol.to_string(),
362+
name: name.symbol.to_owned(),
363363
});
364364

365365
// Store module under proper name:
@@ -619,13 +619,13 @@ impl<O: OutputStream> Compiler<O> {
619619
match &expression.node {
620620
ast::ExpressionType::Identifier { name } => {
621621
self.emit(Instruction::DeleteName {
622-
name: name.to_string(),
622+
name: name.to_owned(),
623623
});
624624
}
625625
ast::ExpressionType::Attribute { value, name } => {
626626
self.compile_expression(value)?;
627627
self.emit(Instruction::DeleteAttr {
628-
name: name.to_string(),
628+
name: name.to_owned(),
629629
});
630630
}
631631
ast::ExpressionType::Subscript { a, b } => {
@@ -701,7 +701,7 @@ impl<O: OutputStream> Compiler<O> {
701701
compile_varargs(&args.kwarg),
702702
self.source_path.clone().unwrap(),
703703
line_number,
704-
name.to_string(),
704+
name.to_owned(),
705705
));
706706
self.enter_scope();
707707

@@ -909,7 +909,7 @@ impl<O: OutputStream> Compiler<O> {
909909
if let Some(annotation) = &arg.annotation {
910910
self.emit(Instruction::LoadConst {
911911
value: bytecode::Constant::String {
912-
value: arg.arg.to_string(),
912+
value: arg.arg.to_owned(),
913913
},
914914
});
915915
self.compile_expression(&annotation)?;
@@ -982,7 +982,7 @@ impl<O: OutputStream> Compiler<O> {
982982
Varargs::None,
983983
self.source_path.clone().unwrap(),
984984
line_number,
985-
name.to_string(),
985+
name.to_owned(),
986986
));
987987
self.enter_scope();
988988

@@ -1022,7 +1022,7 @@ impl<O: OutputStream> Compiler<O> {
10221022
});
10231023
self.emit(Instruction::LoadConst {
10241024
value: bytecode::Constant::String {
1025-
value: name.to_string(),
1025+
value: name.to_owned(),
10261026
},
10271027
});
10281028

@@ -1044,7 +1044,7 @@ impl<O: OutputStream> Compiler<O> {
10441044
for keyword in keywords {
10451045
if let Some(name) = &keyword.name {
10461046
kwarg_names.push(bytecode::Constant::String {
1047-
value: name.to_string(),
1047+
value: name.to_owned(),
10481048
});
10491049
} else {
10501050
// This means **kwargs!
@@ -1308,7 +1308,7 @@ impl<O: OutputStream> Compiler<O> {
13081308
});
13091309
self.emit(Instruction::LoadConst {
13101310
value: bytecode::Constant::String {
1311-
value: name.to_string(),
1311+
value: name.to_owned(),
13121312
},
13131313
});
13141314
self.emit(Instruction::StoreSubscript);
@@ -1332,7 +1332,7 @@ impl<O: OutputStream> Compiler<O> {
13321332
ast::ExpressionType::Attribute { value, name } => {
13331333
self.compile_expression(value)?;
13341334
self.emit(Instruction::StoreAttr {
1335-
name: name.to_string(),
1335+
name: name.to_owned(),
13361336
});
13371337
}
13381338
ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => {
@@ -1605,7 +1605,7 @@ impl<O: OutputStream> Compiler<O> {
16051605
Attribute { value, name } => {
16061606
self.compile_expression(value)?;
16071607
self.emit(Instruction::LoadAttr {
1608-
name: name.to_string(),
1608+
name: name.to_owned(),
16091609
});
16101610
}
16111611
Compare { vals, ops } => {
@@ -1795,7 +1795,7 @@ impl<O: OutputStream> Compiler<O> {
17951795
if let Some(name) = &keyword.name {
17961796
self.emit(Instruction::LoadConst {
17971797
value: bytecode::Constant::String {
1798-
value: name.to_string(),
1798+
value: name.to_owned(),
17991799
},
18001800
});
18011801
self.compile_expression(&keyword.value)?;
@@ -1858,7 +1858,7 @@ impl<O: OutputStream> Compiler<O> {
18581858
for keyword in keywords {
18591859
if let Some(name) = &keyword.name {
18601860
kwarg_names.push(bytecode::Constant::String {
1861-
value: name.to_string(),
1861+
value: name.to_owned(),
18621862
});
18631863
} else {
18641864
// This means **kwargs!
@@ -1927,7 +1927,7 @@ impl<O: OutputStream> Compiler<O> {
19271927
ast::ComprehensionKind::Set { .. } => "<setcomp>",
19281928
ast::ComprehensionKind::Dict { .. } => "<dictcomp>",
19291929
}
1930-
.to_string();
1930+
.to_owned();
19311931

19321932
let line_number = self.get_source_line_number();
19331933
// Create magnificent function <listcomp>:
@@ -2099,7 +2099,7 @@ impl<O: OutputStream> Compiler<O> {
20992099
ast::StringGroup::Constant { value } => {
21002100
self.emit(Instruction::LoadConst {
21012101
value: bytecode::Constant::String {
2102-
value: value.to_string(),
2102+
value: value.to_owned(),
21032103
},
21042104
});
21052105
}
@@ -2266,7 +2266,7 @@ mod tests {
22662266
let mut compiler: Compiler = Default::default();
22672267
compiler.source_path = Some("source_path".to_owned());
22682268
compiler.push_new_code_object("<module>".to_owned());
2269-
let ast = parser::parse_program(&source.to_string()).unwrap();
2269+
let ast = parser::parse_program(source).unwrap();
22702270
let symbol_scope = make_symbol_table(&ast).unwrap();
22712271
compiler.compile_program(&ast, symbol_scope).unwrap();
22722272
compiler.pop_code_object()

compiler/src/symboltable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct Symbol {
105105
impl Symbol {
106106
fn new(name: &str) -> Self {
107107
Symbol {
108-
name: name.to_string(),
108+
name: name.to_owned(),
109109
// table,
110110
scope: SymbolScope::Unknown,
111111
is_param: false,
@@ -304,7 +304,7 @@ impl SymbolTableBuilder {
304304
}
305305

306306
fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) {
307-
let table = SymbolTable::new(name.to_string(), typ, line_number);
307+
let table = SymbolTable::new(name.to_owned(), typ, line_number);
308308
self.tables.push(table);
309309
}
310310

@@ -793,7 +793,7 @@ impl SymbolTableBuilder {
793793
// Insert symbol when required:
794794
if !containing {
795795
let symbol = Symbol::new(name);
796-
table.symbols.insert(name.to_string(), symbol);
796+
table.symbols.insert(name.to_owned(), symbol);
797797
}
798798

799799
// Set proper flags on symbol:

derive/src/compile_bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl CompilationSource {
128128
let module_name = if is_init {
129129
parent.clone()
130130
} else if parent.is_empty() {
131-
stem.to_string()
131+
stem.to_owned()
132132
} else {
133133
format!("{}.{}", parent, stem)
134134
};

derive/src/pyclass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ fn generate_class_def(
620620
let meta = attr.parse_meta().expect("expected doc attr to be a meta");
621621
if let Meta::NameValue(name_value) = meta {
622622
if let Lit::Str(s) = name_value.lit {
623-
let val = s.value().trim().to_string();
623+
let val = s.value().trim().to_owned();
624624
match doc {
625625
Some(ref mut doc) => doc.push(val),
626626
None => doc = Some(vec![val]),

parser/src/fstring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a> FStringParser<'a> {
8383
}))
8484
} else {
8585
spec = Some(Box::new(Constant {
86-
value: spec_expression.to_string(),
86+
value: spec_expression.to_owned(),
8787
}))
8888
}
8989
}

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> {
364364

365365
// Figure out if a -c option was given:
366366
if let Some(command) = matches.value_of("c") {
367-
run_command(&vm, scope, command.to_string())?;
367+
run_command(&vm, scope, command.to_owned())?;
368368
} else if let Some(module) = matches.value_of("m") {
369369
run_module(&vm, module)?;
370370
} else if let Some(filename) = matches.value_of("script") {
@@ -426,13 +426,13 @@ fn run_script(vm: &VirtualMachine, scope: Scope, script_file: &str) -> PyResult<
426426
process::exit(1);
427427
};
428428

429-
let dir = file_path.parent().unwrap().to_str().unwrap().to_string();
429+
let dir = file_path.parent().unwrap().to_str().unwrap().to_owned();
430430
let sys_path = vm.get_attribute(vm.sys_module.clone(), "path").unwrap();
431431
vm.call_method(&sys_path, "insert", vec![vm.new_int(0), vm.new_str(dir)])?;
432432

433433
match util::read_file(&file_path) {
434434
Ok(source) => {
435-
_run_string(vm, scope, &source, file_path.to_str().unwrap().to_string())?;
435+
_run_string(vm, scope, &source, file_path.to_str().unwrap().to_owned())?;
436436
}
437437
Err(err) => {
438438
error!(

vm/src/builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn builtin_compile(args: CompileArgs, vm: &VirtualMachine) -> PyResult {
146146
.parse::<compile::Mode>()
147147
.map_err(|err| vm.new_value_error(err.to_string()))?;
148148

149-
vm.compile(&source, mode, args.filename.as_str().to_string())
149+
vm.compile(&source, mode, args.filename.as_str().to_owned())
150150
.map(|o| o.into_object())
151151
.map_err(|err| vm.new_syntax_error(&err))
152152
}
@@ -920,7 +920,7 @@ pub fn builtin_build_class_(
920920
vm: &VirtualMachine,
921921
) -> PyResult {
922922
let name = qualified_name.as_str().split('.').next_back().unwrap();
923-
let name_obj = vm.new_str(name.to_string());
923+
let name_obj = vm.new_str(name.to_owned());
924924

925925
let mut metaclass = if let Some(metaclass) = kwargs.pop_kwarg("metaclass") {
926926
PyClassRef::try_from_object(vm, metaclass)?

vm/src/dictdatatype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl DictKey for &PyObjectRef {
344344
impl DictKey for &str {
345345
fn do_hash(self, _vm: &VirtualMachine) -> PyResult<HashValue> {
346346
// follow a similar route as the hashing of PyStringRef
347-
let raw_hash = pyhash::hash_value(&self.to_string()).to_bigint().unwrap();
347+
let raw_hash = pyhash::hash_value(&self.to_owned()).to_bigint().unwrap();
348348
let raw_hash = pyhash::hash_bigint(&raw_hash);
349349
let mut hasher = DefaultHasher::new();
350350
raw_hash.hash(&mut hasher);
@@ -362,7 +362,7 @@ impl DictKey for &str {
362362
Ok(py_str_value.as_str() == self)
363363
} else {
364364
// Fall back to PyString implementation.
365-
let s = vm.new_str(self.to_string());
365+
let s = vm.new_str(self.to_owned());
366366
s.do_eq(vm, other_key)
367367
}
368368
}
@@ -438,7 +438,7 @@ mod tests {
438438
fn check_hash_equivalence(text: &str) {
439439
let vm: VirtualMachine = Default::default();
440440
let value1 = text;
441-
let value2 = vm.new_str(value1.to_string());
441+
let value2 = vm.new_str(value1.to_owned());
442442

443443
let hash1 = value1.do_hash(&vm).expect("Hash should not fail.");
444444
let hash2 = value2.do_hash(&vm).expect("Hash should not fail.");

vm/src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::vm::VirtualMachine;
44
use rustpython_compiler::compile;
55

66
pub fn eval(vm: &VirtualMachine, source: &str, scope: Scope, source_path: &str) -> PyResult {
7-
match vm.compile(source, compile::Mode::Eval, source_path.to_string()) {
7+
match vm.compile(source, compile::Mode::Eval, source_path.to_owned()) {
88
Ok(bytecode) => {
99
debug!("Code object: {:?}", bytecode);
1010
vm.run_code_obj(bytecode, scope)

vm/src/exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn print_source_line<W: Write>(output: &mut W, filename: &str, lineno: usize) ->
225225

226226
/// Print exception occurrence location from traceback element
227227
fn write_traceback_entry<W: Write>(output: &mut W, tb_entry: &PyTracebackRef) -> io::Result<()> {
228-
let filename = tb_entry.frame.code.source_path.to_string();
228+
let filename = tb_entry.frame.code.source_path.to_owned();
229229
writeln!(
230230
output,
231231
r##" File "{}", line {}, in {}"##,

0 commit comments

Comments
 (0)