@@ -148,11 +148,11 @@ enum LifetimeSyntaxCategory {
148148}
149149
150150impl LifetimeSyntaxCategory {
151- fn new ( syntax_source : ( hir:: LifetimeSyntax , LifetimeSource ) ) -> Option < Self > {
151+ fn new ( lifetime : & hir:: Lifetime ) -> Option < Self > {
152152 use LifetimeSource :: * ;
153153 use hir:: LifetimeSyntax :: * ;
154154
155- match syntax_source {
155+ match ( lifetime . syntax , lifetime . source ) {
156156 // E.g. `&T`.
157157 ( Implicit , Reference ) |
158158 // E.g. `&'_ T`.
@@ -233,22 +233,8 @@ impl std::ops::Add for LifetimeSyntaxCategories<usize> {
233233}
234234
235235fn lifetimes_use_matched_syntax ( input_info : & [ Info < ' _ > ] , output_info : & [ Info < ' _ > ] ) -> bool {
236- let mut syntax_counts = LifetimeSyntaxCategories :: < usize > :: default ( ) ;
237-
238- for info in input_info. iter ( ) . chain ( output_info) {
239- if let Some ( category) = info. lifetime_syntax_category ( ) {
240- * syntax_counts. select ( category) += 1 ;
241- }
242- }
243-
244- tracing:: debug!( ?syntax_counts) ;
245-
246- matches ! (
247- syntax_counts,
248- LifetimeSyntaxCategories { hidden: _, elided: 0 , named: 0 }
249- | LifetimeSyntaxCategories { hidden: 0 , elided: _, named: 0 }
250- | LifetimeSyntaxCategories { hidden: 0 , elided: 0 , named: _ }
251- )
236+ let ( first, inputs) = input_info. split_first ( ) . unwrap ( ) ;
237+ std:: iter:: chain ( inputs, output_info) . all ( |info| info. syntax_category == first. syntax_category )
252238}
253239
254240fn emit_mismatch_diagnostic < ' tcx > (
@@ -312,11 +298,6 @@ fn emit_mismatch_diagnostic<'tcx>(
312298
313299 let syntax_source = info. syntax_source ( ) ;
314300
315- if let ( _, Other ) = syntax_source {
316- // Ignore any other kind of lifetime.
317- continue ;
318- }
319-
320301 if let ( ExplicitBound , _) = syntax_source {
321302 bound_lifetime = Some ( info) ;
322303 }
@@ -393,9 +374,7 @@ fn emit_mismatch_diagnostic<'tcx>(
393374 let categorize = |infos : & [ Info < ' _ > ] | {
394375 let mut categories = LifetimeSyntaxCategories :: < Vec < _ > > :: default ( ) ;
395376 for info in infos {
396- if let Some ( category) = info. lifetime_syntax_category ( ) {
397- categories. select ( category) . push ( info. reporting_span ( ) ) ;
398- }
377+ categories. select ( info. syntax_category ) . push ( info. reporting_span ( ) ) ;
399378 }
400379 categories
401380 } ;
@@ -518,6 +497,7 @@ fn build_mismatch_suggestion(
518497#[ derive( Debug ) ]
519498struct Info < ' tcx > {
520499 lifetime : & ' tcx hir:: Lifetime ,
500+ syntax_category : LifetimeSyntaxCategory ,
521501 ty : & ' tcx hir:: Ty < ' tcx > ,
522502}
523503
@@ -526,10 +506,6 @@ impl<'tcx> Info<'tcx> {
526506 ( self . lifetime . syntax , self . lifetime . source )
527507 }
528508
529- fn lifetime_syntax_category ( & self ) -> Option < LifetimeSyntaxCategory > {
530- LifetimeSyntaxCategory :: new ( self . syntax_source ( ) )
531- }
532-
533509 fn lifetime_name ( & self ) -> & str {
534510 self . lifetime . ident . as_str ( )
535511 }
@@ -589,8 +565,10 @@ impl<'a, 'tcx> LifetimeInfoCollector<'a, 'tcx> {
589565impl < ' a , ' tcx > Visitor < ' tcx > for LifetimeInfoCollector < ' a , ' tcx > {
590566 #[ instrument( skip( self ) ) ]
591567 fn visit_lifetime ( & mut self , lifetime : & ' tcx hir:: Lifetime ) {
592- let info = Info { lifetime, ty : self . ty } ;
593- self . map . entry ( & lifetime. kind ) . or_default ( ) . push ( info) ;
568+ if let Some ( syntax_category) = LifetimeSyntaxCategory :: new ( lifetime) {
569+ let info = Info { lifetime, syntax_category, ty : self . ty } ;
570+ self . map . entry ( & lifetime. kind ) . or_default ( ) . push ( info) ;
571+ }
594572 }
595573
596574 #[ instrument( skip( self ) ) ]
0 commit comments