From f3d4f186da2af3513fac4a130f6d893611ae1614 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 2 Jul 2026 13:36:22 +0900 Subject: [PATCH 1/2] add a test for malformed disabled on_type_error arguments --- ...re-gate-diagnostic-on-type-error-malformed-args.rs | 9 +++++++++ ...ate-diagnostic-on-type-error-malformed-args.stderr | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.rs create mode 100644 tests/ui/feature-gates/feature-gate-diagnostic-on-type-error-malformed-args.stderr 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 + From 673dcf067aec0e601b8d77bc8b66284157155775 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 2 Jul 2026 13:36:36 +0900 Subject: [PATCH 2/2] ignore on_type_error args when the feature is disabled --- .../src/attributes/diagnostic/on_type_error.rs | 2 ++ 1 file changed, 2 insertions(+) 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; }