@@ -9,7 +9,7 @@ use rustc_errors::{
9
9
} ;
10
10
use rustc_hir:: def:: Namespace ;
11
11
use rustc_hir:: def_id:: DefId ;
12
- use rustc_hir:: { self as hir} ;
12
+ use rustc_hir:: { self as hir, MissingLifetimeKind } ;
13
13
use rustc_macros:: { LintDiagnostic , Subdiagnostic } ;
14
14
use rustc_middle:: ty:: inhabitedness:: InhabitedPredicate ;
15
15
use rustc_middle:: ty:: { Clause , PolyExistentialTraitRef , Ty , TyCtxt } ;
@@ -2623,14 +2623,49 @@ pub(crate) struct ElidedLifetimesInPaths {
2623
2623
pub subdiag : ElidedLifetimeInPathSubdiag ,
2624
2624
}
2625
2625
2626
- #[ derive( LintDiagnostic ) ]
2627
- #[ diag( lint_elided_named_lifetime) ]
2628
2626
pub ( crate ) struct ElidedNamedLifetime {
2629
- #[ label( lint_label_elided) ]
2630
2627
pub span : Span ,
2628
+ pub kind : MissingLifetimeKind ,
2631
2629
pub name : Symbol ,
2632
- #[ label( lint_label_named) ]
2633
- pub named_declaration : Option < Span > ,
2630
+ pub declaration : Option < Span > ,
2631
+ }
2632
+
2633
+ impl < G : EmissionGuarantee > LintDiagnostic < ' _ , G > for ElidedNamedLifetime {
2634
+ fn decorate_lint ( self , diag : & mut rustc_errors:: Diag < ' _ , G > ) {
2635
+ let Self { span, kind, name, declaration } = self ;
2636
+ diag. primary_message ( fluent:: lint_elided_named_lifetime) ;
2637
+ diag. arg ( "name" , name) ;
2638
+ diag. span_label ( span, fluent:: lint_label_elided) ;
2639
+ if let Some ( declaration) = declaration {
2640
+ diag. span_label ( declaration, fluent:: lint_label_named) ;
2641
+ }
2642
+ match kind {
2643
+ MissingLifetimeKind :: Underscore => diag. span_suggestion_verbose (
2644
+ span,
2645
+ fluent:: lint_suggestion,
2646
+ format ! ( "{name}" ) ,
2647
+ Applicability :: MachineApplicable ,
2648
+ ) ,
2649
+ MissingLifetimeKind :: Ampersand => diag. span_suggestion_verbose (
2650
+ span. shrink_to_hi ( ) ,
2651
+ fluent:: lint_suggestion,
2652
+ format ! ( "{name} " ) ,
2653
+ Applicability :: MachineApplicable ,
2654
+ ) ,
2655
+ MissingLifetimeKind :: Comma => diag. span_suggestion_verbose (
2656
+ span. shrink_to_hi ( ) ,
2657
+ fluent:: lint_suggestion,
2658
+ format ! ( "{name}, " ) ,
2659
+ Applicability :: MachineApplicable ,
2660
+ ) ,
2661
+ MissingLifetimeKind :: Brackets => diag. span_suggestion_verbose (
2662
+ span. shrink_to_hi ( ) ,
2663
+ fluent:: lint_suggestion,
2664
+ format ! ( "<{name}>" ) ,
2665
+ Applicability :: MachineApplicable ,
2666
+ ) ,
2667
+ } ;
2668
+ }
2634
2669
}
2635
2670
2636
2671
#[ derive( LintDiagnostic ) ]
0 commit comments