From c7ea602b621fc26f34d44b2ec713c4787be9679d Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 17 Oct 2026 23:23:40 +0200 Subject: [PATCH 1/7] add test for literals in lint attributes --- tests/ui/lint/lint-attribute-literals.rs | 7 +++++++ tests/ui/lint/lint-attribute-literals.stderr | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/ui/lint/lint-attribute-literals.rs create mode 100644 tests/ui/lint/lint-attribute-literals.stderr diff --git a/tests/ui/lint/lint-attribute-literals.rs b/tests/ui/lint/lint-attribute-literals.rs new file mode 100644 index 0000000000000..6cbae8e1e9fcf --- /dev/null +++ b/tests/ui/lint/lint-attribute-literals.rs @@ -0,0 +1,7 @@ +// Checks that lint attributes with literals have an explanatory error + +//@ compile-flags: -Zdeduplicate-diagnostics=yes + +#[allow("literal")] +//~^ ERROR malformed lint attribute input [E0452] +fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.stderr b/tests/ui/lint/lint-attribute-literals.stderr new file mode 100644 index 0000000000000..34d7fbfc9b968 --- /dev/null +++ b/tests/ui/lint/lint-attribute-literals.stderr @@ -0,0 +1,9 @@ +error[E0452]: malformed lint attribute input + --> $DIR/lint-attribute-literals.rs:5:9 + | +LL | #[allow("literal")] + | ^^^^^^^^^ bad attribute argument + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0452`. From 7142f9a635a049f1248d860062d86df2cbf159af Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 17 Oct 2026 21:19:21 +0200 Subject: [PATCH 2/7] improve diagnostic for literals in lint attributes --- .../rustc_attr_parsing/src/attributes/lint.rs | 112 ++++++++++-------- .../rustc_attr_parsing/src/diagnostics.rs | 18 +++ ...deduplicate-diagnostics.deduplicate.stderr | 7 +- .../deduplicate-diagnostics.duplicate.stderr | 17 +-- .../deduplicate-diagnostics.rs | 6 +- tests/ui/lint/lint-attribute-literals.rs | 2 +- tests/ui/lint/lint-attribute-literals.stderr | 7 +- 7 files changed, 102 insertions(+), 67 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/lint.rs b/compiler/rustc_attr_parsing/src/attributes/lint.rs index e1221ecbb96d8..51b0578d83688 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint.rs @@ -7,7 +7,7 @@ use thin_vec::ThinVec; use crate::attributes::{AcceptMapping, AttributeParser, AttributeStability}; use crate::context::{AcceptContext, ExpectStringLiteral, FinalizeContext}; -use crate::parser::ArgParser; +use crate::parser::{ArgParser, MetaItemOrLitParser}; use crate::target_checking::AllowedTargets; use crate::target_checking::Policy::{Allow, Warn}; use crate::{AttributeTemplate, diagnostics, template}; @@ -48,58 +48,70 @@ impl LintParser { }; for item in parsers { - if let Some(p) = item.meta_item() { - match p.args() { - ArgParser::NoArgs => { - let (tool, lint_name, rest) = match &*p.path().0.segments { - [] => unreachable!(), - [lint_name] => (None, lint_name.ident.name, None), - [tool, lint_name] => (Some(tool.ident), lint_name.ident.name, None), - [tool, lint_name, rest @ ..] => { - let rest = rest - .iter() - .map(|s| s.ident.name) - .collect::>() - .into(); - (Some(tool.ident), lint_name.ident.name, Some(rest)) - } - }; + match item { + MetaItemOrLitParser::MetaItemParser(p) => { + match p.args() { + ArgParser::NoArgs => { + let (tool, lint_name, rest) = match &*p.path().0.segments { + [] => unreachable!(), + [lint_name] => (None, lint_name.ident.name, None), + [tool, lint_name] => { + (Some(tool.ident), lint_name.ident.name, None) + } + [tool, lint_name, rest @ ..] => { + let rest = rest + .iter() + .map(|s| s.ident.name) + .collect::>() + .into(); + (Some(tool.ident), lint_name.ident.name, Some(rest)) + } + }; - self.lints.push(LintCheck { - tool, - lint_name, - lint_span: p.span(), - kind, - attr_id, - reason, - attr_span, - rest, - }) - } - // We're found a `reason = "reason"` but we're not the last element. - ArgParser::NameValue(nv) if p.path().word_is(sym::reason) => { - cx.emit_err(diagnostics::MalformedAttribute { - span: p.span(), - sub: diagnostics::MalformedAttributeSub::ReasonMustComeLast( - item.span(), - ), - }); - nv.expect_string_literal(cx); - } - ArgParser::NameValue(_) | ArgParser::List(_) => { - cx.emit_err(diagnostics::MalformedAttribute { - span: p.span(), - sub: diagnostics::MalformedAttributeSub::BadAttributeArgument( - item.span(), - ), - }); + self.lints.push(LintCheck { + tool, + lint_name, + lint_span: p.span(), + kind, + attr_id, + reason, + attr_span, + rest, + }) + } + // We've found a `reason = "reason"` but we're not the last element. + ArgParser::NameValue(nv) if p.path().word_is(sym::reason) => { + cx.emit_err(diagnostics::MalformedAttribute { + span: p.span(), + sub: diagnostics::MalformedAttributeSub::ReasonMustComeLast( + item.span(), + ), + }); + nv.expect_string_literal(cx); + } + ArgParser::NameValue(_) | ArgParser::List(_) => { + cx.emit_err(diagnostics::MalformedAttribute { + span: p.span(), + sub: diagnostics::MalformedAttributeSub::BadAttributeArgument( + item.span(), + ), + }); + } } } - } else { - cx.emit_err(diagnostics::MalformedAttribute { - span: item.span(), - sub: diagnostics::MalformedAttributeSub::BadAttributeArgument(item.span()), - }); + MetaItemOrLitParser::Lit(lit) => { + cx.emit_err(diagnostics::BadAttributeLit { + span: item.span(), + sub: if lit.kind.is_str() { + diagnostics::BadAttributeLitHelp::StrLit { + sym: lit.symbol, + kind: kind.sym(), + } + } else { + diagnostics::BadAttributeLitHelp::Other { kind: kind.sym() } + }, + }); + } } } if parsers.is_empty() { diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index b55d7e476896b..6e517b3f7085a 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -2150,6 +2150,24 @@ pub(crate) enum MalformedAttributeSub { ReasonMustComeLast(#[primary_span] Span), } +#[derive(Diagnostic)] +#[diag("expected path to a lint, found literal")] +pub(crate) struct BadAttributeLit { + #[primary_span] + #[label("not a lint")] + pub span: Span, + #[subdiagnostic] + pub sub: BadAttributeLitHelp, +} + +#[derive(Subdiagnostic)] +pub(crate) enum BadAttributeLitHelp { + #[help("try using `#[{$kind}({$sym})]`")] + StrLit { sym: Symbol, kind: Symbol }, + #[help("for example, write `#[{$kind}(dead_code)]` for `dead_code`")] + Other { kind: Symbol }, +} + #[derive(Subdiagnostic)] pub(crate) enum UnusedNote { #[note("attribute `{$name}` with an empty list has no effect")] diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr b/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr index c0d568eb5384e..7e962b20a63f6 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr @@ -1,8 +1,10 @@ -error[E0452]: malformed lint attribute input +error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ bad attribute argument + | ^^^^^^^^^ not a lint + | + = help: try using `#[deny(literal)]` error: cannot find derive macro `Unresolved` in this scope --> $DIR/deduplicate-diagnostics.rs:6:10 @@ -12,4 +14,3 @@ LL | #[derive(Unresolved)] error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0452`. diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr b/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr index 74d7066293f30..142333d750b4c 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr @@ -1,8 +1,10 @@ -error[E0452]: malformed lint attribute input +error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ bad attribute argument + | ^^^^^^^^^ not a lint + | + = help: try using `#[deny(literal)]` error: cannot find derive macro `Unresolved` in this scope --> $DIR/deduplicate-diagnostics.rs:6:10 @@ -18,22 +20,23 @@ LL | #[derive(Unresolved)] | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0452]: malformed lint attribute input +error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ bad attribute argument + | ^^^^^^^^^ not a lint | + = help: try using `#[deny(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0452]: malformed lint attribute input +error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ bad attribute argument + | ^^^^^^^^^ not a lint | + = help: try using `#[deny(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0452`. diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs b/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs index 48705266e3584..27b033b346307 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs @@ -7,7 +7,7 @@ //[duplicate]~| ERROR cannot find derive macro `Unresolved` in this scope struct S; -#[deny("literal")] //~ ERROR malformed lint attribute input - //[duplicate]~| ERROR malformed lint attribute input - //[duplicate]~| ERROR malformed lint attribute input +#[deny("literal")] //~ ERROR expected path to a lint, found literal + //[duplicate]~| ERROR expected path to a lint, found literal + //[duplicate]~| ERROR expected path to a lint, found literal fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.rs b/tests/ui/lint/lint-attribute-literals.rs index 6cbae8e1e9fcf..1d104644c71bc 100644 --- a/tests/ui/lint/lint-attribute-literals.rs +++ b/tests/ui/lint/lint-attribute-literals.rs @@ -3,5 +3,5 @@ //@ compile-flags: -Zdeduplicate-diagnostics=yes #[allow("literal")] -//~^ ERROR malformed lint attribute input [E0452] +//~^ ERROR expected path to a lint, found literal fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.stderr b/tests/ui/lint/lint-attribute-literals.stderr index 34d7fbfc9b968..ca6832a0cdad8 100644 --- a/tests/ui/lint/lint-attribute-literals.stderr +++ b/tests/ui/lint/lint-attribute-literals.stderr @@ -1,9 +1,10 @@ -error[E0452]: malformed lint attribute input +error: expected path to a lint, found literal --> $DIR/lint-attribute-literals.rs:5:9 | LL | #[allow("literal")] - | ^^^^^^^^^ bad attribute argument + | ^^^^^^^^^ not a lint + | + = help: try using `#[allow(literal)]` error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0452`. From 1cb7727098ec3c8aa9758e2a18718a3532f0e3d3 Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 17 Oct 2026 23:35:39 +0200 Subject: [PATCH 3/7] rename sub to kind in attribute diagnostics --- compiler/rustc_attr_parsing/src/attributes/lint.rs | 8 ++++---- compiler/rustc_attr_parsing/src/diagnostics.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/lint.rs b/compiler/rustc_attr_parsing/src/attributes/lint.rs index 51b0578d83688..0c603faa4b5f9 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint.rs @@ -37,7 +37,7 @@ impl LintParser { if !p.path().word_is(sym::reason) { cx.emit_err(diagnostics::MalformedAttribute { span: p.span(), - sub: diagnostics::MalformedAttributeSub::BadAttributeArgument(p.span()), + kind: diagnostics::MalformedAttributeKind::BadAttributeArgument(p.span()), }); } else { parsers = &parsers[..(parsers.len() - 1)]; @@ -83,7 +83,7 @@ impl LintParser { ArgParser::NameValue(nv) if p.path().word_is(sym::reason) => { cx.emit_err(diagnostics::MalformedAttribute { span: p.span(), - sub: diagnostics::MalformedAttributeSub::ReasonMustComeLast( + kind: diagnostics::MalformedAttributeKind::ReasonMustComeLast( item.span(), ), }); @@ -92,7 +92,7 @@ impl LintParser { ArgParser::NameValue(_) | ArgParser::List(_) => { cx.emit_err(diagnostics::MalformedAttribute { span: p.span(), - sub: diagnostics::MalformedAttributeSub::BadAttributeArgument( + kind: diagnostics::MalformedAttributeKind::BadAttributeArgument( item.span(), ), }); @@ -102,7 +102,7 @@ impl LintParser { MetaItemOrLitParser::Lit(lit) => { cx.emit_err(diagnostics::BadAttributeLit { span: item.span(), - sub: if lit.kind.is_str() { + help: if lit.kind.is_str() { diagnostics::BadAttributeLitHelp::StrLit { sym: lit.symbol, kind: kind.sym(), diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 6e517b3f7085a..259b2e5d8425f 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -2139,11 +2139,11 @@ pub(crate) struct MalformedAttribute { #[primary_span] pub span: Span, #[subdiagnostic] - pub sub: MalformedAttributeSub, + pub kind: MalformedAttributeKind, } #[derive(Subdiagnostic)] -pub(crate) enum MalformedAttributeSub { +pub(crate) enum MalformedAttributeKind { #[label("bad attribute argument")] BadAttributeArgument(#[primary_span] Span), #[label("reason in lint attribute must come last")] @@ -2157,7 +2157,7 @@ pub(crate) struct BadAttributeLit { #[label("not a lint")] pub span: Span, #[subdiagnostic] - pub sub: BadAttributeLitHelp, + pub help: BadAttributeLitHelp, } #[derive(Subdiagnostic)] From 4245f27b542a0370fecb1691fe931d3d4f7bc6fb Mon Sep 17 00:00:00 2001 From: annieversary Date: Sun, 18 Oct 2026 07:46:15 +0200 Subject: [PATCH 4/7] change label in BadAttributeLit to be more descriptive --- compiler/rustc_attr_parsing/src/diagnostics.rs | 2 +- .../deduplicate-diagnostics.deduplicate.stderr | 2 +- .../deduplicate-diagnostics.duplicate.stderr | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 259b2e5d8425f..47ea9a2c08517 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -2154,7 +2154,7 @@ pub(crate) enum MalformedAttributeKind { #[diag("expected path to a lint, found literal")] pub(crate) struct BadAttributeLit { #[primary_span] - #[label("not a lint")] + #[label("not the name of a lint")] pub span: Span, #[subdiagnostic] pub help: BadAttributeLitHelp, diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr b/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr index 7e962b20a63f6..c35a239f7e062 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr @@ -2,7 +2,7 @@ error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ not a lint + | ^^^^^^^^^ not the name of a lint | = help: try using `#[deny(literal)]` diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr b/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr index 142333d750b4c..ff782a8d80cca 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr @@ -2,7 +2,7 @@ error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ not a lint + | ^^^^^^^^^ not the name of a lint | = help: try using `#[deny(literal)]` @@ -24,7 +24,7 @@ error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ not a lint + | ^^^^^^^^^ not the name of a lint | = help: try using `#[deny(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` @@ -33,7 +33,7 @@ error: expected path to a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] - | ^^^^^^^^^ not a lint + | ^^^^^^^^^ not the name of a lint | = help: try using `#[deny(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` From 1c9a4b7396042bbc50761be18821fa4d3086c945 Mon Sep 17 00:00:00 2001 From: annieversary Date: Sun, 18 Oct 2026 07:46:49 +0200 Subject: [PATCH 5/7] change t/u/l/lint-attribute-literals to not deduplicate-diagnostics --- tests/ui/lint/lint-attribute-literals.rs | 4 ++-- tests/ui/lint/lint-attribute-literals.stderr | 24 +++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/ui/lint/lint-attribute-literals.rs b/tests/ui/lint/lint-attribute-literals.rs index 1d104644c71bc..137b5b94ea7b7 100644 --- a/tests/ui/lint/lint-attribute-literals.rs +++ b/tests/ui/lint/lint-attribute-literals.rs @@ -1,7 +1,7 @@ // Checks that lint attributes with literals have an explanatory error -//@ compile-flags: -Zdeduplicate-diagnostics=yes - #[allow("literal")] //~^ ERROR expected path to a lint, found literal +//~| ERROR expected path to a lint, found literal +//~| ERROR expected path to a lint, found literal fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.stderr b/tests/ui/lint/lint-attribute-literals.stderr index ca6832a0cdad8..161800c09a869 100644 --- a/tests/ui/lint/lint-attribute-literals.stderr +++ b/tests/ui/lint/lint-attribute-literals.stderr @@ -1,10 +1,28 @@ error: expected path to a lint, found literal - --> $DIR/lint-attribute-literals.rs:5:9 + --> $DIR/lint-attribute-literals.rs:3:9 | LL | #[allow("literal")] - | ^^^^^^^^^ not a lint + | ^^^^^^^^^ not the name of a lint | = help: try using `#[allow(literal)]` -error: aborting due to 1 previous error +error: expected path to a lint, found literal + --> $DIR/lint-attribute-literals.rs:3:9 + | +LL | #[allow("literal")] + | ^^^^^^^^^ not the name of a lint + | + = help: try using `#[allow(literal)]` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: expected path to a lint, found literal + --> $DIR/lint-attribute-literals.rs:3:9 + | +LL | #[allow("literal")] + | ^^^^^^^^^ not the name of a lint + | + = help: try using `#[allow(literal)]` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 3 previous errors From f9d044c80089a17b746d14173d6c51480813b56f Mon Sep 17 00:00:00 2001 From: annieversary Date: Sun, 18 Oct 2026 15:13:46 +0200 Subject: [PATCH 6/7] simplify BadAttributeLit diagnostic message --- compiler/rustc_attr_parsing/src/diagnostics.rs | 2 +- .../deduplicate-diagnostics.deduplicate.stderr | 2 +- .../deduplicate-diagnostics.duplicate.stderr | 6 +++--- tests/ui/diagnostic-flags/deduplicate-diagnostics.rs | 6 +++--- tests/ui/lint/lint-attribute-literals.rs | 6 +++--- tests/ui/lint/lint-attribute-literals.stderr | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 47ea9a2c08517..848ab845dc7f6 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -2151,7 +2151,7 @@ pub(crate) enum MalformedAttributeKind { } #[derive(Diagnostic)] -#[diag("expected path to a lint, found literal")] +#[diag("expected a lint, found literal")] pub(crate) struct BadAttributeLit { #[primary_span] #[label("not the name of a lint")] diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr b/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr index c35a239f7e062..114c37188a9ef 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.deduplicate.stderr @@ -1,4 +1,4 @@ -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr b/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr index ff782a8d80cca..66d0d94c0e815 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.duplicate.stderr @@ -1,4 +1,4 @@ -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] @@ -20,7 +20,7 @@ LL | #[derive(Unresolved)] | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] @@ -29,7 +29,7 @@ LL | #[deny("literal")] = help: try using `#[deny(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/deduplicate-diagnostics.rs:10:8 | LL | #[deny("literal")] diff --git a/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs b/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs index 27b033b346307..b070ec0f7dd93 100644 --- a/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs +++ b/tests/ui/diagnostic-flags/deduplicate-diagnostics.rs @@ -7,7 +7,7 @@ //[duplicate]~| ERROR cannot find derive macro `Unresolved` in this scope struct S; -#[deny("literal")] //~ ERROR expected path to a lint, found literal - //[duplicate]~| ERROR expected path to a lint, found literal - //[duplicate]~| ERROR expected path to a lint, found literal +#[deny("literal")] //~ ERROR expected a lint, found literal + //[duplicate]~| ERROR expected a lint, found literal + //[duplicate]~| ERROR expected a lint, found literal fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.rs b/tests/ui/lint/lint-attribute-literals.rs index 137b5b94ea7b7..69fb7f76007a0 100644 --- a/tests/ui/lint/lint-attribute-literals.rs +++ b/tests/ui/lint/lint-attribute-literals.rs @@ -1,7 +1,7 @@ // Checks that lint attributes with literals have an explanatory error #[allow("literal")] -//~^ ERROR expected path to a lint, found literal -//~| ERROR expected path to a lint, found literal -//~| ERROR expected path to a lint, found literal +//~^ ERROR expected a lint, found literal +//~| ERROR expected a lint, found literal +//~| ERROR expected a lint, found literal fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.stderr b/tests/ui/lint/lint-attribute-literals.stderr index 161800c09a869..188a941918c8d 100644 --- a/tests/ui/lint/lint-attribute-literals.stderr +++ b/tests/ui/lint/lint-attribute-literals.stderr @@ -1,4 +1,4 @@ -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/lint-attribute-literals.rs:3:9 | LL | #[allow("literal")] @@ -6,7 +6,7 @@ LL | #[allow("literal")] | = help: try using `#[allow(literal)]` -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/lint-attribute-literals.rs:3:9 | LL | #[allow("literal")] @@ -15,7 +15,7 @@ LL | #[allow("literal")] = help: try using `#[allow(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: expected path to a lint, found literal +error: expected a lint, found literal --> $DIR/lint-attribute-literals.rs:3:9 | LL | #[allow("literal")] From 31b27ab32c6a6b09825e3f937661b4e0baceca7f Mon Sep 17 00:00:00 2001 From: annieversary Date: Sun, 18 Oct 2026 14:17:33 +0100 Subject: [PATCH 7/7] add test for the BadAttributeLitHelp::Other case --- tests/ui/lint/lint-attribute-literals.rs | 4 +++ tests/ui/lint/lint-attribute-literals.stderr | 28 +++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/ui/lint/lint-attribute-literals.rs b/tests/ui/lint/lint-attribute-literals.rs index 69fb7f76007a0..34a4757adec3c 100644 --- a/tests/ui/lint/lint-attribute-literals.rs +++ b/tests/ui/lint/lint-attribute-literals.rs @@ -4,4 +4,8 @@ //~^ ERROR expected a lint, found literal //~| ERROR expected a lint, found literal //~| ERROR expected a lint, found literal +#[deny(1.0)] +//~^ ERROR expected a lint, found literal +//~| ERROR expected a lint, found literal +//~| ERROR expected a lint, found literal fn main() {} diff --git a/tests/ui/lint/lint-attribute-literals.stderr b/tests/ui/lint/lint-attribute-literals.stderr index 188a941918c8d..7434f8b5c5d4b 100644 --- a/tests/ui/lint/lint-attribute-literals.stderr +++ b/tests/ui/lint/lint-attribute-literals.stderr @@ -6,6 +6,14 @@ LL | #[allow("literal")] | = help: try using `#[allow(literal)]` +error: expected a lint, found literal + --> $DIR/lint-attribute-literals.rs:7:8 + | +LL | #[deny(1.0)] + | ^^^ not the name of a lint + | + = help: for example, write `#[deny(dead_code)]` for `dead_code` + error: expected a lint, found literal --> $DIR/lint-attribute-literals.rs:3:9 | @@ -15,6 +23,15 @@ LL | #[allow("literal")] = help: try using `#[allow(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +error: expected a lint, found literal + --> $DIR/lint-attribute-literals.rs:7:8 + | +LL | #[deny(1.0)] + | ^^^ not the name of a lint + | + = help: for example, write `#[deny(dead_code)]` for `dead_code` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error: expected a lint, found literal --> $DIR/lint-attribute-literals.rs:3:9 | @@ -24,5 +41,14 @@ LL | #[allow("literal")] = help: try using `#[allow(literal)]` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 3 previous errors +error: expected a lint, found literal + --> $DIR/lint-attribute-literals.rs:7:8 + | +LL | #[deny(1.0)] + | ^^^ not the name of a lint + | + = help: for example, write `#[deny(dead_code)]` for `dead_code` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 6 previous errors