Skip to content

Add AcceptContext::expect_key_value#155831

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
scrabsha:push-pqrumlqtlsyk
Apr 30, 2026
Merged

Add AcceptContext::expect_key_value#155831
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
scrabsha:push-pqrumlqtlsyk

Conversation

@scrabsha
Copy link
Copy Markdown
Contributor

@scrabsha scrabsha commented Apr 26, 2026

View all comments

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

Having expect_name_value taking care of all the error emission allowed me to remove every call to AttributeDiagnosticContext::expected_name_value from outside rustc_attr_parsing::context and mark it as private. as_name_value is still used in places in which we want to emit our own error messages.

r? JonathanBrouwer

Oracle changes

While reviewing the uses of expected_name_value, I found quite a few of these:

let Some(value_str) = name_value.value_as_str() else {
    cx.adcx().expected_name_value(/* ... */);
    return None;
};

I believe emitting an "expected a name-value pair" error message is misleading because in this situation we already have asserted that the name-value is... a name-value. I replaced these with calls to expected_string_literal. This alters the oracles a bit.


I also made MetaItemParser::expect_name_value slightly smarter than what ~most of the code was doing before, as it is able to assert that the name is a single word (and not an arbitrary path) and that the argument is an = value (and not a list, or nothing) in one go and potentially emit two errors instead of just ones. This too alters oracles.

@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
Comment thread compiler/rustc_attr_parsing/src/parser.rs
Comment thread compiler/rustc_attr_parsing/src/parser.rs Outdated
@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

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-pqrumlqtlsyk branch 2 times, most recently from cf8ee27 to c92e28d Compare April 27, 2026 20:44
| ^^^^^^^^^^^^^^^^^-------^^^^^^^^^^
| |
| expected this to be of the form `enable = "..."`
| the only valid argument here is `enable`
Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 28, 2026

Choose a reason for hiding this comment

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

The change here is caused by the change expected_name_value -> expected_specific_argument when checking that the argument is enable in compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs.

View changes since the review

Comment on lines +1 to +15
error[E0539]: malformed `cfg` attribute input
--> $DIR/cfg-target-compact-errors.rs:5:1
|
LL | #[cfg(target(o::o))]
| ^^^^^^^^^^^^^----^^^
| |
| expected a valid identifier here
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
help: must be of the form
|
LL - #[cfg(target(o::o))]
LL + #[cfg(predicate)]
|

Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 28, 2026

Choose a reason for hiding this comment

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

This error is added because MetaItemOrLitParser::expect_key_value checks both that the argument is a single word (here it is a path) and that the argument is a key-value (next error in this oracle) before returning.

View changes since the review

Comment on lines +5 to +7
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| |
| expected a string literal here
Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 28, 2026

Choose a reason for hiding this comment

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

This change is caused by replacing expected_key_value -> expected_string_literal in compiler/rustc_attr_parsing/src/attributes/link_attrs.rs.

View changes since the review

@scrabsha scrabsha marked this pull request as ready for review April 28, 2026 08:41
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to diagnostic attributes.

cc @mejrs

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 28, 2026
@rust-bors

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 29, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

^ Rebased
@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

📌 Commit 7724d13 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 29, 2026
…thanBrouwer

Add `AcceptContext::expect_key_value`
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 29, 2026
…thanBrouwer

Add `AcceptContext::expect_key_value`
rust-bors Bot pushed a commit that referenced this pull request Apr 29, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #154149 (resolve: Extend `ambiguous_import_visibilities` deprecation lint to glob-vs-glob ambiguities)
 - #155189 (simd_reduce_min/max: remove float support)
 - #155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets)
 - #155562 (Add a missing `GenericTypeVisitable`, and avoid having interner traits for `FnSigKind` and `Abi`)
 - #155608 (rustc_middle: Implement the `partial_cmp` operation for `DefId`s)
 - #155721 (When archive format is wrong produce an error instead of ICE)
 - #155794 (privacy: share effective visibility initialization)
 - #155832 (c-variadic: more precise compatibility check in const-eval)
 - #155856 (std_detect: support detecting more features on aarch64 Windows)
 - #155861 (Suggest `[const] Trait` bounds in more places)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155916 (Update with new LLVM 22 target for `wasm32-wali-linux-musl` target)
 - #155935 (remap OUT_DIR paths to fix build script path leakage in crate metadata. )
 - #155950 (use the new `//@ needs-asm-mnemonic: ret` more)
 - #155958 (ci(free-disk-space): remove more tools and fix warnings)
 - #155966 (miri subtree update)
 - #155711 (bump curl-sys and openssl-sys to support OpenSSL 4.0.x)
 - #155831 (Add `AcceptContext::expect_key_value`)
 - #155877 (Avoid misleading return-type note for foreign `Fn` callees)
 - #155949 (Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`)
 - #155951 (Make `FlatMapInPlaceVec` an unsafe trait.)
 - #155967 (Fix `doc_cfg` feature for extern items)
rust-bors Bot pushed a commit that referenced this pull request Apr 29, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #155966 (miri subtree update)
 - #154149 (resolve: Extend `ambiguous_import_visibilities` deprecation lint to glob-vs-glob ambiguities)
 - #155189 (simd_reduce_min/max: remove float support)
 - #155562 (Add a missing `GenericTypeVisitable`, and avoid having interner traits for `FnSigKind` and `Abi`)
 - #155608 (rustc_middle: Implement the `partial_cmp` operation for `DefId`s)
 - #155721 (When archive format is wrong produce an error instead of ICE)
 - #155794 (privacy: share effective visibility initialization)
 - #155832 (c-variadic: more precise compatibility check in const-eval)
 - #155856 (std_detect: support detecting more features on aarch64 Windows)
 - #155861 (Suggest `[const] Trait` bounds in more places)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155916 (Update with new LLVM 22 target for `wasm32-wali-linux-musl` target)
 - #155935 (remap OUT_DIR paths to fix build script path leakage in crate metadata. )
 - #155950 (use the new `//@ needs-asm-mnemonic: ret` more)
 - #155958 (ci(free-disk-space): remove more tools and fix warnings)
 - #155711 (bump curl-sys and openssl-sys to support OpenSSL 4.0.x)
 - #155831 (Add `AcceptContext::expect_key_value`)
 - #155877 (Avoid misleading return-type note for foreign `Fn` callees)
 - #155949 (Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`)
 - #155951 (Make `FlatMapInPlaceVec` an unsafe trait.)
 - #155967 (Fix `doc_cfg` feature for extern items)
@rust-bors rust-bors Bot merged commit 344cc3e into rust-lang:main Apr 30, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Apr 30, 2026
Rollup merge of #155831 - scrabsha:push-pqrumlqtlsyk, r=JonathanBrouwer

Add `AcceptContext::expect_key_value`
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Apr 30, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - rust-lang/rust#155966 (miri subtree update)
 - rust-lang/rust#154149 (resolve: Extend `ambiguous_import_visibilities` deprecation lint to glob-vs-glob ambiguities)
 - rust-lang/rust#155189 (simd_reduce_min/max: remove float support)
 - rust-lang/rust#155562 (Add a missing `GenericTypeVisitable`, and avoid having interner traits for `FnSigKind` and `Abi`)
 - rust-lang/rust#155608 (rustc_middle: Implement the `partial_cmp` operation for `DefId`s)
 - rust-lang/rust#155721 (When archive format is wrong produce an error instead of ICE)
 - rust-lang/rust#155794 (privacy: share effective visibility initialization)
 - rust-lang/rust#155832 (c-variadic: more precise compatibility check in const-eval)
 - rust-lang/rust#155856 (std_detect: support detecting more features on aarch64 Windows)
 - rust-lang/rust#155861 (Suggest `[const] Trait` bounds in more places)
 - rust-lang/rust#155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - rust-lang/rust#155916 (Update with new LLVM 22 target for `wasm32-wali-linux-musl` target)
 - rust-lang/rust#155935 (remap OUT_DIR paths to fix build script path leakage in crate metadata. )
 - rust-lang/rust#155950 (use the new `//@ needs-asm-mnemonic: ret` more)
 - rust-lang/rust#155958 (ci(free-disk-space): remove more tools and fix warnings)
 - rust-lang/rust#155711 (bump curl-sys and openssl-sys to support OpenSSL 4.0.x)
 - rust-lang/rust#155831 (Add `AcceptContext::expect_key_value`)
 - rust-lang/rust#155877 (Avoid misleading return-type note for foreign `Fn` callees)
 - rust-lang/rust#155949 (Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`)
 - rust-lang/rust#155951 (Make `FlatMapInPlaceVec` an unsafe trait.)
 - rust-lang/rust#155967 (Fix `doc_cfg` feature for extern items)
@scrabsha scrabsha deleted the push-pqrumlqtlsyk branch April 30, 2026 07:22
@cuviper cuviper added this to the 1.97.0 milestone Apr 30, 2026
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants