diff --git a/src/compile.rs b/src/compile.rs index 8ea3bc5..dbe938f 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -290,7 +290,7 @@ impl Compiler { fn load_name(&mut self, name: &str) { let scope = self.scope_for_name(name); self.emit(Instruction::LoadName { - name: name.to_string(), + name: name.to_owned(), scope, }); } @@ -298,7 +298,7 @@ impl Compiler { fn store_name(&mut self, name: &str) { let scope = self.scope_for_name(name); self.emit(Instruction::StoreName { - name: name.to_string(), + name: name.to_owned(), scope, }); } @@ -359,7 +359,7 @@ impl Compiler { for name in names { // import symbol from module: self.emit(Instruction::ImportFrom { - name: name.symbol.to_string(), + name: name.symbol.to_owned(), }); // Store module under proper name: @@ -619,13 +619,13 @@ impl Compiler { match &expression.node { ast::ExpressionType::Identifier { name } => { self.emit(Instruction::DeleteName { - name: name.to_string(), + name: name.to_owned(), }); } ast::ExpressionType::Attribute { value, name } => { self.compile_expression(value)?; self.emit(Instruction::DeleteAttr { - name: name.to_string(), + name: name.to_owned(), }); } ast::ExpressionType::Subscript { a, b } => { @@ -701,7 +701,7 @@ impl Compiler { compile_varargs(&args.kwarg), self.source_path.clone().unwrap(), line_number, - name.to_string(), + name.to_owned(), )); self.enter_scope(); @@ -909,7 +909,7 @@ impl Compiler { if let Some(annotation) = &arg.annotation { self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: arg.arg.to_string(), + value: arg.arg.to_owned(), }, }); self.compile_expression(&annotation)?; @@ -982,7 +982,7 @@ impl Compiler { Varargs::None, self.source_path.clone().unwrap(), line_number, - name.to_string(), + name.to_owned(), )); self.enter_scope(); @@ -1022,7 +1022,7 @@ impl Compiler { }); self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }, }); @@ -1044,7 +1044,7 @@ impl Compiler { for keyword in keywords { if let Some(name) = &keyword.name { kwarg_names.push(bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }); } else { // This means **kwargs! @@ -1308,7 +1308,7 @@ impl Compiler { }); self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }, }); self.emit(Instruction::StoreSubscript); @@ -1332,7 +1332,7 @@ impl Compiler { ast::ExpressionType::Attribute { value, name } => { self.compile_expression(value)?; self.emit(Instruction::StoreAttr { - name: name.to_string(), + name: name.to_owned(), }); } ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => { @@ -1605,7 +1605,7 @@ impl Compiler { Attribute { value, name } => { self.compile_expression(value)?; self.emit(Instruction::LoadAttr { - name: name.to_string(), + name: name.to_owned(), }); } Compare { vals, ops } => { @@ -1795,7 +1795,7 @@ impl Compiler { if let Some(name) = &keyword.name { self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }, }); self.compile_expression(&keyword.value)?; @@ -1858,7 +1858,7 @@ impl Compiler { for keyword in keywords { if let Some(name) = &keyword.name { kwarg_names.push(bytecode::Constant::String { - value: name.to_string(), + value: name.to_owned(), }); } else { // This means **kwargs! @@ -1927,7 +1927,7 @@ impl Compiler { ast::ComprehensionKind::Set { .. } => "", ast::ComprehensionKind::Dict { .. } => "", } - .to_string(); + .to_owned(); let line_number = self.get_source_line_number(); // Create magnificent function : @@ -2099,7 +2099,7 @@ impl Compiler { ast::StringGroup::Constant { value } => { self.emit(Instruction::LoadConst { value: bytecode::Constant::String { - value: value.to_string(), + value: value.to_owned(), }, }); } @@ -2266,7 +2266,7 @@ mod tests { let mut compiler: Compiler = Default::default(); 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 ast = parser::parse_program(source).unwrap(); let symbol_scope = make_symbol_table(&ast).unwrap(); compiler.compile_program(&ast, symbol_scope).unwrap(); compiler.pop_code_object() diff --git a/src/symboltable.rs b/src/symboltable.rs index c3e2099..d08aa4f 100644 --- a/src/symboltable.rs +++ b/src/symboltable.rs @@ -105,7 +105,7 @@ pub struct Symbol { impl Symbol { fn new(name: &str) -> Self { Symbol { - name: name.to_string(), + name: name.to_owned(), // table, scope: SymbolScope::Unknown, is_param: false, @@ -304,7 +304,7 @@ impl SymbolTableBuilder { } fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) { - let table = SymbolTable::new(name.to_string(), typ, line_number); + let table = SymbolTable::new(name.to_owned(), typ, line_number); self.tables.push(table); } @@ -793,7 +793,7 @@ impl SymbolTableBuilder { // Insert symbol when required: if !containing { let symbol = Symbol::new(name); - table.symbols.insert(name.to_string(), symbol); + table.symbols.insert(name.to_owned(), symbol); } // Set proper flags on symbol: