Skip to content

Add AcceptContext::expect_key_value#155831

Draft
scrabsha wants to merge 1 commit intorust-lang:mainfrom
scrabsha:push-pqrumlqtlsyk
Draft

Add AcceptContext::expect_key_value#155831
scrabsha wants to merge 1 commit intorust-lang:mainfrom
scrabsha:push-pqrumlqtlsyk

Conversation

@scrabsha
Copy link
Copy Markdown
Contributor

@scrabsha scrabsha commented Apr 26, 2026

(I would like to do one more self-review, I'm not sure reading right now this is the best use of your time)

This PR adds AcceptContext::expect_name_value that takes any name-value-ish node and returns what's in it (it depends on the node). It follows the same style as AcceptContext::expect_list and AcceptContext::single.

As expect_name_value takes care of all the error emission, this allowed to remove any call to AttributeDiagnosticContext::expected_name_value from outside rustc_attr_parsing::context. The method now private.

TODO: PR description:

  • list the cases in which as_name_value is still used
  • list the cases in which as_meta_item is still used

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 26, 2026
Comment thread compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs Outdated
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/attributes/doc.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs Outdated
Comment thread compiler/rustc_attr_parsing/src/context.rs
/// there
/// - `#[doc = "hello"]`: `doc = "hello` is also a name value pair
pub fn name_value(&self) -> Option<&NameValueParser> {
pub fn as_name_value(&self) -> Option<&NameValueParser> {
Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention in the PR description:

  • how many uses of the as_name_value are there in the attributes module?
  • what are they still relevant?

View changes since the review

}

pub fn meta_item(&self) -> Option<&MetaItemParser> {
pub fn as_meta_item(&self) -> Option<&MetaItemParser> {
Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention in the PR description:

  • how many uses of the as_name_value are there in the attributes module?
  • what are they still relevant?

View changes since the review

@scrabsha scrabsha force-pushed the push-pqrumlqtlsyk branch from 5c6f7cf to 27cefb8 Compare April 26, 2026 16:20
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-pqrumlqtlsyk branch from 27cefb8 to 1e7d852 Compare April 26, 2026 16:40
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-pqrumlqtlsyk branch from 1e7d852 to 601b48d Compare April 26, 2026 19:28
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-pqrumlqtlsyk branch from 601b48d to 8cc254b Compare April 27, 2026 11:04
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-04-14/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
---- [ui] tests/rustdoc-ui/bad-render-options.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/rustdoc-ui/bad-render-options/bad-render-options.stderr`
diff of stderr:

- 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:4:1
3    |
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 = "..."`
13 
- 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:7:1
16    |
17 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 = "..."`
21 
- 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:10:1
24    |
25 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 = "..."`
29 
- 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:13:1
32    |
33 LL | #![doc(issue_tracker_base_url)]
---
37 
- error: malformed `doc` attribute input
-   --> $DIR/bad-render-options.rs:16: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!
+ error: aborting due to 4 previous errors
45 
---
+ error[E0539]: malformed `doc` attribute input
+   --> $DIR/bad-render-options.rs:4:1
+    | ^^^^^^^----------------^^
+    |        |
+    |        expected this to be of the form `html_favicon_url = "..."`
+ error[E0539]: malformed `doc` attribute input
+   --> $DIR/bad-render-options.rs:7:1
+    | ^^^^^^^-------------^^
+    |        |
+    |        expected this to be of the form `html_logo_url = "..."`
+ error[E0539]: malformed `doc` attribute input
+   --> $DIR/bad-render-options.rs:10:1
+    | ^^^^^^^-------------------^^
+    |        |
+    |        expected this to be of the form `html_playground_url = "..."`
+ error[E0539]: malformed `doc` attribute input
+   --> $DIR/bad-render-options.rs:13:1
+    | ^^^^^^^----------------------^^
+    |        |
+    |        expected this to be of the form `issue_tracker_base_url = "..."`
---
To only update this specific test, also pass `--test-args bad-render-options.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustdoc" "/checkout/tests/rustdoc-ui/bad-render-options.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/rustdoc-ui/bad-render-options" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Cdebuginfo=0"
stdout: none
--- stderr -------------------------------
error[E0539]: malformed `doc` attribute input
##[error]  --> /checkout/tests/rustdoc-ui/bad-render-options.rs:4:1
   |
LL | #![doc(html_favicon_url)]
   | ^^^^^^^----------------^^
   |        |
   |        expected this to be of the form `html_favicon_url = "..."`

error[E0539]: malformed `doc` attribute input
##[error]  --> /checkout/tests/rustdoc-ui/bad-render-options.rs:7:1
   |
LL | #![doc(html_logo_url)]
---
   |
LL | #![doc(html_playground_url)]
   | ^^^^^^^-------------------^^
   |        |
   |        expected this to be of the form `html_playground_url = "..."`

error[E0539]: malformed `doc` attribute input
##[error]  --> /checkout/tests/rustdoc-ui/bad-render-options.rs:13:1
   |
LL | #![doc(issue_tracker_base_url)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants