@@ -3,10 +3,7 @@ use std::num::NonZeroU32;
33use rustc_errors:: { fluent, AddToDiagnostic , Applicability , DecorateLint , DiagnosticMessage } ;
44use rustc_hir:: def_id:: DefId ;
55use rustc_macros:: { LintDiagnostic , Subdiagnostic } ;
6- use rustc_middle:: {
7- lint:: LintExpectation ,
8- ty:: { Predicate , Ty , TyCtxt } ,
9- } ;
6+ use rustc_middle:: ty:: { Predicate , Ty , TyCtxt } ;
107use rustc_span:: { edition:: Edition , symbol:: Ident , Span , Symbol } ;
118
129use crate :: { errors:: OverruledAttributeSub , LateContext } ;
@@ -80,6 +77,7 @@ pub struct BuiltinMissingDebugImpl<'a> {
8077 pub def_id : DefId ,
8178}
8279
80+ // Needed for def_path_str
8381impl < ' a > DecorateLint < ' a , ( ) > for BuiltinMissingDebugImpl < ' _ > {
8482 fn decorate_lint < ' b > (
8583 self ,
@@ -225,31 +223,24 @@ pub struct BuiltinExplicitOutlivesSuggestion {
225223 pub applicability : Applicability ,
226224}
227225
226+ #[ derive( LintDiagnostic ) ]
227+ #[ diag( lint_builtin_incomplete_features) ]
228228pub struct BuiltinIncompleteFeatures {
229229 pub name : Symbol ,
230- pub note : Option < NonZeroU32 > ,
231- pub help : Option < ( ) > ,
230+ #[ subdiagnostic]
231+ pub note : Option < BuiltinIncompleteFeaturesNote > ,
232+ #[ subdiagnostic]
233+ pub help : Option < BuiltinIncompleteFeaturesHelp > ,
232234}
233235
234- impl < ' a > DecorateLint < ' a , ( ) > for BuiltinIncompleteFeatures {
235- fn decorate_lint < ' b > (
236- self ,
237- diag : & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > ,
238- ) -> & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > {
239- diag. set_arg ( "name" , self . name ) ;
240- if let Some ( n) = self . note {
241- diag. set_arg ( "n" , n) ;
242- diag. note ( fluent:: note) ;
243- }
244- if let Some ( _) = self . help {
245- diag. help ( fluent:: help) ;
246- }
247- diag
248- }
236+ #[ derive( Subdiagnostic ) ]
237+ #[ help( help) ]
238+ pub struct BuiltinIncompleteFeaturesHelp ;
249239
250- fn msg ( & self ) -> DiagnosticMessage {
251- fluent:: lint_builtin_incomplete_features
252- }
240+ #[ derive( Subdiagnostic ) ]
241+ #[ note( note) ]
242+ pub struct BuiltinIncompleteFeaturesNote {
243+ pub n : NonZeroU32 ,
253244}
254245
255246// FIXME: migrate "the type `{}` does not permit {}"
@@ -308,29 +299,19 @@ pub struct EnumIntrinsicsMemVariant<'a> {
308299}
309300
310301// expect.rs
311- pub struct Expectation < ' a > {
312- pub expectation : & ' a LintExpectation ,
302+ #[ derive( LintDiagnostic ) ]
303+ #[ diag( lint_expectation) ]
304+ pub struct Expectation {
305+ #[ subdiagnostic]
306+ pub rationale : Option < ExpectationNote > ,
307+ #[ note]
308+ pub note : Option < ( ) > ,
313309}
314310
315- impl < ' a > DecorateLint < ' a , ( ) > for Expectation < ' _ > {
316- fn decorate_lint < ' b > (
317- self ,
318- diag : & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > ,
319- ) -> & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > {
320- if let Some ( rationale) = self . expectation . reason {
321- diag. note ( rationale. as_str ( ) ) ;
322- }
323-
324- if self . expectation . is_unfulfilled_lint_expectations {
325- diag. note ( fluent:: note) ;
326- }
327-
328- diag
329- }
330-
331- fn msg ( & self ) -> DiagnosticMessage {
332- fluent:: lint_expectation
333- }
311+ #[ derive( Subdiagnostic ) ]
312+ #[ note( rationale) ]
313+ pub struct ExpectationNote {
314+ pub rationale : Symbol ,
334315}
335316
336317// for_loops_over_fallibles.rs
@@ -511,59 +492,37 @@ pub struct DeprecatedLintName<'a> {
511492 pub replace : & ' a str ,
512493}
513494
495+ // FIXME: Non-translatable msg
496+ #[ derive( LintDiagnostic ) ]
497+ #[ diag( lint_renamed_or_removed_lint) ]
514498pub struct RenamedOrRemovedLint < ' a > {
515499 pub msg : & ' a str ,
516- pub suggestion : Span ,
517- pub renamed : & ' a Option < String > ,
500+ # [ subdiagnostic ]
501+ pub suggestion : Option < RenamedOrRemovedLintSuggestion < ' a > > ,
518502}
519503
520- impl < ' a > DecorateLint < ' a , ( ) > for RenamedOrRemovedLint < ' _ > {
521- fn decorate_lint < ' b > (
522- self ,
523- diag : & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > ,
524- ) -> & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > {
525- if let Some ( new_name) = self . renamed {
526- diag. span_suggestion (
527- self . suggestion ,
528- fluent:: lint_renamed_or_removed_lint_suggestion,
529- new_name,
530- Applicability :: MachineApplicable ,
531- ) ;
532- } ;
533- diag
534- }
535-
536- fn msg ( & self ) -> rustc_errors:: DiagnosticMessage {
537- rustc_errors:: DiagnosticMessage :: Str ( self . msg . to_string ( ) )
538- }
504+ #[ derive( Subdiagnostic ) ]
505+ #[ suggestion( suggestion, code = "{replace}" , applicability = "machine-applicable" ) ]
506+ pub struct RenamedOrRemovedLintSuggestion < ' a > {
507+ #[ primary_span]
508+ pub suggestion : Span ,
509+ pub replace : & ' a str ,
539510}
540511
541- pub struct UnknownLint < ' a > {
512+ #[ derive( LintDiagnostic ) ]
513+ #[ diag( lint_unknown_lint) ]
514+ pub struct UnknownLint {
542515 pub name : String ,
543- pub suggestion : Span ,
544- pub replace : & ' a Option < Symbol > ,
516+ # [ subdiagnostic ]
517+ pub suggestion : Option < UnknownLintSuggestion > ,
545518}
546519
547- impl < ' a > DecorateLint < ' a , ( ) > for UnknownLint < ' _ > {
548- fn decorate_lint < ' b > (
549- self ,
550- diag : & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > ,
551- ) -> & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > {
552- diag. set_arg ( "name" , self . name ) ;
553- if let Some ( replace) = self . replace {
554- diag. span_suggestion (
555- self . suggestion ,
556- fluent:: suggestion,
557- replace,
558- Applicability :: MaybeIncorrect ,
559- ) ;
560- } ;
561- diag
562- }
563-
564- fn msg ( & self ) -> rustc_errors:: DiagnosticMessage {
565- fluent:: lint_unknown_lint
566- }
520+ #[ derive( Subdiagnostic ) ]
521+ #[ suggestion( suggestion, code = "{replace}" , applicability = "maybe-incorrect" ) ]
522+ pub struct UnknownLintSuggestion {
523+ #[ primary_span]
524+ pub suggestion : Span ,
525+ pub replace : Symbol ,
567526}
568527
569528#[ derive( LintDiagnostic ) ]
@@ -618,6 +577,7 @@ pub struct NonFmtPanicUnused {
618577 pub suggestion : Option < Span > ,
619578}
620579
580+ // Used because of two suggestions based on one Option<Span>
621581impl < ' a > DecorateLint < ' a , ( ) > for NonFmtPanicUnused {
622582 fn decorate_lint < ' b > (
623583 self ,
@@ -803,6 +763,7 @@ pub struct DropTraitConstraintsDiag<'a> {
803763 pub def_id : DefId ,
804764}
805765
766+ // Needed for def_path_str
806767impl < ' a > DecorateLint < ' a , ( ) > for DropTraitConstraintsDiag < ' _ > {
807768 fn decorate_lint < ' b > (
808769 self ,
@@ -822,6 +783,7 @@ pub struct DropGlue<'a> {
822783 pub def_id : DefId ,
823784}
824785
786+ // Needed for def_path_str
825787impl < ' a > DecorateLint < ' a , ( ) > for DropGlue < ' _ > {
826788 fn decorate_lint < ' b > (
827789 self ,
@@ -902,35 +864,22 @@ pub enum OverflowingBinHexSub<'a> {
902864 Help { suggestion_ty : & ' a str } ,
903865}
904866
867+ #[ derive( LintDiagnostic ) ]
868+ #[ diag( lint_overflowing_int) ]
869+ #[ note]
905870pub struct OverflowingInt < ' a > {
906871 pub ty : & ' a str ,
907872 pub lit : String ,
908873 pub min : i128 ,
909874 pub max : u128 ,
910- pub suggestion_ty : Option < & ' a str > ,
875+ #[ subdiagnostic]
876+ pub help : Option < OverflowingIntHelp < ' a > > ,
911877}
912878
913- // FIXME: refactor with `Option<&'a str>` in macro
914- impl < ' a > DecorateLint < ' a , ( ) > for OverflowingInt < ' _ > {
915- fn decorate_lint < ' b > (
916- self ,
917- diag : & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > ,
918- ) -> & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > {
919- diag. set_arg ( "ty" , self . ty ) ;
920- diag. set_arg ( "lit" , self . lit ) ;
921- diag. set_arg ( "min" , self . min ) ;
922- diag. set_arg ( "max" , self . max ) ;
923- diag. note ( fluent:: note) ;
924- if let Some ( suggestion_ty) = self . suggestion_ty {
925- diag. set_arg ( "suggestion_ty" , suggestion_ty) ;
926- diag. help ( fluent:: help) ;
927- }
928- diag
929- }
930-
931- fn msg ( & self ) -> rustc_errors:: DiagnosticMessage {
932- fluent:: lint_overflowing_int
933- }
879+ #[ derive( Subdiagnostic ) ]
880+ #[ help( help) ]
881+ pub struct OverflowingIntHelp < ' a > {
882+ pub suggestion_ty : & ' a str ,
934883}
935884
936885#[ derive( LintDiagnostic ) ]
@@ -972,6 +921,7 @@ pub struct ImproperCTypes<'a> {
972921 pub span_note : Option < Span > ,
973922}
974923
924+ // Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
975925impl < ' a > DecorateLint < ' a , ( ) > for ImproperCTypes < ' _ > {
976926 fn decorate_lint < ' b > (
977927 self ,
@@ -1074,7 +1024,7 @@ pub struct UnusedDef<'a, 'b> {
10741024 pub note : Option < Symbol > ,
10751025}
10761026
1077- // FIXME: refactor with `Option<String>` in macro
1027+ // Needed because of def_path_str
10781028impl < ' a > DecorateLint < ' a , ( ) > for UnusedDef < ' _ , ' _ > {
10791029 fn decorate_lint < ' b > (
10801030 self ,
0 commit comments