diff --git a/src/compile.rs b/src/compile.rs index d02d3d3..8ea3bc5 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -88,7 +88,7 @@ fn with_compiler( ) -> Result { let mut compiler = Compiler::new(optimize); compiler.source_path = Some(source_path); - compiler.push_new_code_object("".to_string()); + compiler.push_new_code_object("".to_owned()); f(&mut compiler)?; let code = compiler.pop_code_object(); trace!("Compilation completed: {:?}", code); @@ -897,7 +897,7 @@ impl Compiler { // key: self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: "return".to_string(), + value: "return".to_owned(), }, }); // value: @@ -989,11 +989,11 @@ impl Compiler { let (new_body, doc_str) = get_doc(body); self.emit(Instruction::LoadName { - name: "__name__".to_string(), + name: "__name__".to_owned(), scope: bytecode::NameScope::Global, }); self.emit(Instruction::StoreName { - name: "__module__".to_string(), + name: "__module__".to_owned(), scope: bytecode::NameScope::Free, }); self.emit(Instruction::LoadConst { @@ -1002,7 +1002,7 @@ impl Compiler { }, }); self.emit(Instruction::StoreName { - name: "__qualname__".to_string(), + name: "__qualname__".to_owned(), scope: bytecode::NameScope::Free, }); self.compile_statements(new_body)?; @@ -1090,7 +1090,7 @@ impl Compiler { self.emit(Instruction::Rotate { amount: 2 }); self.emit(Instruction::StoreAttr { - name: "__doc__".to_string(), + name: "__doc__".to_owned(), }); } @@ -1171,7 +1171,7 @@ impl Compiler { self.set_label(check_asynciter_label); self.emit(Instruction::Duplicate); self.emit(Instruction::LoadName { - name: "StopAsyncIteration".to_string(), + name: "StopAsyncIteration".to_owned(), scope: bytecode::NameScope::Global, }); self.emit(Instruction::CompareOperation { @@ -1732,7 +1732,7 @@ impl Compiler { func: FunctionContext::Function, }; - let name = "".to_string(); + let name = "".to_owned(); self.enter_function(&name, args)?; self.compile_expression(body)?; self.emit(Instruction::ReturnValue); @@ -1933,7 +1933,7 @@ impl Compiler { // Create magnificent function : self.push_output(CodeObject::new( Default::default(), - vec![".0".to_string()], + vec![".0".to_owned()], Varargs::None, vec![], Varargs::None, @@ -2264,8 +2264,8 @@ mod tests { fn compile_exec(source: &str) -> CodeObject { let mut compiler: Compiler = Default::default(); - compiler.source_path = Some("source_path".to_string()); - compiler.push_new_code_object("".to_string()); + 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 symbol_scope = make_symbol_table(&ast).unwrap(); compiler.compile_program(&ast, symbol_scope).unwrap(); diff --git a/src/error.rs b/src/error.rs index ae53a00..836e479 100644 --- a/src/error.rs +++ b/src/error.rs @@ -62,7 +62,7 @@ impl CompileError { match parse { ParseErrorType::Lexical(LexicalErrorType::IndentationError) => true, ParseErrorType::UnrecognizedToken(token, expected) => { - *token == Tok::Indent || expected.clone() == Some("Indent".to_string()) + *token == Tok::Indent || expected.clone() == Some("Indent".to_owned()) } _ => false, } @@ -88,14 +88,14 @@ impl fmt::Display for CompileError { let error_desc = match &self.error { CompileErrorType::Assign(target) => format!("can't assign to {}", target), CompileErrorType::Delete(target) => format!("can't delete {}", target), - CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_string(), + CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(), CompileErrorType::Parse(err) => err.to_string(), CompileErrorType::SyntaxError(err) => err.to_string(), - CompileErrorType::StarArgs => "Two starred expressions in assignment".to_string(), - CompileErrorType::InvalidBreak => "'break' outside loop".to_string(), - CompileErrorType::InvalidContinue => "'continue' outside loop".to_string(), - CompileErrorType::InvalidReturn => "'return' outside function".to_string(), - CompileErrorType::InvalidYield => "'yield' outside function".to_string(), + CompileErrorType::StarArgs => "Two starred expressions in assignment".to_owned(), + CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(), + CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(), + CompileErrorType::InvalidReturn => "'return' outside function".to_owned(), + CompileErrorType::InvalidYield => "'yield' outside function".to_owned(), }; if let Some(statement) = &self.statement {