@@ -147,56 +147,67 @@ pub enum SourceKindSubdiag<'a> {
147
147
} ,
148
148
}
149
149
150
- // Has to be implemented manually because multipart suggestions are not supported by the derive macro.
151
- // Would be a part of `SourceKindSubdiag` otherwise.
150
+ #[ derive( SessionSubdiagnostic ) ]
152
151
pub enum SourceKindMultiSuggestion < ' a > {
152
+ #[ multipart_suggestion_verbose(
153
+ infer:: source_kind_fully_qualified,
154
+ applicability = "has-placeholders"
155
+ ) ]
153
156
FullyQualified {
154
- span : Span ,
157
+ #[ suggestion_part( code = "{def_path}({adjustment}" ) ]
158
+ span_lo : Span ,
159
+ #[ suggestion_part( code = "{successor_pos}" ) ]
160
+ span_hi : Span ,
155
161
def_path : String ,
156
162
adjustment : & ' a str ,
157
- successor : ( & ' a str , BytePos ) ,
163
+ successor_pos : & ' a str ,
158
164
} ,
165
+ #[ multipart_suggestion_verbose(
166
+ infer:: source_kind_closure_return,
167
+ applicability = "has-placeholders"
168
+ ) ]
159
169
ClosureReturn {
160
- ty_info : String ,
161
- data : & ' a FnRetTy < ' a > ,
162
- should_wrap_expr : Option < Span > ,
170
+ #[ suggestion_part( code = "{start_span_code}" ) ]
171
+ start_span : Span ,
172
+ start_span_code : String ,
173
+ #[ suggestion_part( code = "}}" ) ]
174
+ end_span : Option < Span > ,
163
175
} ,
164
176
}
165
177
166
- impl AddSubdiagnostic for SourceKindMultiSuggestion < ' _ > {
167
- fn add_to_diagnostic ( self , diag : & mut rustc_errors:: Diagnostic ) {
168
- match self {
169
- Self :: FullyQualified { span, def_path, adjustment, successor } => {
170
- let suggestion = vec ! [
171
- ( span. shrink_to_lo( ) , format!( "{def_path}({adjustment}" ) ) ,
172
- ( span. shrink_to_hi( ) . with_hi( successor. 1 ) , successor. 0 . to_string( ) ) ,
173
- ] ;
174
- diag. multipart_suggestion_verbose (
175
- fluent:: infer:: source_kind_fully_qualified,
176
- suggestion,
177
- rustc_errors:: Applicability :: HasPlaceholders ,
178
- ) ;
179
- }
180
- Self :: ClosureReturn { ty_info, data, should_wrap_expr } => {
181
- let ( arrow, post) = match data {
182
- FnRetTy :: DefaultReturn ( _) => ( "-> " , " " ) ,
183
- _ => ( "" , "" ) ,
184
- } ;
185
- let suggestion = match should_wrap_expr {
186
- Some ( end_span) => vec ! [
187
- ( data. span( ) , format!( "{}{}{}{{ " , arrow, ty_info, post) ) ,
188
- ( end_span, " }" . to_string( ) ) ,
189
- ] ,
190
- None => vec ! [ ( data. span( ) , format!( "{}{}{}" , arrow, ty_info, post) ) ] ,
191
- } ;
192
- diag. multipart_suggestion_verbose (
193
- fluent:: infer:: source_kind_closure_return,
194
- suggestion,
195
- rustc_errors:: Applicability :: HasPlaceholders ,
196
- ) ;
197
- }
178
+ impl < ' a > SourceKindMultiSuggestion < ' a > {
179
+ pub fn new_fully_qualified (
180
+ span : Span ,
181
+ def_path : String ,
182
+ adjustment : & ' a str ,
183
+ successor : ( & ' a str , BytePos ) ,
184
+ ) -> Self {
185
+ Self :: FullyQualified {
186
+ span_lo : span. shrink_to_lo ( ) ,
187
+ span_hi : span. shrink_to_hi ( ) . with_hi ( successor. 1 ) ,
188
+ def_path,
189
+ adjustment,
190
+ successor_pos : successor. 0 ,
198
191
}
199
192
}
193
+
194
+ pub fn new_closure_return (
195
+ ty_info : String ,
196
+ data : & ' a FnRetTy < ' a > ,
197
+ should_wrap_expr : Option < Span > ,
198
+ ) -> Self {
199
+ let ( arrow, post) = match data {
200
+ FnRetTy :: DefaultReturn ( _) => ( "-> " , " " ) ,
201
+ _ => ( "" , "" ) ,
202
+ } ;
203
+ let ( start_span, start_span_code, end_span) = match should_wrap_expr {
204
+ Some ( end_span) => {
205
+ ( data. span ( ) , format ! ( "{}{}{}{{ " , arrow, ty_info, post) , Some ( end_span) )
206
+ }
207
+ None => ( data. span ( ) , format ! ( "{}{}{}" , arrow, ty_info, post) , None ) ,
208
+ } ;
209
+ Self :: ClosureReturn { start_span, start_span_code, end_span }
210
+ }
200
211
}
201
212
202
213
pub enum RegionOriginNote < ' a > {
0 commit comments