@@ -64,6 +64,7 @@ struct BoundVarContext<'a, 'tcx> {
64
64
tcx : TyCtxt < ' tcx > ,
65
65
rbv : & ' a mut ResolveBoundVars ,
66
66
scope : ScopeRef < ' a > ,
67
+ is_ref : bool ,
67
68
}
68
69
69
70
#[ derive( Debug ) ]
@@ -245,8 +246,12 @@ pub(crate) fn provide(providers: &mut Providers) {
245
246
#[ instrument( level = "debug" , skip( tcx) ) ]
246
247
fn resolve_bound_vars ( tcx : TyCtxt < ' _ > , local_def_id : hir:: OwnerId ) -> ResolveBoundVars {
247
248
let mut rbv = ResolveBoundVars :: default ( ) ;
248
- let mut visitor =
249
- BoundVarContext { tcx, rbv : & mut rbv, scope : & Scope :: Root { opt_parent_item : None } } ;
249
+ let mut visitor = BoundVarContext {
250
+ tcx,
251
+ rbv : & mut rbv,
252
+ scope : & Scope :: Root { opt_parent_item : None } ,
253
+ is_ref : false ,
254
+ } ;
250
255
match tcx. hir_owner_node ( local_def_id) {
251
256
hir:: OwnerNode :: Item ( item) => visitor. visit_item ( item) ,
252
257
hir:: OwnerNode :: ForeignItem ( item) => visitor. visit_foreign_item ( item) ,
@@ -648,7 +653,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
648
653
match * arg {
649
654
hir:: PreciseCapturingArg :: Lifetime ( lt) => match lt. res {
650
655
LifetimeName :: Param ( def_id) => {
651
- self . resolve_lifetime_ref ( def_id, lt) ;
656
+ self . resolve_lifetime_ref ( def_id, lt, false ) ;
652
657
}
653
658
LifetimeName :: Error => { }
654
659
LifetimeName :: ImplicitObjectLifetimeDefault
@@ -701,6 +706,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
701
706
702
707
#[ instrument( level = "debug" , skip( self ) ) ]
703
708
fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty < ' tcx , AmbigArg > ) {
709
+ let old_is_ref = self . is_ref ;
710
+
704
711
match ty. kind {
705
712
hir:: TyKind :: BareFn ( c) => {
706
713
let ( mut bound_vars, binders) : ( FxIndexMap < LocalDefId , ResolvedArg > , Vec < _ > ) = c
@@ -797,6 +804,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
797
804
}
798
805
}
799
806
hir:: TyKind :: Ref ( lifetime_ref, ref mt) => {
807
+ self . is_ref = true ;
800
808
self . visit_lifetime ( lifetime_ref) ;
801
809
let scope = Scope :: ObjectLifetimeDefault {
802
810
lifetime : self . rbv . defs . get ( & lifetime_ref. hir_id . local_id ) . cloned ( ) ,
@@ -821,6 +829,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
821
829
}
822
830
_ => intravisit:: walk_ty ( self , ty) ,
823
831
}
832
+
833
+ self . is_ref = old_is_ref;
824
834
}
825
835
826
836
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -878,7 +888,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
878
888
self . insert_lifetime ( lifetime_ref, ResolvedArg :: StaticLifetime )
879
889
}
880
890
hir:: LifetimeName :: Param ( param_def_id) => {
881
- self . resolve_lifetime_ref ( param_def_id, lifetime_ref)
891
+ self . resolve_lifetime_ref ( param_def_id, lifetime_ref, self . is_ref )
882
892
}
883
893
// If we've already reported an error, just ignore `lifetime_ref`.
884
894
hir:: LifetimeName :: Error => { }
@@ -888,6 +898,9 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
888
898
}
889
899
890
900
fn visit_path ( & mut self , path : & hir:: Path < ' tcx > , hir_id : HirId ) {
901
+ let old_is_ref = self . is_ref ;
902
+ self . is_ref = false ;
903
+
891
904
for ( i, segment) in path. segments . iter ( ) . enumerate ( ) {
892
905
let depth = path. segments . len ( ) - i - 1 ;
893
906
if let Some ( args) = segment. args {
@@ -897,6 +910,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
897
910
if let Res :: Def ( DefKind :: TyParam | DefKind :: ConstParam , param_def_id) = path. res {
898
911
self . resolve_type_ref ( param_def_id. expect_local ( ) , hir_id) ;
899
912
}
913
+
914
+ self . is_ref = old_is_ref;
900
915
}
901
916
902
917
fn visit_fn (
@@ -1092,7 +1107,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1092
1107
F : for < ' b > FnOnce ( & mut BoundVarContext < ' b , ' tcx > ) ,
1093
1108
{
1094
1109
let BoundVarContext { tcx, rbv, .. } = self ;
1095
- let mut this = BoundVarContext { tcx : * tcx, rbv, scope : & wrap_scope } ;
1110
+ let mut this = BoundVarContext { tcx : * tcx, rbv, scope : & wrap_scope, is_ref : false } ;
1096
1111
let span = debug_span ! ( "scope" , scope = ?this. scope. debug_truncated( ) ) ;
1097
1112
{
1098
1113
let _enter = span. enter ( ) ;
@@ -1201,6 +1216,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1201
1216
& mut self ,
1202
1217
region_def_id : LocalDefId ,
1203
1218
lifetime_ref : & ' tcx hir:: Lifetime ,
1219
+ is_ref : bool ,
1204
1220
) {
1205
1221
// Walk up the scope chain, tracking the number of fn scopes
1206
1222
// that we pass through, until we find a lifetime with the
@@ -1266,7 +1282,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1266
1282
( generics. span , "<'a>" . to_owned ( ) )
1267
1283
} ;
1268
1284
1269
- let lifetime_sugg = lifetime_ref. suggestion ( "'a" ) ;
1285
+ let lifetime_sugg = lifetime_ref. suggestion ( "'a" , is_ref ) ;
1270
1286
let suggestions = vec ! [ lifetime_sugg, new_param_sugg] ;
1271
1287
1272
1288
diag. span_label (
0 commit comments