@@ -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 } ;
@@ -2611,14 +2611,49 @@ pub(crate) struct ElidedLifetimesInPaths {
2611
2611
pub subdiag : ElidedLifetimeInPathSubdiag ,
2612
2612
}
2613
2613
2614
- #[ derive( LintDiagnostic ) ]
2615
- #[ diag( lint_elided_named_lifetime) ]
2616
2614
pub ( crate ) struct ElidedNamedLifetime {
2617
- #[ label( lint_label_elided) ]
2618
2615
pub span : Span ,
2616
+ pub kind : MissingLifetimeKind ,
2619
2617
pub name : Symbol ,
2620
- #[ label( lint_label_named) ]
2621
- pub named_declaration : Option < Span > ,
2618
+ pub declaration : Option < Span > ,
2619
+ }
2620
+
2621
+ impl < G : EmissionGuarantee > LintDiagnostic < ' _ , G > for ElidedNamedLifetime {
2622
+ fn decorate_lint ( self , diag : & mut rustc_errors:: Diag < ' _ , G > ) {
2623
+ let Self { span, kind, name, declaration } = self ;
2624
+ diag. primary_message ( fluent:: lint_elided_named_lifetime) ;
2625
+ diag. arg ( "name" , name) ;
2626
+ diag. span_label ( span, fluent:: lint_label_elided) ;
2627
+ if let Some ( declaration) = declaration {
2628
+ diag. span_label ( declaration, fluent:: lint_label_named) ;
2629
+ }
2630
+ match kind {
2631
+ MissingLifetimeKind :: Underscore => diag. span_suggestion_verbose (
2632
+ span,
2633
+ fluent:: lint_suggestion,
2634
+ format ! ( "{name}" ) ,
2635
+ Applicability :: MachineApplicable ,
2636
+ ) ,
2637
+ MissingLifetimeKind :: Ampersand => diag. span_suggestion_verbose (
2638
+ span. shrink_to_hi ( ) ,
2639
+ fluent:: lint_suggestion,
2640
+ format ! ( "{name} " ) ,
2641
+ Applicability :: MachineApplicable ,
2642
+ ) ,
2643
+ MissingLifetimeKind :: Comma => diag. span_suggestion_verbose (
2644
+ span. shrink_to_hi ( ) ,
2645
+ fluent:: lint_suggestion,
2646
+ format ! ( "{name}, " ) ,
2647
+ Applicability :: MachineApplicable ,
2648
+ ) ,
2649
+ MissingLifetimeKind :: Brackets => diag. span_suggestion_verbose (
2650
+ span. shrink_to_hi ( ) ,
2651
+ fluent:: lint_suggestion,
2652
+ format ! ( "<{name}>" ) ,
2653
+ Applicability :: MachineApplicable ,
2654
+ ) ,
2655
+ } ;
2656
+ }
2622
2657
}
2623
2658
2624
2659
#[ derive( LintDiagnostic ) ]
0 commit comments