@@ -289,7 +289,7 @@ pub fn compile_program(
289289) -> CompileResult<CodeObject> {
290290 let symbol_table = SymbolTable::scan_program(ast, source_file.clone())
291291 .map_err(|e| e.into_codegen_error(source_file.name().to_owned()))?;
292- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
292+ let mut compiler = Compiler::new(opts, source_file, "<module>");
293293 compiler.compile_program(ast, symbol_table)?;
294294 let code = compiler.exit_scope();
295295 trace!("Compilation completed: {code:?}");
@@ -304,7 +304,7 @@ pub fn compile_program_single(
304304) -> CompileResult<CodeObject> {
305305 let symbol_table = SymbolTable::scan_program(ast, source_file.clone())
306306 .map_err(|e| e.into_codegen_error(source_file.name().to_owned()))?;
307- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
307+ let mut compiler = Compiler::new(opts, source_file, "<module>");
308308 compiler.compile_program_single(&ast.body, symbol_table)?;
309309 let code = compiler.exit_scope();
310310 trace!("Compilation completed: {code:?}");
@@ -318,7 +318,7 @@ pub fn compile_block_expression(
318318) -> CompileResult<CodeObject> {
319319 let symbol_table = SymbolTable::scan_program(ast, source_file.clone())
320320 .map_err(|e| e.into_codegen_error(source_file.name().to_owned()))?;
321- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
321+ let mut compiler = Compiler::new(opts, source_file, "<module>");
322322 compiler.compile_block_expr(&ast.body, symbol_table)?;
323323 let code = compiler.exit_scope();
324324 trace!("Compilation completed: {code:?}");
@@ -332,7 +332,7 @@ pub fn compile_expression(
332332) -> CompileResult<CodeObject> {
333333 let symbol_table = SymbolTable::scan_expr(ast, source_file.clone())
334334 .map_err(|e| e.into_codegen_error(source_file.name().to_owned()))?;
335- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
335+ let mut compiler = Compiler::new(opts, source_file, "<module>");
336336 compiler.compile_eval(ast, symbol_table)?;
337337 let code = compiler.exit_scope();
338338 Ok(code)
@@ -447,13 +447,14 @@ impl PatternContext {
447447 }
448448}
449449
450+ #[derive(Clone, Copy, Eq, PartialEq)]
450451enum JumpOp {
451452 Jump,
452453 PopJumpIfFalse,
453454}
454455
455456/// Type of collection to build in starunpack_helper
456- #[derive(Debug, Clone, Copy, PartialEq)]
457+ #[derive(Clone, Copy, Debug, Eq , PartialEq)]
457458enum CollectionType {
458459 Tuple,
459460 List,
@@ -541,7 +542,7 @@ impl Compiler {
541542 }
542543 }
543544
544- fn new(opts: CompileOpts, source_file: SourceFile, code_name: String ) -> Self {
545+ fn new(opts: CompileOpts, source_file: SourceFile, code_name: &str ) -> Self {
545546 let module_code = ir::CodeInfo {
546547 // CPython convention: top-level module / interactive /
547548 // expression code does not carry CO_NEWLOCALS or CO_OPTIMIZED.
@@ -558,8 +559,8 @@ impl Compiler {
558559 current_block: BlockIdx::new(0),
559560 annotations_blocks: None,
560561 metadata: ir::CodeUnitMetadata {
561- name: code_name.clone (),
562- qualname: Some(code_name),
562+ name: code_name.to_string (),
563+ qualname: Some(code_name.to_string() ),
563564 consts: IndexSet::default(),
564565 names: IndexSet::default(),
565566 varnames: IndexSet::default(),
@@ -1287,8 +1288,7 @@ impl Compiler {
12871288 let name = current_table.name.clone();
12881289 let typ = current_table.typ;
12891290 return Err(self.error(CodegenErrorType::SyntaxError(format!(
1290- "no symbol table available in {} (type: {:?})",
1291- name, typ
1291+ "no symbol table available in {name} (type: {typ:?})"
12921292 ))));
12931293 }
12941294
@@ -1829,7 +1829,7 @@ impl Compiler {
18291829 posonlyarg_count: u32,
18301830 arg_count: u32,
18311831 kwonlyarg_count: u32,
1832- obj_name: String ,
1832+ obj_name: &str ,
18331833 ) -> CompileResult<()> {
18341834 // First push the symbol table
18351835 let table = self.push_symbol_table()?;
@@ -1842,7 +1842,7 @@ impl Compiler {
18421842 let lineno = self.get_source_line_number().get();
18431843
18441844 // Call enter_scope which does most of the work
1845- self.enter_scope(& obj_name, scope_type, key, lineno.to_u32())?;
1845+ self.enter_scope(obj_name, scope_type, key, lineno.to_u32())?;
18461846
18471847 // Override the values that push_output sets explicitly
18481848 // enter_scope sets default values based on scope_type, but push_output
@@ -3400,7 +3400,7 @@ impl Compiler {
34003400 parameters.posonlyargs.len().to_u32(),
34013401 (parameters.posonlyargs.len() + parameters.args.len()).to_u32(),
34023402 parameters.kwonlyargs.len().to_u32(),
3403- name.to_owned() ,
3403+ name,
34043404 )?;
34053405
34063406 let args_iter = core::iter::empty()
@@ -5258,7 +5258,7 @@ impl Compiler {
52585258 0,
52595259 num_typeparam_args as u32,
52605260 0,
5261- type_params_name,
5261+ & type_params_name,
52625262 )?;
52635263
52645264 // TypeParams scope is function-like
@@ -5820,7 +5820,7 @@ impl Compiler {
58205820 0,
58215821 0,
58225822 0,
5823- type_params_name,
5823+ & type_params_name,
58245824 )?;
58255825
58265826 // Set private name for name mangling
@@ -7956,21 +7956,20 @@ impl Compiler {
79567956 if let ast::Expr::Starred(_) = &element {
79577957 if seen_star {
79587958 return Err(self.error(CodegenErrorType::MultipleStarArgs));
7959- } else {
7960- seen_star = true;
7961- let before = i ;
7962- let after = elts.len() - i - 1 ;
7963- let (before, after) = (|| Some((before.to_u8()?, after.to_u8()?)))(
7964- )
7959+ }
7960+
7961+ seen_star = true ;
7962+ let before = i ;
7963+ let after = elts.len() - i - 1;
7964+ let (before, after) = (|| Some((before.to_u8()?, after.to_u8()?)))( )
79657965 .ok_or_else(|| {
79667966 self.error_ranged(
79677967 CodegenErrorType::TooManyStarUnpack,
79687968 target.range(),
79697969 )
79707970 })?;
7971- let counts = bytecode::UnpackExArgs { before, after };
7972- emit!(self, Instruction::UnpackEx { counts });
7973- }
7971+ let counts = bytecode::UnpackExArgs { before, after };
7972+ emit!(self, Instruction::UnpackEx { counts });
79747973 }
79757974 }
79767975
@@ -9696,8 +9695,7 @@ impl Compiler {
96969695 let name = current_table.name.clone();
96979696 let typ = current_table.typ;
96989697 Err(self.error(CodegenErrorType::SyntaxError(format!(
9699- "no symbol table available in {} (type: {:?})",
9700- name, typ
9698+ "no symbol table available in {name} (type: {typ:?})"
97019699 ))))
97029700 }
97039701 })();
@@ -9715,14 +9713,14 @@ impl Compiler {
97159713 posonlyarg_count: u32,
97169714 arg_count: u32,
97179715 kwonlyarg_count: u32,
9718- obj_name: String ,
9716+ obj_name: &str ,
97199717 ) -> CompileResult<()> {
97209718 let scope_type = table.typ;
97219719 self.symbol_table_stack.push(table);
97229720
97239721 let key = self.symbol_table_stack.len() - 1;
97249722 let lineno = self.get_source_line_number().get();
9725- self.enter_scope(& obj_name, scope_type, key, lineno.to_u32())?;
9723+ self.enter_scope(obj_name, scope_type, key, lineno.to_u32())?;
97269724
97279725 if let Some(info) = self.code_stack.last_mut() {
97289726 info.flags = flags | (info.flags & bytecode::CodeFlags::NESTED);
@@ -9786,7 +9784,7 @@ impl Compiler {
97869784 // and relies on the inlined path itself to handle GET_AITER /
97879785 // async-comprehension cleanup.
97889786 return self.compile_inlined_comprehension(
9789- comp_table,
9787+ & comp_table,
97909788 init_collection,
97919789 generators,
97929790 compile_element,
@@ -9821,7 +9819,7 @@ impl Compiler {
98219819 // scope itself. Peek past those nested scopes so we can enter the
98229820 // correct comprehension table here, then let the real outermost
98239821 // iterator compile consume its nested scopes later in parent scope.
9824- self.push_output_with_symbol_table(comp_table, flags, 1, 1, 0, name.to_owned() )?;
9822+ self.push_output_with_symbol_table(comp_table, flags, 1, 1, 0, name)?;
98259823
98269824 // Set qualname for comprehension
98279825 self.set_qualname();
@@ -10028,7 +10026,7 @@ impl Compiler {
1002810026 /// This generates bytecode inline without creating a new code object
1002910027 fn compile_inlined_comprehension(
1003010028 &mut self,
10031- comp_table: SymbolTable,
10029+ comp_table: & SymbolTable,
1003210030 init_collection: Option<AnyInstruction>,
1003310031 generators: &[ast::Comprehension],
1003410032 compile_element: &dyn Fn(&mut Self, usize) -> CompileResult<()>,
@@ -12380,7 +12378,7 @@ mod tests {
1238012378 let symbol_table = SymbolTable::scan_program(&ast, source_file.clone())
1238112379 .map_err(|e| e.into_codegen_error(source_file.name().to_owned()))
1238212380 .unwrap();
12383- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
12381+ let mut compiler = Compiler::new(opts, source_file, "<module>");
1238412382 compiler.compile_program(&ast, symbol_table).unwrap();
1238512383 compiler.exit_scope()
1238612384 }
@@ -12418,7 +12416,7 @@ mod tests {
1241812416 let symbol_table = SymbolTable::scan_program(&ast, source_file.clone())
1241912417 .map_err(|e| e.into_codegen_error(source_file.name().to_owned()))
1242012418 .unwrap();
12421- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
12419+ let mut compiler = Compiler::new(opts, source_file, "<module>");
1242212420 compiler.compile_program(&ast, symbol_table).unwrap();
1242312421 let _table = compiler.pop_symbol_table();
1242412422 let stack_top = compiler.code_stack.pop().unwrap();
@@ -12459,7 +12457,7 @@ mod tests {
1245912457 let is_async = function.is_async;
1246012458 let range = function.range();
1246112459
12462- let mut compiler = Compiler::new(opts, source_file, "<module>".to_owned() );
12460+ let mut compiler = Compiler::new(opts, source_file, "<module>");
1246312461 compiler.future_annotations = symbol_table.future_annotations;
1246412462 compiler.symbol_table_stack.push(symbol_table);
1246512463 compiler.set_source_range(range);
0 commit comments