From 70ee0c96fc29c57f64a6ccfeb66cccf6fac951f7 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 31 Mar 2022 09:02:31 +0100 Subject: macros: add `#[no_arg]` to skip `set_arg` call A call to `set_arg` is generated for every field of a `SessionDiagnostic` struct without attributes, but not all types support being an argument, so `#[no_arg]` is introduced to skip these fields. Signed-off-by: David Wood --- src/test/ui-fulldeps/session-derive-errors.rs | 20 ++++++++++++++++++++ src/test/ui-fulldeps/session-derive-errors.stderr | 14 +++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src/test/ui-fulldeps') diff --git a/src/test/ui-fulldeps/session-derive-errors.rs b/src/test/ui-fulldeps/session-derive-errors.rs index 422f3894991..96d78c2d00e 100644 --- a/src/test/ui-fulldeps/session-derive-errors.rs +++ b/src/test/ui-fulldeps/session-derive-errors.rs @@ -311,3 +311,23 @@ struct ErrorWithLifetime<'a> { span: Span, name: &'a str, } + +#[derive(SessionDiagnostic)] +//~^ ERROR no method named `into_diagnostic_arg` found for struct `Hello` in the current scope +#[error(code = "E0123", slug = "foo")] +struct ArgFieldWithoutSkip { + #[primary_span] + span: Span, + other: Hello, +} + +#[derive(SessionDiagnostic)] +#[error(code = "E0123", slug = "foo")] +struct ArgFieldWithSkip { + #[primary_span] + span: Span, + // `Hello` does not implement `IntoDiagnosticArg` so this would result in an error if + // not for `#[skip_arg]`. + #[skip_arg] + other: Hello, +} diff --git a/src/test/ui-fulldeps/session-derive-errors.stderr b/src/test/ui-fulldeps/session-derive-errors.stderr index 78ed255523f..21bf8e060ba 100644 --- a/src/test/ui-fulldeps/session-derive-errors.stderr +++ b/src/test/ui-fulldeps/session-derive-errors.stderr @@ -274,5 +274,17 @@ error: cannot find attribute `nonsense` in this scope LL | #[nonsense] | ^^^^^^^^ -error: aborting due to 34 previous errors +error[E0599]: no method named `into_diagnostic_arg` found for struct `Hello` in the current scope + --> $DIR/session-derive-errors.rs:315:10 + | +LL | struct Hello {} + | ------------ method `into_diagnostic_arg` not found for this +... +LL | #[derive(SessionDiagnostic)] + | ^^^^^^^^^^^^^^^^^ method not found in `Hello` + | + = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 35 previous errors +For more information about this error, try `rustc --explain E0599`. -- cgit 1.4.1-3-g733a5