1- use rustc_errors:: {
2- fluent, AddToDiagnostic , Applicability , Diagnostic , DiagnosticArgFromDisplay ,
3- SubdiagnosticMessage ,
4- } ;
1+ use rustc_errors:: DiagnosticArgFromDisplay ;
52use rustc_macros:: { Diagnostic , Subdiagnostic } ;
63use rustc_span:: { symbol:: Ident , Span , Symbol } ;
74
@@ -15,25 +12,15 @@ pub struct GenericTypeWithParentheses {
1512 pub sub : Option < UseAngleBrackets > ,
1613}
1714
18- #[ derive( Clone , Copy ) ]
15+ #[ derive( Clone , Copy , Subdiagnostic ) ]
16+ #[ multipart_suggestion( ast_lowering:: use_angle_brackets, applicability = "maybe-incorrect" ) ]
1917pub struct UseAngleBrackets {
18+ #[ suggestion_part( code = "<" ) ]
2019 pub open_param : Span ,
20+ #[ suggestion_part( code = ">" ) ]
2121 pub close_param : Span ,
2222}
2323
24- impl AddToDiagnostic for UseAngleBrackets {
25- fn add_to_diagnostic_with < F > ( self , diag : & mut Diagnostic , _: F )
26- where
27- F : Fn ( & mut Diagnostic , SubdiagnosticMessage ) -> SubdiagnosticMessage ,
28- {
29- diag. multipart_suggestion (
30- fluent:: ast_lowering:: use_angle_brackets,
31- vec ! [ ( self . open_param, String :: from( "<" ) ) , ( self . close_param, String :: from( ">" ) ) ] ,
32- Applicability :: MaybeIncorrect ,
33- ) ;
34- }
35- }
36-
3724#[ derive( Diagnostic ) ]
3825#[ diag( ast_lowering:: invalid_abi, code = "E0703" ) ]
3926#[ note]
@@ -68,30 +55,20 @@ pub struct AssocTyParentheses {
6855 pub sub : AssocTyParenthesesSub ,
6956}
7057
71- #[ derive( Clone , Copy ) ]
58+ #[ derive( Clone , Copy , Subdiagnostic ) ]
7259pub enum AssocTyParenthesesSub {
73- Empty { parentheses_span : Span } ,
74- NotEmpty { open_param : Span , close_param : Span } ,
75- }
76-
77- impl AddToDiagnostic for AssocTyParenthesesSub {
78- fn add_to_diagnostic_with < F > ( self , diag : & mut Diagnostic , _: F )
79- where
80- F : Fn ( & mut Diagnostic , SubdiagnosticMessage ) -> SubdiagnosticMessage ,
81- {
82- match self {
83- Self :: Empty { parentheses_span } => diag. multipart_suggestion (
84- fluent:: ast_lowering:: remove_parentheses,
85- vec ! [ ( parentheses_span, String :: new( ) ) ] ,
86- Applicability :: MaybeIncorrect ,
87- ) ,
88- Self :: NotEmpty { open_param, close_param } => diag. multipart_suggestion (
89- fluent:: ast_lowering:: use_angle_brackets,
90- vec ! [ ( open_param, String :: from( "<" ) ) , ( close_param, String :: from( ">" ) ) ] ,
91- Applicability :: MaybeIncorrect ,
92- ) ,
93- } ;
94- }
60+ #[ multipart_suggestion( ast_lowering:: remove_parentheses) ]
61+ Empty {
62+ #[ suggestion_part( code = "" ) ]
63+ parentheses_span : Span ,
64+ } ,
65+ #[ multipart_suggestion( ast_lowering:: use_angle_brackets) ]
66+ NotEmpty {
67+ #[ suggestion_part( code = "<" ) ]
68+ open_param : Span ,
69+ #[ suggestion_part( code = ">" ) ]
70+ close_param : Span ,
71+ } ,
9572}
9673
9774#[ derive( Diagnostic ) ]
0 commit comments