diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_type_error.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_type_error.rs index 89cae4b7c55f1..38c1f9ab6c945 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_type_error.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_type_error.rs @@ -18,6 +18,8 @@ pub(crate) struct OnTypeErrorParser { impl OnTypeErrorParser { fn parse<'sess>(&mut self, cx: &mut AcceptContext<'_, 'sess>, args: &ArgParser, mode: Mode) { if !cx.features().diagnostic_on_type_error() { + // `UnknownDiagnosticAttribute` is emitted in rustc_resolve/macros.rs + args.ignore_args(); return; } diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.rs b/tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.rs new file mode 100644 index 0000000000000..5bacedcb76493 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.rs @@ -0,0 +1,9 @@ +//@ check-pass + +// Regression test for https://github.com/rust-lang/rust/issues/158628. + +#[diagnostic::on_type_error(unknown = "")] +//~^ WARN unknown diagnostic attribute +pub struct Foo {} + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.stderr b/tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.stderr new file mode 100644 index 0000000000000..c8b4aac78d6e1 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.stderr @@ -0,0 +1,11 @@ +warning: unknown diagnostic attribute + --> $DIR/feature-gate-diagnostic-on-type-error-malformed-args.rs:5:15 + | +LL | #[diagnostic::on_type_error(unknown = "")] + | ^^^^^^^^^^^^^ + | + = help: add `#![feature(diagnostic_on_type_error)]` to the crate attributes to enable + = note: `#[warn(unknown_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default + +warning: 1 warning emitted +