@@ -13,6 +13,7 @@ use std::collections::HashMap;
13
13
use syn:: { spanned:: Spanned , Attribute , Meta , MetaList , MetaNameValue , NestedMeta , Path } ;
14
14
use synstructure:: { BindingInfo , Structure , VariantInfo } ;
15
15
16
+ use super :: error:: invalid_attr;
16
17
use super :: utils:: { SpannedOption , SubdiagnosticKind } ;
17
18
18
19
/// The central struct for constructing the `add_to_diagnostic` method from an annotated struct.
@@ -271,18 +272,18 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
271
272
"skip_arg" => Ok ( quote ! { } ) ,
272
273
"primary_span" => {
273
274
if kind_stats. has_multipart_suggestion {
274
- throw_invalid_attr ! ( attr, & Meta :: Path ( path) , |diag| {
275
- diag . help(
275
+ invalid_attr ( attr, & Meta :: Path ( path) )
276
+ . help (
276
277
"multipart suggestions use one or more `#[suggestion_part]`s rather \
277
278
than one `#[primary_span]`",
278
279
)
279
- } )
280
- }
281
-
282
- report_error_if_not_applied_to_span ( attr, & info) ?;
280
+ . emit ( ) ;
281
+ } else {
282
+ report_error_if_not_applied_to_span ( attr, & info) ?;
283
283
284
- let binding = info. binding . binding . clone ( ) ;
285
- self . span_field . set_once ( binding, span) ;
284
+ let binding = info. binding . binding . clone ( ) ;
285
+ self . span_field . set_once ( binding, span) ;
286
+ }
286
287
287
288
Ok ( quote ! { } )
288
289
}
@@ -292,14 +293,16 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
292
293
if kind_stats. has_multipart_suggestion {
293
294
span_err ( span, "`#[suggestion_part(...)]` attribute without `code = \" ...\" `" )
294
295
. emit ( ) ;
295
- Ok ( quote ! { } )
296
296
} else {
297
- throw_invalid_attr ! ( attr, & Meta :: Path ( path) , |diag| {
298
- diag. help(
299
- "`#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead" ,
300
- )
301
- } ) ;
297
+ invalid_attr ( attr, & Meta :: Path ( path) )
298
+ . help (
299
+ "`#[suggestion_part(...)]` is only valid in multipart suggestions, \
300
+ use `#[primary_span]` instead",
301
+ )
302
+ . emit ( ) ;
302
303
}
304
+
305
+ Ok ( quote ! { } )
303
306
}
304
307
"applicability" => {
305
308
if kind_stats. has_multipart_suggestion || kind_stats. has_normal_suggestion {
@@ -322,19 +325,24 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
322
325
323
326
Ok ( quote ! { } )
324
327
}
325
- _ => throw_invalid_attr ! ( attr , & Meta :: Path ( path ) , |diag| {
328
+ _ => {
326
329
let mut span_attrs = vec ! [ ] ;
327
330
if kind_stats. has_multipart_suggestion {
328
331
span_attrs. push ( "suggestion_part" ) ;
329
332
}
330
333
if !kind_stats. all_multipart_suggestions {
331
334
span_attrs. push ( "primary_span" )
332
335
}
333
- diag. help( format!(
334
- "only `{}`, `applicability` and `skip_arg` are valid field attributes" ,
335
- span_attrs. join( ", " )
336
- ) )
337
- } ) ,
336
+
337
+ invalid_attr ( attr, & Meta :: Path ( path) )
338
+ . help ( format ! (
339
+ "only `{}`, `applicability` and `skip_arg` are valid field attributes" ,
340
+ span_attrs. join( ", " )
341
+ ) )
342
+ . emit ( ) ;
343
+
344
+ Ok ( quote ! { } )
345
+ }
338
346
}
339
347
}
340
348
0 commit comments