@@ -35,7 +35,8 @@ use crate::{
35
35
db:: DefDatabase ,
36
36
expr_store:: {
37
37
Body , BodySourceMap , ExprPtr , ExpressionStore , ExpressionStoreBuilder ,
38
- ExpressionStoreDiagnostics , ExpressionStoreSourceMap , HygieneId , LabelPtr , PatPtr , TypePtr ,
38
+ ExpressionStoreDiagnostics , ExpressionStoreSourceMap , HygieneId , LabelPtr , LifetimePtr ,
39
+ PatPtr , TypePtr ,
39
40
expander:: Expander ,
40
41
lower:: generics:: ImplTraitLowerFn ,
41
42
path:: { AssociatedTypeBinding , GenericArg , GenericArgs , GenericArgsParentheses , Path } ,
@@ -56,8 +57,8 @@ use crate::{
56
57
lang_item:: LangItem ,
57
58
nameres:: { DefMap , LocalDefMap , MacroSubNs } ,
58
59
type_ref:: {
59
- ArrayType , ConstRef , FnType , LifetimeRef , Mutability , PathId , Rawness , RefType ,
60
- TraitBoundModifier , TraitRef , TypeBound , TypeRef , TypeRefId , UseArgRef ,
60
+ ArrayType , ConstRef , FnType , LifetimeRef , LifetimeRefId , Mutability , PathId , Rawness ,
61
+ RefType , TraitBoundModifier , TraitRef , TypeBound , TypeRef , TypeRefId , UseArgRef ,
61
62
} ,
62
63
} ;
63
64
@@ -568,20 +569,21 @@ impl ExprCollector<'_> {
568
569
}
569
570
}
570
571
571
- pub fn lower_lifetime_ref ( & mut self , lifetime : ast:: Lifetime ) -> LifetimeRef {
572
+ pub fn lower_lifetime_ref ( & mut self , lifetime : ast:: Lifetime ) -> LifetimeRefId {
572
573
// FIXME: Keyword check?
573
- match & * lifetime. text ( ) {
574
+ let lifetime_ref = match & * lifetime. text ( ) {
574
575
"" | "'" => LifetimeRef :: Error ,
575
576
"'static" => LifetimeRef :: Static ,
576
577
"'_" => LifetimeRef :: Placeholder ,
577
578
text => LifetimeRef :: Named ( Name :: new_lifetime ( text) ) ,
578
- }
579
+ } ;
580
+ self . alloc_lifetime_ref ( lifetime_ref, AstPtr :: new ( & lifetime) )
579
581
}
580
582
581
- pub fn lower_lifetime_ref_opt ( & mut self , lifetime : Option < ast:: Lifetime > ) -> LifetimeRef {
583
+ pub fn lower_lifetime_ref_opt ( & mut self , lifetime : Option < ast:: Lifetime > ) -> LifetimeRefId {
582
584
match lifetime {
583
585
Some ( lifetime) => self . lower_lifetime_ref ( lifetime) ,
584
- None => LifetimeRef :: Placeholder ,
586
+ None => self . alloc_lifetime_ref_desugared ( LifetimeRef :: Placeholder ) ,
585
587
}
586
588
}
587
589
@@ -735,6 +737,30 @@ impl ExprCollector<'_> {
735
737
id
736
738
}
737
739
740
+ fn alloc_lifetime_ref (
741
+ & mut self ,
742
+ lifetime_ref : LifetimeRef ,
743
+ node : LifetimePtr ,
744
+ ) -> LifetimeRefId {
745
+ let id = self . store . lifetimes . alloc ( lifetime_ref) ;
746
+ let ptr = self . expander . in_file ( node) ;
747
+ self . source_map . lifetime_map_back . insert ( id, ptr) ;
748
+ self . source_map . lifetime_map . insert ( ptr, id) ;
749
+ id
750
+ }
751
+
752
+ fn alloc_type_ref_desugared ( & mut self , type_ref : TypeRef ) -> TypeRefId {
753
+ self . store . types . alloc ( type_ref)
754
+ }
755
+
756
+ fn alloc_lifetime_ref_desugared ( & mut self , lifetime_ref : LifetimeRef ) -> LifetimeRefId {
757
+ self . store . lifetimes . alloc ( lifetime_ref)
758
+ }
759
+
760
+ fn alloc_error_type ( & mut self ) -> TypeRefId {
761
+ self . store . types . alloc ( TypeRef :: Error )
762
+ }
763
+
738
764
pub fn lower_path (
739
765
& mut self ,
740
766
ast : ast:: Path ,
@@ -754,14 +780,6 @@ impl ExprCollector<'_> {
754
780
result
755
781
}
756
782
757
- fn alloc_type_ref_desugared ( & mut self , type_ref : TypeRef ) -> TypeRefId {
758
- self . store . types . alloc ( type_ref)
759
- }
760
-
761
- fn alloc_error_type ( & mut self ) -> TypeRefId {
762
- self . store . types . alloc ( TypeRef :: Error )
763
- }
764
-
765
783
pub fn impl_trait_error_allocator (
766
784
ec : & mut ExprCollector < ' _ > ,
767
785
ptr : TypePtr ,
@@ -962,7 +980,7 @@ impl ExprCollector<'_> {
962
980
. lifetime_params ( )
963
981
. flat_map ( |lp| lp. lifetime ( ) . map ( |lt| Name :: new_lifetime ( & lt. text ( ) ) ) )
964
982
. collect ( ) ,
965
- None => Box :: default ( ) ,
983
+ None => ThinVec :: default ( ) ,
966
984
} ;
967
985
let path = for_type. ty ( ) . and_then ( |ty| match & ty {
968
986
ast:: Type :: PathType ( path_type) => {
0 commit comments