@@ -3,10 +3,7 @@ use std::num::NonZeroU32;
3
3
use rustc_errors:: { fluent, AddToDiagnostic , Applicability , DecorateLint , DiagnosticMessage } ;
4
4
use rustc_hir:: def_id:: DefId ;
5
5
use 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 } ;
10
7
use rustc_span:: { edition:: Edition , symbol:: Ident , Span , Symbol } ;
11
8
12
9
use crate :: { errors:: OverruledAttributeSub , LateContext } ;
@@ -80,6 +77,7 @@ pub struct BuiltinMissingDebugImpl<'a> {
80
77
pub def_id : DefId ,
81
78
}
82
79
80
+ // Needed for def_path_str
83
81
impl < ' a > DecorateLint < ' a , ( ) > for BuiltinMissingDebugImpl < ' _ > {
84
82
fn decorate_lint < ' b > (
85
83
self ,
@@ -225,31 +223,24 @@ pub struct BuiltinExplicitOutlivesSuggestion {
225
223
pub applicability : Applicability ,
226
224
}
227
225
226
+ #[ derive( LintDiagnostic ) ]
227
+ #[ diag( lint_builtin_incomplete_features) ]
228
228
pub struct BuiltinIncompleteFeatures {
229
229
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 > ,
232
234
}
233
235
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 ;
249
239
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 ,
253
244
}
254
245
255
246
// FIXME: migrate "the type `{}` does not permit {}"
@@ -308,29 +299,19 @@ pub struct EnumIntrinsicsMemVariant<'a> {
308
299
}
309
300
310
301
// 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 < ( ) > ,
313
309
}
314
310
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 ,
334
315
}
335
316
336
317
// for_loops_over_fallibles.rs
@@ -511,59 +492,37 @@ pub struct DeprecatedLintName<'a> {
511
492
pub replace : & ' a str ,
512
493
}
513
494
495
+ // FIXME: Non-translatable msg
496
+ #[ derive( LintDiagnostic ) ]
497
+ #[ diag( lint_renamed_or_removed_lint) ]
514
498
pub struct RenamedOrRemovedLint < ' a > {
515
499
pub msg : & ' a str ,
516
- pub suggestion : Span ,
517
- pub renamed : & ' a Option < String > ,
500
+ # [ subdiagnostic ]
501
+ pub suggestion : Option < RenamedOrRemovedLintSuggestion < ' a > > ,
518
502
}
519
503
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 ,
539
510
}
540
511
541
- pub struct UnknownLint < ' a > {
512
+ #[ derive( LintDiagnostic ) ]
513
+ #[ diag( lint_unknown_lint) ]
514
+ pub struct UnknownLint {
542
515
pub name : String ,
543
- pub suggestion : Span ,
544
- pub replace : & ' a Option < Symbol > ,
516
+ # [ subdiagnostic ]
517
+ pub suggestion : Option < UnknownLintSuggestion > ,
545
518
}
546
519
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 ,
567
526
}
568
527
569
528
#[ derive( LintDiagnostic ) ]
@@ -618,6 +577,7 @@ pub struct NonFmtPanicUnused {
618
577
pub suggestion : Option < Span > ,
619
578
}
620
579
580
+ // Used because of two suggestions based on one Option<Span>
621
581
impl < ' a > DecorateLint < ' a , ( ) > for NonFmtPanicUnused {
622
582
fn decorate_lint < ' b > (
623
583
self ,
@@ -803,6 +763,7 @@ pub struct DropTraitConstraintsDiag<'a> {
803
763
pub def_id : DefId ,
804
764
}
805
765
766
+ // Needed for def_path_str
806
767
impl < ' a > DecorateLint < ' a , ( ) > for DropTraitConstraintsDiag < ' _ > {
807
768
fn decorate_lint < ' b > (
808
769
self ,
@@ -822,6 +783,7 @@ pub struct DropGlue<'a> {
822
783
pub def_id : DefId ,
823
784
}
824
785
786
+ // Needed for def_path_str
825
787
impl < ' a > DecorateLint < ' a , ( ) > for DropGlue < ' _ > {
826
788
fn decorate_lint < ' b > (
827
789
self ,
@@ -902,35 +864,22 @@ pub enum OverflowingBinHexSub<'a> {
902
864
Help { suggestion_ty : & ' a str } ,
903
865
}
904
866
867
+ #[ derive( LintDiagnostic ) ]
868
+ #[ diag( lint_overflowing_int) ]
869
+ #[ note]
905
870
pub struct OverflowingInt < ' a > {
906
871
pub ty : & ' a str ,
907
872
pub lit : String ,
908
873
pub min : i128 ,
909
874
pub max : u128 ,
910
- pub suggestion_ty : Option < & ' a str > ,
875
+ #[ subdiagnostic]
876
+ pub help : Option < OverflowingIntHelp < ' a > > ,
911
877
}
912
878
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 ,
934
883
}
935
884
936
885
#[ derive( LintDiagnostic ) ]
@@ -972,6 +921,7 @@ pub struct ImproperCTypes<'a> {
972
921
pub span_note : Option < Span > ,
973
922
}
974
923
924
+ // Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
975
925
impl < ' a > DecorateLint < ' a , ( ) > for ImproperCTypes < ' _ > {
976
926
fn decorate_lint < ' b > (
977
927
self ,
@@ -1074,7 +1024,7 @@ pub struct UnusedDef<'a, 'b> {
1074
1024
pub note : Option < Symbol > ,
1075
1025
}
1076
1026
1077
- // FIXME: refactor with `Option<String>` in macro
1027
+ // Needed because of def_path_str
1078
1028
impl < ' a > DecorateLint < ' a , ( ) > for UnusedDef < ' _ , ' _ > {
1079
1029
fn decorate_lint < ' b > (
1080
1030
self ,
0 commit comments