@@ -459,47 +459,34 @@ impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
459459 }
460460}
461461
462- pub struct ImplNote {
463- pub impl_span : Option < Span > ,
464- }
465-
466- impl AddToDiagnostic for ImplNote {
467- fn add_to_diagnostic_with < F > ( self , diag : & mut Diagnostic , _: F )
468- where
469- F : Fn ( & mut Diagnostic , SubdiagnosticMessage ) -> SubdiagnosticMessage ,
470- {
471- match self . impl_span {
472- Some ( span) => diag. span_note ( span, fluent:: infer:: msl_impl_note) ,
473- None => diag. note ( fluent:: infer:: msl_impl_note) ,
474- } ;
475- }
476- }
477-
478- pub enum TraitSubdiag {
479- Note { span : Span } ,
480- Sugg { span : Span } ,
462+ // FIXME(#100717): replace with a `Option<Span>` when subdiagnostic supports that
463+ #[ derive( Subdiagnostic ) ]
464+ pub enum DoesNotOutliveStaticFromImpl {
465+ #[ note( infer:: does_not_outlive_static_from_impl) ]
466+ Spanned {
467+ #[ primary_span]
468+ span : Span ,
469+ } ,
470+ #[ note( infer:: does_not_outlive_static_from_impl) ]
471+ Unspanned ,
481472}
482473
483- // FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support
484- impl AddToDiagnostic for TraitSubdiag {
485- fn add_to_diagnostic_with < F > ( self , diag : & mut Diagnostic , _: F )
486- where
487- F : Fn ( & mut Diagnostic , SubdiagnosticMessage ) -> SubdiagnosticMessage ,
488- {
489- match self {
490- TraitSubdiag :: Note { span } => {
491- diag. span_note ( span, "this has an implicit `'static` lifetime requirement" ) ;
492- }
493- TraitSubdiag :: Sugg { span } => {
494- diag. span_suggestion_verbose (
495- span,
496- "consider relaxing the implicit `'static` requirement" ,
497- " + '_" . to_owned ( ) ,
498- rustc_errors:: Applicability :: MaybeIncorrect ,
499- ) ;
500- }
501- }
502- }
474+ #[ derive( Subdiagnostic ) ]
475+ pub enum ImplicitStaticLifetimeSubdiag {
476+ #[ note( infer:: implicit_static_lifetime_note) ]
477+ Note {
478+ #[ primary_span]
479+ span : Span ,
480+ } ,
481+ #[ suggestion_verbose(
482+ infer:: implicit_static_lifetime_suggestion,
483+ code = " + '_" ,
484+ applicability = "maybe-incorrect"
485+ ) ]
486+ Sugg {
487+ #[ primary_span]
488+ span : Span ,
489+ } ,
503490}
504491
505492#[ derive( Diagnostic ) ]
@@ -512,7 +499,7 @@ pub struct MismatchedStaticLifetime<'a> {
512499 #[ subdiagnostic]
513500 pub expl : Option < note_and_explain:: RegionExplanation < ' a > > ,
514501 #[ subdiagnostic]
515- pub impl_note : ImplNote ,
516- #[ subdiagnostic]
517- pub trait_subdiags : Vec < TraitSubdiag > ,
502+ pub does_not_outlive_static_from_impl : DoesNotOutliveStaticFromImpl ,
503+ #[ subdiagnostic( eager ) ]
504+ pub implicit_static_lifetimes : Vec < ImplicitStaticLifetimeSubdiag > ,
518505}
0 commit comments