@@ -41,8 +41,8 @@ use rustpython_compiler_core::{
4141} ;
4242use rustpython_compiler_source:: SourceCode ;
4343// use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
44- use std:: borrow:: Cow ;
4544use crate :: error:: InternalError ;
45+ use std:: borrow:: Cow ;
4646
4747pub ( crate ) type InternalResult < T > = Result < T , InternalError > ;
4848type CompileResult < T > = Result < T , CodegenError > ;
@@ -213,27 +213,38 @@ macro_rules! emit {
213213}
214214
215215fn eprint_location ( zelf : & Compiler < ' _ > ) {
216- let start = zelf. source_code . source_location ( zelf. current_source_range . start ( ) ) ;
217- let end = zelf. source_code . source_location ( zelf. current_source_range . end ( ) ) ;
218- eprintln ! ( "LOCATION: {} from {}:{} to {}:{}" , zelf. source_code. path. to_owned( ) , start. row, start. column, end. row, end. column) ;
216+ let start = zelf
217+ . source_code
218+ . source_location ( zelf. current_source_range . start ( ) ) ;
219+ let end = zelf
220+ . source_code
221+ . source_location ( zelf. current_source_range . end ( ) ) ;
222+ eprintln ! (
223+ "LOCATION: {} from {}:{} to {}:{}" ,
224+ zelf. source_code. path. to_owned( ) ,
225+ start. row,
226+ start. column,
227+ end. row,
228+ end. column
229+ ) ;
219230}
220231
221232/// Better traceback for internal error
222233fn unwrap_internal < T > ( zelf : & Compiler < ' _ > , r : InternalResult < T > ) -> T {
223234 if let Err ( ref r_err) = r {
224235 eprintln ! ( "=== CODEGEN PANIC INFO ===" ) ;
225236 eprintln ! ( "This IS an internal error: {}" , r_err) ;
226- print_location ( zelf) ;
237+ eprint_location ( zelf) ;
227238 eprintln ! ( "=== END PANIC INFO ===" ) ;
228239 }
229240 r. unwrap ( )
230241}
231242
232243fn compiler_unwrap_option < T > ( zelf : & Compiler < ' _ > , o : Option < T > ) -> T {
233- if let None = o {
244+ if o . is_none ( ) {
234245 eprintln ! ( "=== CODEGEN PANIC INFO ===" ) ;
235246 eprintln ! ( "This IS an internal error, an option was unwrapped during codegen" ) ;
236- print_location ( zelf) ;
247+ eprint_location ( zelf) ;
237248 eprintln ! ( "=== END PANIC INFO ===" ) ;
238249 }
239250 o. unwrap ( )
@@ -243,7 +254,7 @@ fn compiler_unwrap_option<T>(zelf: &Compiler<'_>, o: Option<T>) -> T {
243254// if result.is_err() {
244255// eprintln!("=== CODEGEN PANIC INFO ===");
245256// eprintln!("This IS an internal error, an result was unwrapped during codegen");
246- // print_location (zelf);
257+ // eprint_location (zelf);
247258// eprintln!("=== END PANIC INFO ===");
248259// }
249260// result.unwrap()
@@ -579,9 +590,12 @@ impl Compiler<'_> {
579590 self . check_forbidden_name ( & name, usage) ?;
580591
581592 let symbol_table = self . symbol_table_stack . last ( ) . unwrap ( ) ;
582- let symbol = unwrap_internal ( self , symbol_table. lookup ( name. as_ref ( ) ) . ok_or_else ( ||
583- InternalError :: MissingSymbol ( name. to_string ( ) )
584- ) ) ;
593+ let symbol = unwrap_internal (
594+ self ,
595+ symbol_table
596+ . lookup ( name. as_ref ( ) )
597+ . ok_or_else ( || InternalError :: MissingSymbol ( name. to_string ( ) ) ) ,
598+ ) ;
585599 let info = self . code_stack . last_mut ( ) . unwrap ( ) ;
586600 let mut cache = & mut info. name_cache ;
587601 enum NameOpType {
@@ -1515,9 +1529,12 @@ impl Compiler<'_> {
15151529 }
15161530 for var in & * code. freevars {
15171531 let table = self . symbol_table_stack . last ( ) . unwrap ( ) ;
1518- let symbol = unwrap_internal ( self , table. lookup ( var) . ok_or_else ( || {
1519- InternalError :: MissingSymbol ( var. to_owned ( ) )
1520- } ) ) ;
1532+ let symbol = unwrap_internal (
1533+ self ,
1534+ table
1535+ . lookup ( var)
1536+ . ok_or_else ( || InternalError :: MissingSymbol ( var. to_owned ( ) ) ) ,
1537+ ) ;
15211538 let parent_code = self . code_stack . last ( ) . unwrap ( ) ;
15221539 let vars = match symbol. scope {
15231540 SymbolScope :: Free => & parent_code. freevar_cache ,
@@ -1600,7 +1617,12 @@ impl Compiler<'_> {
16001617
16011618 // Check if the class is declared global
16021619 let symbol_table = self . symbol_table_stack . last ( ) . unwrap ( ) ;
1603- let symbol = unwrap_internal ( self , symbol_table. lookup ( name. as_ref ( ) ) . ok_or_else ( || InternalError :: MissingSymbol ( name. to_owned ( ) ) ) ) ;
1620+ let symbol = unwrap_internal (
1621+ self ,
1622+ symbol_table
1623+ . lookup ( name. as_ref ( ) )
1624+ . ok_or_else ( || InternalError :: MissingSymbol ( name. to_owned ( ) ) ) ,
1625+ ) ;
16041626 let mut global_path_prefix = Vec :: new ( ) ;
16051627 if symbol. scope == SymbolScope :: GlobalExplicit {
16061628 global_path_prefix. append ( & mut self . qualified_path ) ;
0 commit comments