@@ -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,17 +705,21 @@ 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) ?;
722+ let path = self . parse_path ( path) ?;
723723 let Path :: Normal { type_anchor, mod_path, generic_args } = & path else {
724724 panic ! ( "path parsing produced a non-normal path" ) ;
725725 } ;
@@ -790,16 +790,13 @@ impl ExprCollector<'_> {
790790 }
791791 ast:: Expr :: CallExpr ( e) => {
792792 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) ;
793+ let path = path. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
797794 let ( ellipsis, args) = collect_tuple ( self , e. arg_list ( ) ?. args ( ) ) ;
798795 self . alloc_pat_from_expr ( Pat :: TupleStruct { path, args, ellipsis } , syntax_ptr)
799796 }
800797 ast:: Expr :: PathExpr ( e) => {
801798 let ( path, hygiene) = self
802- . collect_expr_path ( e)
799+ . collect_expr_path ( e. clone ( ) )
803800 . map ( |( path, hygiene) | ( Pat :: Path ( Box :: new ( path) ) , hygiene) )
804801 . unwrap_or ( ( Pat :: Missing , HygieneId :: ROOT ) ) ;
805802 let pat_id = self . alloc_pat_from_expr ( path, syntax_ptr) ;
@@ -819,8 +816,7 @@ impl ExprCollector<'_> {
819816 id
820817 }
821818 ast:: Expr :: RecordExpr ( e) => {
822- let path =
823- e. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
819+ let path = e. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
824820 let record_field_list = e. record_expr_field_list ( ) ?;
825821 let ellipsis = record_field_list. dotdot_token ( ) . is_some ( ) ;
826822 // FIXME: Report an error here if `record_field_list.spread().is_some()`.
@@ -1325,8 +1321,7 @@ impl ExprCollector<'_> {
13251321 return ;
13261322 }
13271323 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) ) ) ;
1324+ let type_ref = stmt. ty ( ) . map ( |it| TypeRef :: from_ast ( & self . ctx ( ) , it) ) ;
13301325 let initializer = stmt. initializer ( ) . map ( |e| self . collect_expr ( e) ) ;
13311326 let else_branch = stmt
13321327 . let_else ( )
@@ -1552,8 +1547,7 @@ impl ExprCollector<'_> {
15521547 return pat;
15531548 }
15541549 ast:: Pat :: TupleStructPat ( p) => {
1555- let path =
1556- p. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
1550+ let path = p. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
15571551 let ( args, ellipsis) = self . collect_tuple_pat (
15581552 p. fields ( ) ,
15591553 comma_follows_token ( p. l_paren_token ( ) ) ,
@@ -1567,8 +1561,7 @@ impl ExprCollector<'_> {
15671561 Pat :: Ref { pat, mutability }
15681562 }
15691563 ast:: Pat :: PathPat ( p) => {
1570- let path =
1571- p. path ( ) . and_then ( |path| self . expander . parse_path ( self . db , path) ) . map ( Box :: new) ;
1564+ let path = p. path ( ) . and_then ( |path| self . parse_path ( path) ) . map ( Box :: new) ;
15721565 path. map ( Pat :: Path ) . unwrap_or ( Pat :: Missing )
15731566 }
15741567 ast:: Pat :: OrPat ( p) => ' b: {
@@ -1611,8 +1604,7 @@ impl ExprCollector<'_> {
16111604 }
16121605 ast:: Pat :: WildcardPat ( _) => Pat :: Wild ,
16131606 ast:: Pat :: RecordPat ( p) => {
1614- let path =
1615- 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) ;
16161608 let record_pat_field_list =
16171609 & p. record_pat_field_list ( ) . expect ( "every struct should have a field list" ) ;
16181610 let args = record_pat_field_list
0 commit comments