From f94f50b6e1c65ad7c7427ce6c88af2873f692456 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 30 Oct 2026 11:31:23 +0100 Subject: [PATCH] Remove `expected_name_value` function and use the one from `AcceptContext` instead --- .../rustc_attr_parsing/src/attributes/doc.rs | 16 ++--- compiler/rustc_attr_parsing/src/context.rs | 6 +- .../rustc_attr_parsing/src/diagnostics.rs | 7 --- tests/rustdoc-ui/bad-render-options.rs | 9 +-- tests/rustdoc-ui/bad-render-options.stderr | 61 ++++++++++--------- tests/rustdoc-ui/lints/doc-attr.rs | 3 - tests/rustdoc-ui/lints/doc-attr.stderr | 36 +++++------ tests/rustdoc-ui/lints/invalid-doc-attr-2.rs | 1 - .../lints/invalid-doc-attr-2.stderr | 22 ++++--- 9 files changed, 75 insertions(+), 86 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index c7335c1aab171..a9d486096b3c2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -20,8 +20,8 @@ use crate::diagnostics::{ DocAutoCfgHideShowUnexpectedItem, DocAutoCfgHideShowUnexpectedItemAfterValues, DocAutoCfgHideShowValuesMix, DocAutoCfgWrongLiteral, DocInlineConflict, DocInlineOnlyUse, DocKeywordNotKeyword, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, - DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, - ExpectedNoArgs, IllFormedAttributeInput, MalformedDoc, UnusedDuplicate, + DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNoArgs, + IllFormedAttributeInput, MalformedDoc, UnusedDuplicate, }; use crate::parser::{ ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser, @@ -64,11 +64,6 @@ fn check_attr_not_crate_level( true } -// FIXME: To be removed once merged and replace with `cx.expected_name_value(span, _name)`. -fn expected_name_value(cx: &mut AcceptContext<'_, '_>, span: Span, _name: Option) { - cx.emit_lint(INVALID_DOC_ATTRIBUTES, ExpectedNameValue, span); -} - // FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead. fn expected_no_args(cx: &mut AcceptContext<'_, '_>, span: Span) { cx.emit_lint(INVALID_DOC_ATTRIBUTES, ExpectedNoArgs, span); @@ -92,7 +87,7 @@ fn parse_keyword_and_attribute( attr_name: Symbol, ) { let Some(nv) = args.as_name_value() else { - expected_name_value(cx, args.span().unwrap_or(path.span()), path.word_sym()); + cx.adcx().expected_name_value(args.span().unwrap_or(path.span()), path.word_sym()); return; }; @@ -555,7 +550,8 @@ impl DocParser { macro_rules! string_arg_and_crate_level { ($ident: ident) => {{ let Some(nv) = args.as_name_value() else { - expected_name_value(cx, args.span().unwrap_or(path.span()), path.word_sym()); + cx.adcx() + .expected_name_value(args.span().unwrap_or(path.span()), path.word_sym()); return; }; @@ -733,7 +729,7 @@ impl DocParser { self.parse_single_doc_attr_item(cx, mip); } MetaItemOrLitParser::Lit(lit) => { - expected_name_value(cx, lit.span, None); + cx.adcx().expected_name_value(lit.span, None); } } } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index bd2ed165b085b..9f069032f7454 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -1045,7 +1045,11 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> { /// Emit an error that a `name = value` pair was expected at this span. The symbol can be given for /// a nicer error message talking about the specific name that was found lacking a value. #[track_caller] - fn expected_name_value(&mut self, span: Span, name: Option) -> ErrorGuaranteed { + pub(crate) fn expected_name_value( + &mut self, + span: Span, + name: Option, + ) -> ErrorGuaranteed { self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNameValue(name)) } diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index e8c9847965f7a..756f69e3a9353 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -384,13 +384,6 @@ pub(crate) struct MalformedDoc; )] pub(crate) struct ExpectedNoArgs; -#[derive(Diagnostic)] -#[diag("expected this to be of the form `... = \"...\"`")] -#[warning( - "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" -)] -pub(crate) struct ExpectedNameValue; - #[derive(Diagnostic)] #[diag("malformed `{$attribute}` attribute")] #[help("{$options}")] diff --git a/tests/rustdoc-ui/bad-render-options.rs b/tests/rustdoc-ui/bad-render-options.rs index c85a818511d7c..bd4a8d4633f55 100644 --- a/tests/rustdoc-ui/bad-render-options.rs +++ b/tests/rustdoc-ui/bad-render-options.rs @@ -1,18 +1,19 @@ // regression test for https://github.com/rust-lang/rust/issues/149187 #![deny(invalid_doc_attributes)] +//~^ NOTE #![doc(html_favicon_url)] //~^ ERROR -//~| WARN +//~| NOTE expected this to be of the form #![doc(html_logo_url)] //~^ ERROR -//~| WARN +//~| NOTE expected this to be of the form #![doc(html_playground_url)] //~^ ERROR -//~| WARN +//~| NOTE expected this to be of the form #![doc(issue_tracker_base_url)] //~^ ERROR -//~| WARN +//~| NOTE expected this to be of the form #![doc(html_favicon_url = 1)] //~^ ERROR //~| WARN diff --git a/tests/rustdoc-ui/bad-render-options.stderr b/tests/rustdoc-ui/bad-render-options.stderr index dac6bc231c37c..a59eedb4c170c 100644 --- a/tests/rustdoc-ui/bad-render-options.stderr +++ b/tests/rustdoc-ui/bad-render-options.stderr @@ -1,50 +1,50 @@ -error: expected this to be of the form `... = "..."` - --> $DIR/bad-render-options.rs:4:8 +error[E0539]: malformed `doc` attribute input + --> $DIR/bad-render-options.rs:5:4 | LL | #![doc(html_favicon_url)] - | ^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -note: the lint level is defined here - --> $DIR/bad-render-options.rs:2:9 - | -LL | #![deny(invalid_doc_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^----------------^ + | | + | expected this to be of the form `html_favicon_url = "..."` -error: expected this to be of the form `... = "..."` - --> $DIR/bad-render-options.rs:7:8 +error[E0539]: malformed `doc` attribute input + --> $DIR/bad-render-options.rs:8:4 | LL | #![doc(html_logo_url)] - | ^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + | ^^^^-------------^ + | | + | expected this to be of the form `html_logo_url = "..."` -error: expected this to be of the form `... = "..."` - --> $DIR/bad-render-options.rs:10:8 +error[E0539]: malformed `doc` attribute input + --> $DIR/bad-render-options.rs:11:4 | LL | #![doc(html_playground_url)] - | ^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + | ^^^^-------------------^ + | | + | expected this to be of the form `html_playground_url = "..."` -error: expected this to be of the form `... = "..."` - --> $DIR/bad-render-options.rs:13:8 +error[E0539]: malformed `doc` attribute input + --> $DIR/bad-render-options.rs:14:4 | LL | #![doc(issue_tracker_base_url)] - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + | ^^^^----------------------^ + | | + | expected this to be of the form `issue_tracker_base_url = "..."` error: malformed `doc` attribute input - --> $DIR/bad-render-options.rs:16:27 + --> $DIR/bad-render-options.rs:17:27 | LL | #![doc(html_favicon_url = 1)] | ^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +note: the lint level is defined here + --> $DIR/bad-render-options.rs:2:9 + | +LL | #![deny(invalid_doc_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^ error: malformed `doc` attribute input - --> $DIR/bad-render-options.rs:19:24 + --> $DIR/bad-render-options.rs:20:24 | LL | #![doc(html_logo_url = 2)] | ^ @@ -52,7 +52,7 @@ LL | #![doc(html_logo_url = 2)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: malformed `doc` attribute input - --> $DIR/bad-render-options.rs:22:30 + --> $DIR/bad-render-options.rs:23:30 | LL | #![doc(html_playground_url = 3)] | ^ @@ -60,7 +60,7 @@ LL | #![doc(html_playground_url = 3)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: malformed `doc` attribute input - --> $DIR/bad-render-options.rs:25:33 + --> $DIR/bad-render-options.rs:26:33 | LL | #![doc(issue_tracker_base_url = 4)] | ^ @@ -68,7 +68,7 @@ LL | #![doc(issue_tracker_base_url = 4)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: didn't expect any arguments here - --> $DIR/bad-render-options.rs:28:23 + --> $DIR/bad-render-options.rs:29:23 | LL | #![doc(html_no_source = "asdf")] | ^^^^^^^^ @@ -77,3 +77,4 @@ LL | #![doc(html_no_source = "asdf")] error: aborting due to 9 previous errors +For more information about this error, try `rustc --explain E0539`. diff --git a/tests/rustdoc-ui/lints/doc-attr.rs b/tests/rustdoc-ui/lints/doc-attr.rs index 46d56e7f59620..2e0aa7bdc386e 100644 --- a/tests/rustdoc-ui/lints/doc-attr.rs +++ b/tests/rustdoc-ui/lints/doc-attr.rs @@ -3,10 +3,7 @@ #[doc(123)] //~^ ERROR -//~| WARN #[doc("hello", "bar")] //~^ ERROR //~| ERROR -//~| WARN -//~| WARN fn bar() {} diff --git a/tests/rustdoc-ui/lints/doc-attr.stderr b/tests/rustdoc-ui/lints/doc-attr.stderr index 263b068e092da..13de09d650bc0 100644 --- a/tests/rustdoc-ui/lints/doc-attr.stderr +++ b/tests/rustdoc-ui/lints/doc-attr.stderr @@ -1,31 +1,27 @@ -error: expected this to be of the form `... = "..."` - --> $DIR/doc-attr.rs:4:7 +error[E0539]: malformed `doc` attribute input + --> $DIR/doc-attr.rs:4:3 | LL | #[doc(123)] - | ^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -note: the lint level is defined here - --> $DIR/doc-attr.rs:2:9 - | -LL | #![deny(invalid_doc_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^---^ + | | + | expected this to be of the form `... = "..."` -error: expected this to be of the form `... = "..."` - --> $DIR/doc-attr.rs:7:7 +error[E0539]: malformed `doc` attribute input + --> $DIR/doc-attr.rs:6:3 | LL | #[doc("hello", "bar")] - | ^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + | ^^^^-------^^^^^^^^ + | | + | expected this to be of the form `... = "..."` -error: expected this to be of the form `... = "..."` - --> $DIR/doc-attr.rs:7:16 +error[E0539]: malformed `doc` attribute input + --> $DIR/doc-attr.rs:6:3 | LL | #[doc("hello", "bar")] - | ^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + | ^^^^^^^^^^^^^-----^ + | | + | expected this to be of the form `... = "..."` error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0539`. diff --git a/tests/rustdoc-ui/lints/invalid-doc-attr-2.rs b/tests/rustdoc-ui/lints/invalid-doc-attr-2.rs index de99d5a9e078c..62c3e58c22d9b 100644 --- a/tests/rustdoc-ui/lints/invalid-doc-attr-2.rs +++ b/tests/rustdoc-ui/lints/invalid-doc-attr-2.rs @@ -2,6 +2,5 @@ #![doc("other attribute")] //~^ ERROR -//~| WARN #![doc] //~^ ERROR diff --git a/tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr b/tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr index 0285af4108ef0..ca2c95ecfbd5f 100644 --- a/tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr +++ b/tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr @@ -1,21 +1,23 @@ -error: expected this to be of the form `... = "..."` - --> $DIR/invalid-doc-attr-2.rs:3:8 +error[E0539]: malformed `doc` attribute input + --> $DIR/invalid-doc-attr-2.rs:3:4 | LL | #![doc("other attribute")] - | ^^^^^^^^^^^^^^^^^ + | ^^^^-----------------^ + | | + | expected this to be of the form `... = "..."` + +error: valid forms for the attribute are `doc = "doc comment"`, `doc(alias)`, `doc(auto_cfg)`, `doc(cfg)`, `doc(hidden)`, `doc(html_favicon_url)`, `doc(html_logo_url)`, `doc(html_no_source)`, `doc(html_playground_url)`, `doc(html_root_url)`, `doc(inline)`, `doc(issue_tracker_base_url)`, `doc(masked)`, `doc(no_inline)`, `doc(notable_trait)`, and `doc(test)` + --> $DIR/invalid-doc-attr-2.rs:5:4 + | +LL | #![doc] + | ^^^ | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! note: the lint level is defined here --> $DIR/invalid-doc-attr-2.rs:1:9 | LL | #![deny(invalid_doc_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: valid forms for the attribute are `doc = "doc comment"`, `doc(alias)`, `doc(auto_cfg)`, `doc(cfg)`, `doc(hidden)`, `doc(html_favicon_url)`, `doc(html_logo_url)`, `doc(html_no_source)`, `doc(html_playground_url)`, `doc(html_root_url)`, `doc(inline)`, `doc(issue_tracker_base_url)`, `doc(masked)`, `doc(no_inline)`, `doc(notable_trait)`, and `doc(test)` - --> $DIR/invalid-doc-attr-2.rs:6:4 - | -LL | #![doc] - | ^^^ - error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0539`.