Skip to content

Commit ad6f0e6

Browse files
committed
&str::to_string -> &str::to_owned
1 parent 7cdaba7 commit ad6f0e6

Some content is hidden

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

75 files changed

+426
-433
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
);

parser/src/lexer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ where
303303
if self.chr0 == Some('.') {
304304
if self.chr1 == Some('_') {
305305
return Err(LexicalError {
306-
error: LexicalErrorType::OtherError("Invalid Syntax".to_string()),
306+
error: LexicalErrorType::OtherError("Invalid Syntax".to_owned()),
307307
location: self.get_pos(),
308308
});
309309
}
@@ -352,7 +352,7 @@ where
352352
let value = value_text.parse::<BigInt>().unwrap();
353353
if start_is_zero && !value.is_zero() {
354354
return Err(LexicalError {
355-
error: LexicalErrorType::OtherError("Invalid Token".to_string()),
355+
error: LexicalErrorType::OtherError("Invalid Token".to_owned()),
356356
location: self.get_pos(),
357357
});
358358
}
@@ -643,7 +643,7 @@ where
643643
// This is technically stricter than python3 but spaces after
644644
// tabs is even more insane than mixing spaces and tabs.
645645
return Some(Err(LexicalError {
646-
error: LexicalErrorType::OtherError("Spaces not allowed as part of indentation after tabs".to_string()),
646+
error: LexicalErrorType::OtherError("Spaces not allowed as part of indentation after tabs".to_owned()),
647647
location: self.get_pos(),
648648
}));
649649
}
@@ -658,7 +658,7 @@ where
658658
// tabs is even more insane than mixing spaces and tabs.
659659
return Err(LexicalError {
660660
error: LexicalErrorType::OtherError(
661-
"Tabs not allowed as part of indentation after spaces".to_string(),
661+
"Tabs not allowed as part of indentation after spaces".to_owned(),
662662
),
663663
location: self.get_pos(),
664664
});
@@ -1313,11 +1313,11 @@ mod tests {
13131313
tokens,
13141314
vec![
13151315
Tok::String {
1316-
value: "\\\\".to_string(),
1316+
value: "\\\\".to_owned(),
13171317
is_fstring: false,
13181318
},
13191319
Tok::String {
1320-
value: "\\".to_string(),
1320+
value: "\\".to_owned(),
13211321
is_fstring: false,
13221322
},
13231323
Tok::Newline,

parser/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mod tests {
213213
function: Box::new(mk_ident("my_func", 1, 1)),
214214
args: vec![make_string("positional", 1, 10)],
215215
keywords: vec![ast::Keyword {
216-
name: Some("keyword".to_string()),
216+
name: Some("keyword".to_owned()),
217217
value: make_int(2, 1, 31),
218218
}],
219219
}

parser/src/python.lalrpop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ ImportAsNames: Vec<ast::ImportSymbol> = {
251251
"(" <i:OneOrMore<ImportAsAlias<Identifier>>> ","? ")" => i,
252252
"*" => {
253253
// Star import all
254-
vec![ast::ImportSymbol { symbol: "*".to_string(), alias: None }]
254+
vec![ast::ImportSymbol { symbol: "*".to_owned(), alias: None }]
255255
},
256256
};
257257

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn _run_string(vm: &VirtualMachine, scope: Scope, source: &str, source_path: Str
389389

390390
fn run_command(vm: &VirtualMachine, scope: Scope, source: String) -> PyResult<()> {
391391
debug!("Running command {}", source);
392-
_run_string(vm, scope, &source, "<stdin>".to_string())?;
392+
_run_string(vm, scope, &source, "<stdin>".to_owned())?;
393393
Ok(())
394394
}
395395

src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum ShellExecResult {
2121
}
2222

2323
fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResult {
24-
match vm.compile(source, compile::Mode::Single, "<stdin>".to_string()) {
24+
match vm.compile(source, compile::Mode::Single, "<stdin>".to_owned()) {
2525
Ok(code) => {
2626
match vm.run_code_obj(code, scope.clone()) {
2727
Ok(value) => {

src/shell/rustyline_helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Completer for ShellHelper<'_> {
159159
.complete_opt(&line[0..pos])
160160
// as far as I can tell, there's no better way to do both completion
161161
// and indentation (or even just indentation)
162-
.unwrap_or_else(|| (line.len(), vec!["\t".to_string()])))
162+
.unwrap_or_else(|| (line.len(), vec!["\t".to_owned()])))
163163
}
164164
}
165165

vm/src/builtins.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn builtin_callable(obj: PyObjectRef, vm: &VirtualMachine) -> bool {
105105
fn builtin_chr(i: u32, vm: &VirtualMachine) -> PyResult<String> {
106106
match char::from_u32(i) {
107107
Some(value) => Ok(value.to_string()),
108-
None => Err(vm.new_value_error("chr() arg not in range(0x110000)".to_string())),
108+
None => Err(vm.new_value_error("chr() arg not in range(0x110000)".to_owned())),
109109
}
110110
}
111111

@@ -229,7 +229,7 @@ fn run_code(
229229
// Determine code object:
230230
let code_obj = match source {
231231
Either::A(string) => vm
232-
.compile(string.as_str(), mode, "<string>".to_string())
232+
.compile(string.as_str(), mode, "<string>".to_owned())
233233
.map_err(|err| vm.new_syntax_error(&err))?,
234234
Either::B(code_obj) => code_obj,
235235
};
@@ -400,14 +400,14 @@ fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
400400
std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?,
401401
std::cmp::Ordering::Less => {
402402
// zero arguments means type error:
403-
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
403+
return Err(vm.new_type_error("Expected 1 or more arguments".to_owned()));
404404
}
405405
};
406406

407407
if candidates.is_empty() {
408408
let default = args.get_optional_kwarg("default");
409409
return default
410-
.ok_or_else(|| vm.new_value_error("max() arg is an empty sequence".to_string()));
410+
.ok_or_else(|| vm.new_value_error("max() arg is an empty sequence".to_owned()));
411411
}
412412

413413
let key_func = args.get_optional_kwarg("key");
@@ -446,14 +446,14 @@ fn builtin_min(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
446446
std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?,
447447
std::cmp::Ordering::Less => {
448448
// zero arguments means type error:
449-
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
449+
return Err(vm.new_type_error("Expected 1 or more arguments".to_owned()));
450450
}
451451
};
452452

453453
if candidates.is_empty() {
454454
let default = args.get_optional_kwarg("default");
455455
return default
456-
.ok_or_else(|| vm.new_value_error("min() arg is an empty sequence".to_string()));
456+
.ok_or_else(|| vm.new_value_error("min() arg is an empty sequence".to_owned()));
457457
}
458458

459459
let key_func = args.get_optional_kwarg("key");
@@ -540,7 +540,7 @@ fn builtin_ord(string: Either<PyByteInner, PyStringRef>, vm: &VirtualMachine) ->
540540
match string.chars().next() {
541541
Some(character) => Ok(character as u32),
542542
None => Err(vm.new_type_error(
543-
"ord() could not guess the integer representing this character".to_string(),
543+
"ord() could not guess the integer representing this character".to_owned(),
544544
)),
545545
}
546546
}
@@ -565,18 +565,18 @@ fn builtin_pow(
565565
&& objtype::isinstance(&y, &vm.ctx.int_type()))
566566
{
567567
return Err(vm.new_type_error(
568-
"pow() 3rd argument not allowed unless all arguments are integers".to_string(),
568+
"pow() 3rd argument not allowed unless all arguments are integers".to_owned(),
569569
));
570570
}
571571
let y = objint::get_value(&y);
572572
if y.sign() == Sign::Minus {
573573
return Err(vm.new_value_error(
574-
"pow() 2nd argument cannot be negative when 3rd argument specified".to_string(),
574+
"pow() 2nd argument cannot be negative when 3rd argument specified".to_owned(),
575575
));
576576
}
577577
let m = m.as_bigint();
578578
if m.is_zero() {
579-
return Err(vm.new_value_error("pow() 3rd argument cannot be 0".to_string()));
579+
return Err(vm.new_value_error("pow() 3rd argument cannot be 0".to_owned()));
580580
}
581581
let x = objint::get_value(&x);
582582
Ok(vm.new_int(x.modpow(&y, &m)))
@@ -675,7 +675,7 @@ fn builtin_reversed(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
675675
vm.invoke(&reversed_method?, PyFuncArgs::default())
676676
} else {
677677
vm.get_method_or_type_error(obj.clone(), "__getitem__", || {
678-
"argument to reversed() must be a sequence".to_string()
678+
"argument to reversed() must be a sequence".to_owned()
679679
})?;
680680
let len = vm.call_method(&obj.clone(), "__len__", PyFuncArgs::default())?;
681681
let obj_iterator = objiter::PySequenceIterator {

0 commit comments

Comments
 (0)