1
- use rustc_errors:: {
2
- fluent, AddToDiagnostic , Applicability , Diagnostic , DiagnosticArgFromDisplay ,
3
- SubdiagnosticMessage ,
4
- } ;
1
+ use rustc_errors:: DiagnosticArgFromDisplay ;
5
2
use rustc_macros:: { Diagnostic , Subdiagnostic } ;
6
3
use rustc_span:: { symbol:: Ident , Span , Symbol } ;
7
4
@@ -15,25 +12,15 @@ pub struct GenericTypeWithParentheses {
15
12
pub sub : Option < UseAngleBrackets > ,
16
13
}
17
14
18
- #[ derive( Clone , Copy ) ]
15
+ #[ derive( Clone , Copy , Subdiagnostic ) ]
16
+ #[ multipart_suggestion( ast_lowering:: use_angle_brackets, applicability = "maybe-incorrect" ) ]
19
17
pub struct UseAngleBrackets {
18
+ #[ suggestion_part( code = "<" ) ]
20
19
pub open_param : Span ,
20
+ #[ suggestion_part( code = ">" ) ]
21
21
pub close_param : Span ,
22
22
}
23
23
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
-
37
24
#[ derive( Diagnostic ) ]
38
25
#[ diag( ast_lowering:: invalid_abi, code = "E0703" ) ]
39
26
#[ note]
@@ -68,30 +55,20 @@ pub struct AssocTyParentheses {
68
55
pub sub : AssocTyParenthesesSub ,
69
56
}
70
57
71
- #[ derive( Clone , Copy ) ]
58
+ #[ derive( Clone , Copy , Subdiagnostic ) ]
72
59
pub 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
+ } ,
95
72
}
96
73
97
74
#[ derive( Diagnostic ) ]
0 commit comments