@@ -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,23 +705,23 @@ 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) ?;
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) ?;
726
723
// 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 ) ;
729
725
let hygiene = if may_be_variable {
730
726
self . hygiene_id_for ( e. syntax ( ) . text_range ( ) . start ( ) )
731
727
} else {
@@ -790,17 +786,14 @@ impl ExprCollector<'_> {
790
786
}
791
787
ast:: Expr :: CallExpr ( e) => {
792
788
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) ;
797
790
let ( ellipsis, args) = collect_tuple ( self , e. arg_list ( ) ?. args ( ) ) ;
798
791
self . alloc_pat_from_expr ( Pat :: TupleStruct { path, args, ellipsis } , syntax_ptr)
799
792
}
800
793
ast:: Expr :: PathExpr ( e) => {
801
794
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) )
804
797
. unwrap_or ( ( Pat :: Missing , HygieneId :: ROOT ) ) ;
805
798
let pat_id = self . alloc_pat_from_expr ( path, syntax_ptr) ;
806
799
if !hygiene. is_root ( ) {
@@ -819,8 +812,7 @@ impl ExprCollector<'_> {
819
812
id
820
813
}
821
814
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) ;
824
816
let record_field_list = e. record_expr_field_list ( ) ?;
825
817
let ellipsis = record_field_list. dotdot_token ( ) . is_some ( ) ;
826
818
// FIXME: Report an error here if `record_field_list.spread().is_some()`.
@@ -1063,7 +1055,7 @@ impl ExprCollector<'_> {
1063
1055
syntax_ptr,
1064
1056
) ;
1065
1057
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) ) ,
1067
1059
guard : None ,
1068
1060
expr : self . alloc_expr ( Expr :: Break { expr : None , label : None } , syntax_ptr) ,
1069
1061
} ;
@@ -1325,8 +1317,7 @@ impl ExprCollector<'_> {
1325
1317
return ;
1326
1318
}
1327
1319
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) ) ;
1330
1321
let initializer = stmt. initializer ( ) . map ( |e| self . collect_expr ( e) ) ;
1331
1322
let else_branch = stmt
1332
1323
. let_else ( )
@@ -1552,8 +1543,7 @@ impl ExprCollector<'_> {
1552
1543
return pat;
1553
1544
}
1554
1545
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) ;
1557
1547
let ( args, ellipsis) = self . collect_tuple_pat (
1558
1548
p. fields ( ) ,
1559
1549
comma_follows_token ( p. l_paren_token ( ) ) ,
@@ -1567,8 +1557,7 @@ impl ExprCollector<'_> {
1567
1557
Pat :: Ref { pat, mutability }
1568
1558
}
1569
1559
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) ) ;
1572
1561
path. map ( Pat :: Path ) . unwrap_or ( Pat :: Missing )
1573
1562
}
1574
1563
ast:: Pat :: OrPat ( p) => ' b: {
@@ -1615,8 +1604,7 @@ impl ExprCollector<'_> {
1615
1604
}
1616
1605
ast:: Pat :: WildcardPat ( _) => Pat :: Wild ,
1617
1606
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) ;
1620
1608
let record_pat_field_list =
1621
1609
& p. record_pat_field_list ( ) . expect ( "every struct should have a field list" ) ;
1622
1610
let args = record_pat_field_list
0 commit comments