Skip to content

Commit 1bac582

Browse files
committed
&str::to_string -> &str::to_owned for literals
1 parent c435ba0 commit 1bac582

Some content is hidden

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

73 files changed

+424
-431
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: 11 additions & 11 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);
@@ -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:
@@ -989,11 +989,11 @@ impl<O: OutputStream> Compiler<O> {
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)?;
@@ -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 {
@@ -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);
@@ -1933,7 +1933,7 @@ impl<O: OutputStream> Compiler<O> {
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,
@@ -2264,8 +2264,8 @@ 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());
2267+
compiler.source_path = Some("source_path".to_owned());
2268+
compiler.push_new_code_object("<module>".to_owned());
22692269
let ast = parser::parse_program(&source.to_string()).unwrap();
22702270
let symbol_scope = make_symbol_table(&ast).unwrap();
22712271
compiler.compile_program(&ast, symbol_scope).unwrap();

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 {

derive/src/compile_bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
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
}

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)

parser/src/fstring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ mod tests {
274274
value: Box::new(mk_ident("foo", 1, 1)),
275275
conversion: None,
276276
spec: Some(Box::new(Constant {
277-
value: "spec".to_string(),
277+
value: "spec".to_owned(),
278278
})),
279279
}
280280
);

0 commit comments

Comments
 (0)