File tree Expand file tree Collapse file tree 4 files changed +45
-2
lines changed
compiler/rustc_macros/src Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ decl_derive!(
67
67
warning,
68
68
error,
69
69
// field attributes
70
+ skip_arg,
70
71
primary_span,
71
72
label,
72
73
suggestion,
Original file line number Diff line number Diff line change @@ -216,7 +216,12 @@ impl<'a> SessionDiagnosticDerive<'a> {
216
216
if field. attrs . is_empty ( ) {
217
217
let diag = & builder. diag ;
218
218
let ident = field_binding. ast ( ) . ident . as_ref ( ) . unwrap ( ) ;
219
- quote ! { #diag. set_arg( stringify!( #ident) , #field_binding. into_diagnostic_arg( ) ) ; }
219
+ quote ! {
220
+ #diag. set_arg(
221
+ stringify!( #ident) ,
222
+ #field_binding. into_diagnostic_arg( )
223
+ ) ;
224
+ }
220
225
} else {
221
226
quote ! { }
222
227
}
@@ -566,6 +571,11 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
566
571
let meta = attr. parse_meta ( ) ?;
567
572
match meta {
568
573
syn:: Meta :: Path ( _) => match name {
574
+ "skip_arg" => {
575
+ // Don't need to do anything - by virtue of the attribute existing, the
576
+ // `set_arg` call will not be generated.
577
+ Ok ( quote ! { } )
578
+ }
569
579
"primary_span" => {
570
580
if type_matches_path ( & info. ty , & [ "rustc_span" , "Span" ] ) {
571
581
return Ok ( quote ! {
Original file line number Diff line number Diff line change @@ -311,3 +311,23 @@ struct ErrorWithLifetime<'a> {
311
311
span : Span ,
312
312
name : & ' a str ,
313
313
}
314
+
315
+ #[ derive( SessionDiagnostic ) ]
316
+ //~^ ERROR no method named `into_diagnostic_arg` found for struct `Hello` in the current scope
317
+ #[ error( code = "E0123" , slug = "foo" ) ]
318
+ struct ArgFieldWithoutSkip {
319
+ #[ primary_span]
320
+ span : Span ,
321
+ other : Hello ,
322
+ }
323
+
324
+ #[ derive( SessionDiagnostic ) ]
325
+ #[ error( code = "E0123" , slug = "foo" ) ]
326
+ struct ArgFieldWithSkip {
327
+ #[ primary_span]
328
+ span : Span ,
329
+ // `Hello` does not implement `IntoDiagnosticArg` so this would result in an error if
330
+ // not for `#[skip_arg]`.
331
+ #[ skip_arg]
332
+ other : Hello ,
333
+ }
Original file line number Diff line number Diff line change @@ -274,5 +274,17 @@ error: cannot find attribute `nonsense` in this scope
274
274
LL | #[nonsense]
275
275
| ^^^^^^^^
276
276
277
- error: aborting due to 34 previous errors
277
+ error[E0599]: no method named `into_diagnostic_arg` found for struct `Hello` in the current scope
278
+ --> $DIR/session-derive-errors.rs:315:10
279
+ |
280
+ LL | struct Hello {}
281
+ | ------------ method `into_diagnostic_arg` not found for this
282
+ ...
283
+ LL | #[derive(SessionDiagnostic)]
284
+ | ^^^^^^^^^^^^^^^^^ method not found in `Hello`
285
+ |
286
+ = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
287
+
288
+ error: aborting due to 35 previous errors
278
289
290
+ For more information about this error, try `rustc --explain E0599`.
You can’t perform that action at this time.
0 commit comments