@@ -12,7 +12,7 @@ use hir_expand::{
1212 span_map:: { ExpansionSpanMap , SpanMap } ,
1313 InFile , MacroDefId ,
1414} ;
15- use intern:: { sym, Interned , Symbol } ;
15+ use intern:: { sym, Symbol } ;
1616use rustc_hash:: FxHashMap ;
1717use span:: AstIdMap ;
1818use stdx:: never;
@@ -274,8 +274,8 @@ impl ExprCollector<'_> {
274274 ( self . body , self . source_map )
275275 }
276276
277- fn ctx ( & self ) -> LowerCtx < ' _ > {
278- self . expander . ctx ( self . db )
277+ fn ctx ( & mut self ) -> LowerCtx < ' _ > {
278+ self . expander . ctx ( self . db , & mut self . body . types , & mut self . source_map . types )
279279 }
280280
281281 fn collect_expr ( & mut self , expr : ast:: Expr ) -> ExprId {
@@ -436,7 +436,7 @@ impl ExprCollector<'_> {
436436 }
437437 ast:: Expr :: PathExpr ( e) => {
438438 let ( path, hygiene) = self
439- . collect_expr_path ( & e)
439+ . collect_expr_path ( e)
440440 . map ( |( path, hygiene) | ( Expr :: Path ( path) , hygiene) )
441441 . unwrap_or ( ( Expr :: Missing , HygieneId :: ROOT ) ) ;
442442 let expr_id = self . alloc_expr ( path, syntax_ptr) ;
@@ -486,8 +486,7 @@ impl ExprCollector<'_> {
486486 self . alloc_expr ( Expr :: Yeet { expr } , syntax_ptr)
487487 }
488488 ast:: Expr :: RecordExpr ( e) => {
489- let path =
490- e. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
489+ let path = e. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
491490 let record_lit = if let Some ( nfl) = e. record_expr_field_list ( ) {
492491 let fields = nfl
493492 . fields ( )
@@ -534,7 +533,7 @@ impl ExprCollector<'_> {
534533 ast:: Expr :: TryExpr ( e) => self . collect_try_operator ( syntax_ptr, e) ,
535534 ast:: Expr :: CastExpr ( e) => {
536535 let expr = self . collect_expr_opt ( e. expr ( ) ) ;
537- let type_ref = Interned :: new ( TypeRef :: from_ast_opt ( & self . ctx ( ) , e. ty ( ) ) ) ;
536+ let type_ref = TypeRef :: from_ast_opt ( & self . ctx ( ) , e. ty ( ) ) ;
538537 self . alloc_expr ( Expr :: Cast { expr, type_ref } , syntax_ptr)
539538 }
540539 ast:: Expr :: RefExpr ( e) => {
@@ -573,16 +572,13 @@ impl ExprCollector<'_> {
573572 arg_types. reserve_exact ( num_params) ;
574573 for param in pl. params ( ) {
575574 let pat = this. collect_pat_top ( param. pat ( ) ) ;
576- let type_ref =
577- param. ty ( ) . map ( |it| Interned :: new ( TypeRef :: from_ast ( & this. ctx ( ) , it) ) ) ;
575+ let type_ref = param. ty ( ) . map ( |it| TypeRef :: from_ast ( & this. ctx ( ) , it) ) ;
578576 args. push ( pat) ;
579577 arg_types. push ( type_ref) ;
580578 }
581579 }
582- let ret_type = e
583- . ret_type ( )
584- . and_then ( |r| r. ty ( ) )
585- . map ( |it| Interned :: new ( TypeRef :: from_ast ( & this. ctx ( ) , it) ) ) ;
580+ let ret_type =
581+ e. ret_type ( ) . and_then ( |r| r. ty ( ) ) . map ( |it| TypeRef :: from_ast ( & this. ctx ( ) , it) ) ;
586582
587583 let prev_is_lowering_coroutine = mem:: take ( & mut this. is_lowering_coroutine ) ;
588584 let prev_try_block_label = this. current_try_block_label . take ( ) ;
@@ -709,23 +705,23 @@ impl ExprCollector<'_> {
709705 ast:: Expr :: UnderscoreExpr ( _) => self . alloc_expr ( Expr :: Underscore , syntax_ptr) ,
710706 ast:: Expr :: AsmExpr ( e) => self . lower_inline_asm ( e, syntax_ptr) ,
711707 ast:: Expr :: OffsetOfExpr ( e) => {
712- let container = Interned :: new ( TypeRef :: from_ast_opt ( & self . ctx ( ) , e. ty ( ) ) ) ;
708+ let container = TypeRef :: from_ast_opt ( & self . ctx ( ) , e. ty ( ) ) ;
713709 let fields = e. fields ( ) . map ( |it| it. as_name ( ) ) . collect ( ) ;
714710 self . alloc_expr ( Expr :: OffsetOf ( OffsetOf { container, fields } ) , syntax_ptr)
715711 }
716712 ast:: Expr :: FormatArgsExpr ( f) => self . collect_format_args ( f, syntax_ptr) ,
717713 } )
718714 }
719715
720- fn collect_expr_path ( & mut self , e : & ast:: PathExpr ) -> Option < ( Path , HygieneId ) > {
716+ fn parse_path ( & mut self , path : ast:: Path ) -> Option < Path > {
717+ self . expander . parse_path ( self . db , path, & mut self . body . types , & mut self . source_map . types )
718+ }
719+
720+ fn collect_expr_path ( & mut self , e : ast:: PathExpr ) -> Option < ( Path , HygieneId ) > {
721721 e. path ( ) . and_then ( |path| {
722- let path = self . expander . parse_path ( self . db , path) ?;
723- let Path :: Normal { type_anchor, mod_path, generic_args } = & path else {
724- panic ! ( "path parsing produced a non-normal path" ) ;
725- } ;
722+ let path = self . parse_path ( path) ?;
726723 // Need to enable `mod_path.len() < 1` for `self`.
727- let may_be_variable =
728- type_anchor. is_none ( ) && mod_path. len ( ) <= 1 && generic_args. is_none ( ) ;
724+ let may_be_variable = matches ! ( & path, Path :: BarePath ( mod_path) if mod_path. len( ) <= 1 ) ;
729725 let hygiene = if may_be_variable {
730726 self . hygiene_id_for ( e. syntax ( ) . text_range ( ) . start ( ) )
731727 } else {
@@ -790,17 +786,14 @@ impl ExprCollector<'_> {
790786 }
791787 ast:: Expr :: CallExpr ( e) => {
792788 let path = collect_path ( self , e. expr ( ) ?) ?;
793- let path = path
794- . path ( )
795- . and_then ( |path| self . expander . parse_path ( self . db , path) )
796- . map ( Box :: new) ;
789+ let path = path. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
797790 let ( ellipsis, args) = collect_tuple ( self , e. arg_list ( ) ?. args ( ) ) ;
798791 self . alloc_pat_from_expr ( Pat :: TupleStruct { path, args, ellipsis } , syntax_ptr)
799792 }
800793 ast:: Expr :: PathExpr ( e) => {
801794 let ( path, hygiene) = self
802- . collect_expr_path ( e)
803- . map ( |( path, hygiene) | ( Pat :: Path ( Box :: new ( path) ) , hygiene) )
795+ . collect_expr_path ( e. clone ( ) )
796+ . map ( |( path, hygiene) | ( Pat :: Path ( path) , hygiene) )
804797 . unwrap_or ( ( Pat :: Missing , HygieneId :: ROOT ) ) ;
805798 let pat_id = self . alloc_pat_from_expr ( path, syntax_ptr) ;
806799 if !hygiene. is_root ( ) {
@@ -819,8 +812,7 @@ impl ExprCollector<'_> {
819812 id
820813 }
821814 ast:: Expr :: RecordExpr ( e) => {
822- let path =
823- e. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
815+ let path = e. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
824816 let record_field_list = e. record_expr_field_list ( ) ?;
825817 let ellipsis = record_field_list. dotdot_token ( ) . is_some ( ) ;
826818 // FIXME: Report an error here if `record_field_list.spread().is_some()`.
@@ -1063,7 +1055,7 @@ impl ExprCollector<'_> {
10631055 syntax_ptr,
10641056 ) ;
10651057 let none_arm = MatchArm {
1066- pat : self . alloc_pat_desugared ( Pat :: Path ( Box :: new ( option_none) ) ) ,
1058+ pat : self . alloc_pat_desugared ( Pat :: Path ( option_none) ) ,
10671059 guard : None ,
10681060 expr : self . alloc_expr ( Expr :: Break { expr : None , label : None } , syntax_ptr) ,
10691061 } ;
@@ -1325,8 +1317,7 @@ impl ExprCollector<'_> {
13251317 return ;
13261318 }
13271319 let pat = self . collect_pat_top ( stmt. pat ( ) ) ;
1328- let type_ref =
1329- stmt. ty ( ) . map ( |it| Interned :: new ( TypeRef :: from_ast ( & self . ctx ( ) , it) ) ) ;
1320+ let type_ref = stmt. ty ( ) . map ( |it| TypeRef :: from_ast ( & self . ctx ( ) , it) ) ;
13301321 let initializer = stmt. initializer ( ) . map ( |e| self . collect_expr ( e) ) ;
13311322 let else_branch = stmt
13321323 . let_else ( )
@@ -1552,8 +1543,7 @@ impl ExprCollector<'_> {
15521543 return pat;
15531544 }
15541545 ast:: Pat :: TupleStructPat ( p) => {
1555- let path =
1556- p. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
1546+ let path = p. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
15571547 let ( args, ellipsis) = self . collect_tuple_pat (
15581548 p. fields ( ) ,
15591549 comma_follows_token ( p. l_paren_token ( ) ) ,
@@ -1567,8 +1557,7 @@ impl ExprCollector<'_> {
15671557 Pat :: Ref { pat, mutability }
15681558 }
15691559 ast:: Pat :: PathPat ( p) => {
1570- let path =
1571- p. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
1560+ let path = p. path ( ) . and_then ( |path| self . parse_path ( path) ) ;
15721561 path. map ( Pat :: Path ) . unwrap_or ( Pat :: Missing )
15731562 }
15741563 ast:: Pat :: OrPat ( p) => ' b: {
@@ -1615,8 +1604,7 @@ impl ExprCollector<'_> {
16151604 }
16161605 ast:: Pat :: WildcardPat ( _) => Pat :: Wild ,
16171606 ast:: Pat :: RecordPat ( p) => {
1618- let path =
1619- p. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
1607+ let path = p. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
16201608 let record_pat_field_list =
16211609 & p. record_pat_field_list ( ) . expect ( "every struct should have a field list" ) ;
16221610 let args = record_pat_field_list
0 commit comments