@@ -565,7 +565,7 @@ impl Compiler {
565565 // we do this here because `from __future__` still executes that `from` statement at runtime,
566566 // we still need to compile the ImportFrom down below
567567 ImportFrom ( ast:: StmtImportFrom { module, names, .. } )
568- if module. as_deref ( ) == Some ( "__future__" ) =>
568+ if module. as_ref ( ) . map ( |id| id . as_str ( ) ) == Some ( "__future__" ) =>
569569 {
570570 self . compile_future_features ( names) ?
571571 }
@@ -582,16 +582,16 @@ impl Compiler {
582582 value : num_traits:: Zero :: zero ( ) ,
583583 } ) ;
584584 self . emit_constant ( ConstantData :: None ) ;
585- let idx = self . name ( & name. name ) ;
585+ let idx = self . name ( name. name . as_str ( ) ) ;
586586 emit ! ( self , Instruction :: ImportName { idx } ) ;
587587 if let Some ( alias) = & name. asname {
588- for part in name. name . split ( '.' ) . skip ( 1 ) {
588+ for part in name. name . as_str ( ) . split ( '.' ) . skip ( 1 ) {
589589 let idx = self . name ( part) ;
590590 emit ! ( self , Instruction :: LoadAttr { idx } ) ;
591591 }
592- self . store_name ( alias) ?
592+ self . store_name ( alias. as_str ( ) ) ?
593593 } else {
594- self . store_name ( name. name . split ( '.' ) . next ( ) . unwrap ( ) ) ?
594+ self . store_name ( name. name . as_str ( ) . split ( '.' ) . next ( ) . unwrap ( ) ) ?
595595 }
596596 }
597597 }
@@ -600,7 +600,7 @@ impl Compiler {
600600 module,
601601 names,
602602 } ) => {
603- let import_star = names. iter ( ) . any ( |n| n. node . name == "*" ) ;
603+ let import_star = names. iter ( ) . any ( |n| n. node . name . as_str ( ) == "*" ) ;
604604
605605 let from_list = if import_star {
606606 if self . ctx . in_func ( ) {
@@ -616,16 +616,16 @@ impl Compiler {
616616 names
617617 . iter ( )
618618 . map ( |n| ConstantData :: Str {
619- value : n. node . name . to_owned ( ) ,
619+ value : n. node . name . to_string ( ) ,
620620 } )
621621 . collect ( )
622622 } ;
623623
624- let module_idx = module. as_ref ( ) . map ( |s| self . name ( s) ) ;
624+ let module_idx = module. as_ref ( ) . map ( |s| self . name ( s. as_str ( ) ) ) ;
625625
626626 // from .... import (*fromlist)
627627 self . emit_constant ( ConstantData :: Integer {
628- value : ( * level) . unwrap_or ( 0 ) . into ( ) ,
628+ value : level. as_ref ( ) . map_or ( 0 , |level| level . to_u32 ( ) ) . into ( ) ,
629629 } ) ;
630630 self . emit_constant ( ConstantData :: Tuple {
631631 elements : from_list,
@@ -644,15 +644,15 @@ impl Compiler {
644644
645645 for name in names {
646646 let name = & name. node ;
647- let idx = self . name ( & name. name ) ;
647+ let idx = self . name ( name. name . as_str ( ) ) ;
648648 // import symbol from module:
649649 emit ! ( self , Instruction :: ImportFrom { idx } ) ;
650650
651651 // Store module under proper name:
652652 if let Some ( alias) = & name. asname {
653- self . store_name ( alias) ?
653+ self . store_name ( alias. as_str ( ) ) ?
654654 } else {
655- self . store_name ( & name. name ) ?
655+ self . store_name ( name. name . as_str ( ) ) ?
656656 }
657657 }
658658
@@ -747,7 +747,7 @@ impl Compiler {
747747 returns,
748748 ..
749749 } ) => self . compile_function_def (
750- name,
750+ name. as_str ( ) ,
751751 args,
752752 body,
753753 decorator_list,
@@ -762,7 +762,7 @@ impl Compiler {
762762 returns,
763763 ..
764764 } ) => self . compile_function_def (
765- name,
765+ name. as_str ( ) ,
766766 args,
767767 body,
768768 decorator_list,
@@ -775,7 +775,7 @@ impl Compiler {
775775 bases,
776776 keywords,
777777 decorator_list,
778- } ) => self . compile_class_def ( name, body, bases, keywords, decorator_list) ?,
778+ } ) => self . compile_class_def ( name. as_str ( ) , body, bases, keywords, decorator_list) ?,
779779 Assert ( StmtAssert { test, msg } ) => {
780780 // if some flag, ignore all assert statements!
781781 if self . opts . optimize == 0 {
@@ -885,12 +885,12 @@ impl Compiler {
885885 fn compile_delete ( & mut self , expression : & ast:: located:: Expr ) -> CompileResult < ( ) > {
886886 match & expression. node {
887887 ast:: ExprKind :: Name ( ast:: ExprName { id, .. } ) => {
888- self . compile_name ( id, NameUsage :: Delete ) ?
888+ self . compile_name ( id. as_str ( ) , NameUsage :: Delete ) ?
889889 }
890890 ast:: ExprKind :: Attribute ( ast:: ExprAttribute { value, attr, .. } ) => {
891- self . check_forbidden_name ( attr, NameUsage :: Delete ) ?;
891+ self . check_forbidden_name ( attr. as_str ( ) , NameUsage :: Delete ) ?;
892892 self . compile_expression ( value) ?;
893- let idx = self . name ( attr) ;
893+ let idx = self . name ( attr. as_str ( ) ) ;
894894 emit ! ( self , Instruction :: DeleteAttr { idx } ) ;
895895 }
896896 ast:: ExprKind :: Subscript ( ast:: ExprSubscript { value, slice, .. } ) => {
@@ -935,7 +935,7 @@ impl Compiler {
935935 . zip ( & args. kw_defaults )
936936 {
937937 self . emit_constant ( ConstantData :: Str {
938- value : kw. node . arg . clone ( ) ,
938+ value : kw. node . arg . to_string ( ) ,
939939 } ) ;
940940 self . compile_expression ( default) ?;
941941 }
@@ -968,16 +968,16 @@ impl Compiler {
968968 . chain ( & args. args )
969969 . chain ( & args. kwonlyargs ) ;
970970 for name in args_iter {
971- self . varname ( & name. node . arg ) ?;
971+ self . varname ( name. node . arg . as_str ( ) ) ?;
972972 }
973973
974974 if let Some ( name) = args. vararg . as_deref ( ) {
975975 self . current_code_info ( ) . flags |= bytecode:: CodeFlags :: HAS_VARARGS ;
976- self . varname ( & name. node . arg ) ?;
976+ self . varname ( name. node . arg . as_str ( ) ) ?;
977977 }
978978 if let Some ( name) = args. kwarg . as_deref ( ) {
979979 self . current_code_info ( ) . flags |= bytecode:: CodeFlags :: HAS_VARKEYWORDS ;
980- self . varname ( & name. node . arg ) ?;
980+ self . varname ( name. node . arg . as_str ( ) ) ?;
981981 }
982982
983983 Ok ( func_flags)
@@ -1066,7 +1066,7 @@ impl Compiler {
10661066
10671067 // We have a match, store in name (except x as y)
10681068 if let Some ( alias) = name {
1069- self . store_name ( alias) ?
1069+ self . store_name ( alias. as_str ( ) ) ?
10701070 } else {
10711071 // Drop exception from top of stack:
10721072 emit ! ( self , Instruction :: Pop ) ;
@@ -1224,7 +1224,7 @@ impl Compiler {
12241224 for arg in args_iter {
12251225 if let Some ( annotation) = & arg. node . annotation {
12261226 self . emit_constant ( ConstantData :: Str {
1227- value : self . mangle ( & arg. node . arg ) . into_owned ( ) ,
1227+ value : self . mangle ( arg. node . arg . as_str ( ) ) . into_owned ( ) ,
12281228 } ) ;
12291229 self . compile_annotation ( annotation) ?;
12301230 num_annotations += 1 ;
@@ -1750,7 +1750,7 @@ impl Compiler {
17501750 let annotations = self . name ( "__annotations__" ) ;
17511751 emit ! ( self , Instruction :: LoadNameAny ( annotations) ) ;
17521752 self . emit_constant ( ConstantData :: Str {
1753- value : self . mangle ( id) . into_owned ( ) ,
1753+ value : self . mangle ( id. as_str ( ) ) . into_owned ( ) ,
17541754 } ) ;
17551755 emit ! ( self , Instruction :: StoreSubscript ) ;
17561756 } else {
@@ -1763,16 +1763,16 @@ impl Compiler {
17631763
17641764 fn compile_store ( & mut self , target : & ast:: located:: Expr ) -> CompileResult < ( ) > {
17651765 match & target. node {
1766- ast:: ExprKind :: Name ( ast:: ExprName { id, .. } ) => self . store_name ( id) ?,
1766+ ast:: ExprKind :: Name ( ast:: ExprName { id, .. } ) => self . store_name ( id. as_str ( ) ) ?,
17671767 ast:: ExprKind :: Subscript ( ast:: ExprSubscript { value, slice, .. } ) => {
17681768 self . compile_expression ( value) ?;
17691769 self . compile_expression ( slice) ?;
17701770 emit ! ( self , Instruction :: StoreSubscript ) ;
17711771 }
17721772 ast:: ExprKind :: Attribute ( ast:: ExprAttribute { value, attr, .. } ) => {
1773- self . check_forbidden_name ( attr, NameUsage :: Store ) ?;
1773+ self . check_forbidden_name ( attr. as_str ( ) , NameUsage :: Store ) ?;
17741774 self . compile_expression ( value) ?;
1775- let idx = self . name ( attr) ;
1775+ let idx = self . name ( attr. as_str ( ) ) ;
17761776 emit ! ( self , Instruction :: StoreAttr { idx } ) ;
17771777 }
17781778 ast:: ExprKind :: List ( ast:: ExprList { elts, .. } )
@@ -1845,6 +1845,7 @@ impl Compiler {
18451845
18461846 let kind = match & target. node {
18471847 ast:: ExprKind :: Name ( ast:: ExprName { id, .. } ) => {
1848+ let id = id. as_str ( ) ;
18481849 self . compile_name ( id, NameUsage :: Load ) ?;
18491850 AugAssignKind :: Name { id }
18501851 }
@@ -1856,6 +1857,7 @@ impl Compiler {
18561857 AugAssignKind :: Subscript
18571858 }
18581859 ast:: ExprKind :: Attribute ( ast:: ExprAttribute { value, attr, .. } ) => {
1860+ let attr = attr. as_str ( ) ;
18591861 self . check_forbidden_name ( attr, NameUsage :: Store ) ?;
18601862 self . compile_expression ( value) ?;
18611863 emit ! ( self , Instruction :: Duplicate ) ;
@@ -2108,7 +2110,7 @@ impl Compiler {
21082110 }
21092111 Attribute ( ast:: ExprAttribute { value, attr, .. } ) => {
21102112 self . compile_expression ( value) ?;
2111- let idx = self . name ( attr) ;
2113+ let idx = self . name ( attr. as_str ( ) ) ;
21122114 emit ! ( self , Instruction :: LoadAttr { idx } ) ;
21132115 }
21142116 Compare ( ast:: ExprCompare {
@@ -2230,12 +2232,12 @@ impl Compiler {
22302232 emit ! (
22312233 self ,
22322234 Instruction :: FormatValue {
2233- conversion: ConversionFlag :: from_op_arg( * conversion)
2235+ conversion: ConversionFlag :: from_op_arg( conversion. to_u32 ( ) )
22342236 . expect( "invalid conversion flag" ) ,
22352237 } ,
22362238 ) ;
22372239 }
2238- Name ( ast:: ExprName { id, .. } ) => self . load_name ( id) ?,
2240+ Name ( ast:: ExprName { id, .. } ) => self . load_name ( id. as_str ( ) ) ?,
22392241 Lambda ( ast:: ExprLambda { args, body } ) => {
22402242 let prev_ctx = self . ctx ;
22412243
@@ -2390,7 +2392,7 @@ impl Compiler {
23902392 for keyword in sub_keywords {
23912393 if let Some ( name) = & keyword. node . arg {
23922394 self . emit_constant ( ConstantData :: Str {
2393- value : name. to_owned ( ) ,
2395+ value : name. to_string ( ) ,
23942396 } ) ;
23952397 self . compile_expression ( & keyword. node . value ) ?;
23962398 sub_size += 1 ;
@@ -2415,7 +2417,7 @@ impl Compiler {
24152417 let method =
24162418 if let ast:: ExprKind :: Attribute ( ast:: ExprAttribute { value, attr, .. } ) = & func. node {
24172419 self . compile_expression ( value) ?;
2418- let idx = self . name ( attr) ;
2420+ let idx = self . name ( attr. as_str ( ) ) ;
24192421 emit ! ( self , Instruction :: LoadMethod { idx } ) ;
24202422 true
24212423 } else {
@@ -2464,7 +2466,7 @@ impl Compiler {
24642466
24652467 for keyword in keywords {
24662468 if let Some ( name) = & keyword. node . arg {
2467- self . check_forbidden_name ( name, NameUsage :: Store ) ?;
2469+ self . check_forbidden_name ( name. as_str ( ) , NameUsage :: Store ) ?;
24682470 }
24692471 }
24702472
@@ -2487,7 +2489,7 @@ impl Compiler {
24872489 for keyword in keywords {
24882490 if let Some ( name) = & keyword. node . arg {
24892491 kwarg_names. push ( ConstantData :: Str {
2490- value : name. to_owned ( ) ,
2492+ value : name. to_string ( ) ,
24912493 } ) ;
24922494 } else {
24932495 // This means **kwargs!
@@ -2611,7 +2613,7 @@ impl Compiler {
26112613
26122614 let mut loop_labels = vec ! [ ] ;
26132615 for generator in generators {
2614- if generator. is_async > 0 {
2616+ if generator. is_async {
26152617 unimplemented ! ( "async for comprehensions" ) ;
26162618 }
26172619
@@ -2706,7 +2708,7 @@ impl Compiler {
27062708 return Err ( self . error ( CodegenErrorType :: InvalidFuturePlacement ) ) ;
27072709 }
27082710 for feature in features {
2709- match & * feature. node . name {
2711+ match feature. node . name . as_str ( ) {
27102712 // Python 3 features; we've already implemented them by default
27112713 "nested_scopes" | "generators" | "division" | "absolute_import"
27122714 | "with_statement" | "print_function" | "unicode_literals" => { }
0 commit comments