@@ -517,9 +517,8 @@ fn build_mismatch_suggestion(
517517
518518#[ derive( Debug ) ]
519519struct Info < ' tcx > {
520- type_span : Span ,
521- referenced_type_span : Option < Span > ,
522520 lifetime : & ' tcx hir:: Lifetime ,
521+ ty : & ' tcx hir:: Ty < ' tcx > ,
523522}
524523
525524impl < ' tcx > Info < ' tcx > {
@@ -543,7 +542,7 @@ impl<'tcx> Info<'tcx> {
543542 /// to include the type. Otherwise we end up pointing at nothing,
544543 /// which is a bit confusing.
545544 fn reporting_span ( & self ) -> Span {
546- if self . lifetime . is_implicit ( ) { self . type_span } else { self . lifetime . ident . span }
545+ if self . lifetime . is_implicit ( ) { self . ty . span } else { self . lifetime . ident . span }
547546 }
548547
549548 /// When removing an explicit lifetime from a reference,
@@ -561,11 +560,9 @@ impl<'tcx> Info<'tcx> {
561560 // FIXME: Ideally, we'd also remove the lifetime declaration.
562561 fn removing_span ( & self ) -> Span {
563562 let mut span = self . suggestion ( "'dummy" ) . 0 ;
564-
565- if let Some ( referenced_type_span) = self . referenced_type_span {
566- span = span. until ( referenced_type_span) ;
563+ if let hir:: TyKind :: Ref ( _, mut_ty) = self . ty . kind {
564+ span = span. until ( mut_ty. ty . span ) ;
567565 }
568-
569566 span
570567 }
571568
@@ -577,14 +574,13 @@ impl<'tcx> Info<'tcx> {
577574type LifetimeInfoMap < ' tcx > = FxIndexMap < & ' tcx hir:: LifetimeKind , Vec < Info < ' tcx > > > ;
578575
579576struct LifetimeInfoCollector < ' a , ' tcx > {
580- type_span : Span ,
581- referenced_type_span : Option < Span > ,
582577 map : & ' a mut LifetimeInfoMap < ' tcx > ,
578+ ty : & ' tcx hir:: Ty < ' tcx > ,
583579}
584580
585581impl < ' a , ' tcx > LifetimeInfoCollector < ' a , ' tcx > {
586582 fn collect ( ty : & ' tcx hir:: Ty < ' tcx > , map : & ' a mut LifetimeInfoMap < ' tcx > ) {
587- let mut this = Self { type_span : ty . span , referenced_type_span : None , map } ;
583+ let mut this = Self { map , ty } ;
588584
589585 intravisit:: walk_unambig_ty ( & mut this, ty) ;
590586 }
@@ -593,27 +589,14 @@ impl<'a, 'tcx> LifetimeInfoCollector<'a, 'tcx> {
593589impl < ' a , ' tcx > Visitor < ' tcx > for LifetimeInfoCollector < ' a , ' tcx > {
594590 #[ instrument( skip( self ) ) ]
595591 fn visit_lifetime ( & mut self , lifetime : & ' tcx hir:: Lifetime ) {
596- let type_span = self . type_span ;
597- let referenced_type_span = self . referenced_type_span ;
598-
599- let info = Info { type_span, referenced_type_span, lifetime } ;
600-
592+ let info = Info { lifetime, ty : self . ty } ;
601593 self . map . entry ( & lifetime. kind ) . or_default ( ) . push ( info) ;
602594 }
603595
604596 #[ instrument( skip( self ) ) ]
605597 fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty < ' tcx , hir:: AmbigArg > ) -> Self :: Result {
606- let old_type_span = self . type_span ;
607- let old_referenced_type_span = self . referenced_type_span ;
608-
609- self . type_span = ty. span ;
610- if let hir:: TyKind :: Ref ( _, ty) = ty. kind {
611- self . referenced_type_span = Some ( ty. ty . span ) ;
612- }
613-
598+ let old_ty = std:: mem:: replace ( & mut self . ty , ty. as_unambig_ty ( ) ) ;
614599 intravisit:: walk_ty ( self , ty) ;
615-
616- self . type_span = old_type_span;
617- self . referenced_type_span = old_referenced_type_span;
600+ self . ty = old_ty;
618601 }
619602}
0 commit comments