Skip to content

Commit 78180ff

Browse files
authored
Merge pull request RustPython#1734 from youknowone/to-owned
str::to_string -> str::to_owned
2 parents c435ba0 + 7d0d313 commit 78180ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+549
-561
lines changed

benchmarks/bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn bench_rustpy_nbody(b: &mut test::Bencher) {
9494

9595
let vm = VirtualMachine::default();
9696

97-
let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_string()) {
97+
let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_owned()) {
9898
Ok(code) => code,
9999
Err(e) => panic!("{:?}", e),
100100
};
@@ -113,7 +113,7 @@ fn bench_rustpy_mandelbrot(b: &mut test::Bencher) {
113113

114114
let vm = VirtualMachine::default();
115115

116-
let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_string()) {
116+
let code = match vm.compile(source, compile::Mode::Single, "<stdin>".to_owned()) {
117117
Ok(code) => code,
118118
Err(e) => panic!("{:?}", e),
119119
};

compiler/src/compile.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn with_compiler(
8888
) -> Result<CodeObject, CompileError> {
8989
let mut compiler = Compiler::new(optimize);
9090
compiler.source_path = Some(source_path);
91-
compiler.push_new_code_object("<module>".to_string());
91+
compiler.push_new_code_object("<module>".to_owned());
9292
f(&mut compiler)?;
9393
let code = compiler.pop_code_object();
9494
trace!("Compilation completed: {:?}", code);
@@ -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

@@ -897,7 +897,7 @@ impl<O: OutputStream> Compiler<O> {
897897
// key:
898898
self.emit(Instruction::LoadConst {
899899
value: bytecode::Constant::String {
900-
value: "return".to_string(),
900+
value: "return".to_owned(),
901901
},
902902
});
903903
// value:
@@ -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,18 +982,18 @@ 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

989989
let (new_body, doc_str) = get_doc(body);
990990

991991
self.emit(Instruction::LoadName {
992-
name: "__name__".to_string(),
992+
name: "__name__".to_owned(),
993993
scope: bytecode::NameScope::Global,
994994
});
995995
self.emit(Instruction::StoreName {
996-
name: "__module__".to_string(),
996+
name: "__module__".to_owned(),
997997
scope: bytecode::NameScope::Free,
998998
});
999999
self.emit(Instruction::LoadConst {
@@ -1002,7 +1002,7 @@ impl<O: OutputStream> Compiler<O> {
10021002
},
10031003
});
10041004
self.emit(Instruction::StoreName {
1005-
name: "__qualname__".to_string(),
1005+
name: "__qualname__".to_owned(),
10061006
scope: bytecode::NameScope::Free,
10071007
});
10081008
self.compile_statements(new_body)?;
@@ -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!
@@ -1090,7 +1090,7 @@ impl<O: OutputStream> Compiler<O> {
10901090

10911091
self.emit(Instruction::Rotate { amount: 2 });
10921092
self.emit(Instruction::StoreAttr {
1093-
name: "__doc__".to_string(),
1093+
name: "__doc__".to_owned(),
10941094
});
10951095
}
10961096

@@ -1171,7 +1171,7 @@ impl<O: OutputStream> Compiler<O> {
11711171
self.set_label(check_asynciter_label);
11721172
self.emit(Instruction::Duplicate);
11731173
self.emit(Instruction::LoadName {
1174-
name: "StopAsyncIteration".to_string(),
1174+
name: "StopAsyncIteration".to_owned(),
11751175
scope: bytecode::NameScope::Global,
11761176
});
11771177
self.emit(Instruction::CompareOperation {
@@ -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 } => {
@@ -1732,7 +1732,7 @@ impl<O: OutputStream> Compiler<O> {
17321732
func: FunctionContext::Function,
17331733
};
17341734

1735-
let name = "<lambda>".to_string();
1735+
let name = "<lambda>".to_owned();
17361736
self.enter_function(&name, args)?;
17371737
self.compile_expression(body)?;
17381738
self.emit(Instruction::ReturnValue);
@@ -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,13 +1927,13 @@ 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>:
19341934
self.push_output(CodeObject::new(
19351935
Default::default(),
1936-
vec![".0".to_string()],
1936+
vec![".0".to_owned()],
19371937
Varargs::None,
19381938
vec![],
19391939
Varargs::None,
@@ -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
}
@@ -2264,9 +2264,9 @@ mod tests {
22642264

22652265
fn compile_exec(source: &str) -> CodeObject {
22662266
let mut compiler: Compiler = Default::default();
2267-
compiler.source_path = Some("source_path".to_string());
2268-
compiler.push_new_code_object("<module>".to_string());
2269-
let ast = parser::parse_program(&source.to_string()).unwrap();
2267+
compiler.source_path = Some("source_path".to_owned());
2268+
compiler.push_new_code_object("<module>".to_owned());
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/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl CompileError {
6262
match parse {
6363
ParseErrorType::Lexical(LexicalErrorType::IndentationError) => true,
6464
ParseErrorType::UnrecognizedToken(token, expected) => {
65-
*token == Tok::Indent || expected.clone() == Some("Indent".to_string())
65+
*token == Tok::Indent || expected.clone() == Some("Indent".to_owned())
6666
}
6767
_ => false,
6868
}
@@ -88,14 +88,14 @@ impl fmt::Display for CompileError {
8888
let error_desc = match &self.error {
8989
CompileErrorType::Assign(target) => format!("can't assign to {}", target),
9090
CompileErrorType::Delete(target) => format!("can't delete {}", target),
91-
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_string(),
91+
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(),
9292
CompileErrorType::Parse(err) => err.to_string(),
9393
CompileErrorType::SyntaxError(err) => err.to_string(),
94-
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_string(),
95-
CompileErrorType::InvalidBreak => "'break' outside loop".to_string(),
96-
CompileErrorType::InvalidContinue => "'continue' outside loop".to_string(),
97-
CompileErrorType::InvalidReturn => "'return' outside function".to_string(),
98-
CompileErrorType::InvalidYield => "'yield' outside function".to_string(),
94+
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_owned(),
95+
CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(),
96+
CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(),
97+
CompileErrorType::InvalidReturn => "'return' outside function".to_owned(),
98+
CompileErrorType::InvalidYield => "'yield' outside function".to_owned(),
9999
};
100100

101101
if let Some(statement) = &self.statement {

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: 2 additions & 2 deletions
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
};
@@ -235,7 +235,7 @@ impl PyCompileInput {
235235
})?
236236
.compile(
237237
mode.unwrap_or(compile::Mode::Exec),
238-
module_name.unwrap_or_else(|| "frozen".to_string()),
238+
module_name.unwrap_or_else(|| "frozen".to_owned()),
239239
)
240240
}
241241
}

derive/src/pyclass.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl Class {
224224
} else {
225225
Err(Diagnostic::span_error(
226226
span,
227-
"Duplicate #[py*] attribute on pyimpl".to_string(),
227+
"Duplicate #[py*] attribute on pyimpl".to_owned(),
228228
))
229229
}
230230
}
@@ -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]),

examples/hello_embed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() -> vm::pyobject::PyResult<()> {
1010
.compile(
1111
r#"print("Hello World!")"#,
1212
compiler::compile::Mode::Exec,
13-
"<embedded>".to_string(),
13+
"<embedded>".to_owned(),
1414
)
1515
.map_err(|err| vm.new_syntax_error(&err))?;
1616

examples/mini_repl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() -> vm::pyobject::PyResult<()> {
9696
.compile(
9797
&input,
9898
compiler::compile::Mode::Single,
99-
"<embedded>".to_string(),
99+
"<embedded>".to_owned(),
100100
)
101101
.map_err(|err| vm.new_syntax_error(&err))
102102
.and_then(|code_obj| vm.run_code_obj(code_obj, scope.clone()))

examples/parse_folder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn parse_python_file(filename: &Path) -> ParsedFile {
7878
match std::fs::read_to_string(filename) {
7979
Err(e) => ParsedFile {
8080
// filename: Box::new(filename.to_path_buf()),
81-
// code: "".to_string(),
81+
// code: "".to_owned(),
8282
num_lines: 0,
8383
result: Err(e.to_string()),
8484
},

parser/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl fmt::Display for ParseErrorType {
191191
ParseErrorType::UnrecognizedToken(ref tok, ref expected) => {
192192
if *tok == Tok::Indent {
193193
write!(f, "unexpected indent")
194-
} else if expected.clone() == Some("Indent".to_string()) {
194+
} else if expected.clone() == Some("Indent".to_owned()) {
195195
write!(f, "expected an indented block")
196196
} else {
197197
write!(f, "Got unexpected token {}", tok)

0 commit comments

Comments
 (0)