@@ -12,7 +12,7 @@ use hir_expand::{
12
12
span_map:: { ExpansionSpanMap , SpanMap } ,
13
13
InFile , MacroDefId ,
14
14
} ;
15
- use intern:: { sym, Interned , Symbol } ;
15
+ use intern:: { sym, Symbol } ;
16
16
use rustc_hash:: FxHashMap ;
17
17
use span:: AstIdMap ;
18
18
use stdx:: never;
@@ -274,8 +274,8 @@ impl ExprCollector<'_> {
274
274
( self . body , self . source_map )
275
275
}
276
276
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 )
279
279
}
280
280
281
281
fn collect_expr ( & mut self , expr : ast:: Expr ) -> ExprId {
@@ -436,7 +436,7 @@ impl ExprCollector<'_> {
436
436
}
437
437
ast:: Expr :: PathExpr ( e) => {
438
438
let ( path, hygiene) = self
439
- . collect_expr_path ( & e)
439
+ . collect_expr_path ( e)
440
440
. map ( |( path, hygiene) | ( Expr :: Path ( path) , hygiene) )
441
441
. unwrap_or ( ( Expr :: Missing , HygieneId :: ROOT ) ) ;
442
442
let expr_id = self . alloc_expr ( path, syntax_ptr) ;
@@ -486,8 +486,7 @@ impl ExprCollector<'_> {
486
486
self . alloc_expr ( Expr :: Yeet { expr } , syntax_ptr)
487
487
}
488
488
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) ;
491
490
let record_lit = if let Some ( nfl) = e. record_expr_field_list ( ) {
492
491
let fields = nfl
493
492
. fields ( )
@@ -534,7 +533,7 @@ impl ExprCollector<'_> {
534
533
ast:: Expr :: TryExpr ( e) => self . collect_try_operator ( syntax_ptr, e) ,
535
534
ast:: Expr :: CastExpr ( e) => {
536
535
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 ( ) ) ;
538
537
self . alloc_expr ( Expr :: Cast { expr, type_ref } , syntax_ptr)
539
538
}
540
539
ast:: Expr :: RefExpr ( e) => {
@@ -573,16 +572,13 @@ impl ExprCollector<'_> {
573
572
arg_types. reserve_exact ( num_params) ;
574
573
for param in pl. params ( ) {
575
574
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) ) ;
578
576
args. push ( pat) ;
579
577
arg_types. push ( type_ref) ;
580
578
}
581
579
}
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) ) ;
586
582
587
583
let prev_is_lowering_coroutine = mem:: take ( & mut this. is_lowering_coroutine ) ;
588
584
let prev_try_block_label = this. current_try_block_label . take ( ) ;
@@ -709,17 +705,21 @@ impl ExprCollector<'_> {
709
705
ast:: Expr :: UnderscoreExpr ( _) => self . alloc_expr ( Expr :: Underscore , syntax_ptr) ,
710
706
ast:: Expr :: AsmExpr ( e) => self . lower_inline_asm ( e, syntax_ptr) ,
711
707
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 ( ) ) ;
713
709
let fields = e. fields ( ) . map ( |it| it. as_name ( ) ) . collect ( ) ;
714
710
self . alloc_expr ( Expr :: OffsetOf ( OffsetOf { container, fields } ) , syntax_ptr)
715
711
}
716
712
ast:: Expr :: FormatArgsExpr ( f) => self . collect_format_args ( f, syntax_ptr) ,
717
713
} )
718
714
}
719
715
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 ) > {
721
721
e. path ( ) . and_then ( |path| {
722
- let path = self . expander . parse_path ( self . db , path) ?;
722
+ let path = self . parse_path ( path) ?;
723
723
let Path :: Normal { type_anchor, mod_path, generic_args } = & path else {
724
724
panic ! ( "path parsing produced a non-normal path" ) ;
725
725
} ;
@@ -790,16 +790,13 @@ impl ExprCollector<'_> {
790
790
}
791
791
ast:: Expr :: CallExpr ( e) => {
792
792
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) ;
797
794
let ( ellipsis, args) = collect_tuple ( self , e. arg_list ( ) ?. args ( ) ) ;
798
795
self . alloc_pat_from_expr ( Pat :: TupleStruct { path, args, ellipsis } , syntax_ptr)
799
796
}
800
797
ast:: Expr :: PathExpr ( e) => {
801
798
let ( path, hygiene) = self
802
- . collect_expr_path ( e)
799
+ . collect_expr_path ( e. clone ( ) )
803
800
. map ( |( path, hygiene) | ( Pat :: Path ( Box :: new ( path) ) , hygiene) )
804
801
. unwrap_or ( ( Pat :: Missing , HygieneId :: ROOT ) ) ;
805
802
let pat_id = self . alloc_pat_from_expr ( path, syntax_ptr) ;
@@ -819,8 +816,7 @@ impl ExprCollector<'_> {
819
816
id
820
817
}
821
818
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) ;
824
820
let record_field_list = e. record_expr_field_list ( ) ?;
825
821
let ellipsis = record_field_list. dotdot_token ( ) . is_some ( ) ;
826
822
// FIXME: Report an error here if `record_field_list.spread().is_some()`.
@@ -1325,8 +1321,7 @@ impl ExprCollector<'_> {
1325
1321
return ;
1326
1322
}
1327
1323
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) ) ;
1330
1325
let initializer = stmt. initializer ( ) . map ( |e| self . collect_expr ( e) ) ;
1331
1326
let else_branch = stmt
1332
1327
. let_else ( )
@@ -1552,8 +1547,7 @@ impl ExprCollector<'_> {
1552
1547
return pat;
1553
1548
}
1554
1549
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) ;
1557
1551
let ( args, ellipsis) = self . collect_tuple_pat (
1558
1552
p. fields ( ) ,
1559
1553
comma_follows_token ( p. l_paren_token ( ) ) ,
@@ -1567,8 +1561,7 @@ impl ExprCollector<'_> {
1567
1561
Pat :: Ref { pat, mutability }
1568
1562
}
1569
1563
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) ;
1572
1565
path. map ( Pat :: Path ) . unwrap_or ( Pat :: Missing )
1573
1566
}
1574
1567
ast:: Pat :: OrPat ( p) => ' b: {
@@ -1611,8 +1604,7 @@ impl ExprCollector<'_> {
1611
1604
}
1612
1605
ast:: Pat :: WildcardPat ( _) => Pat :: Wild ,
1613
1606
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) ;
1616
1608
let record_pat_field_list =
1617
1609
& p. record_pat_field_list ( ) . expect ( "every struct should have a field list" ) ;
1618
1610
let args = record_pat_field_list
0 commit comments