Add AcceptContext::expect_key_value#155831
Conversation
This comment has been minimized.
This comment has been minimized.
5c6f7cf to
27cefb8
Compare
This comment has been minimized.
This comment has been minimized.
27cefb8 to
1e7d852
Compare
This comment has been minimized.
This comment has been minimized.
1e7d852 to
601b48d
Compare
This comment has been minimized.
This comment has been minimized.
601b48d to
8cc254b
Compare
This comment has been minimized.
This comment has been minimized.
cf8ee27 to
c92e28d
Compare
| | ^^^^^^^^^^^^^^^^^-------^^^^^^^^^^ | ||
| | | | ||
| | expected this to be of the form `enable = "..."` | ||
| | the only valid argument here is `enable` |
There was a problem hiding this comment.
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.
| 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)] | ||
| | | ||
|
|
There was a problem hiding this comment.
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.
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^ | ||
| | | | ||
| | expected a string literal here |
There was a problem hiding this comment.
This change is caused by replacing expected_key_value -> expected_string_literal in compiler/rustc_attr_parsing/src/attributes/link_attrs.rs.
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred to diagnostic attributes. cc @mejrs |
This comment has been minimized.
This comment has been minimized.
c92e28d to
7724d13
Compare
|
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. |
|
^ Rebased |
…thanBrouwer Add `AcceptContext::expect_key_value`
…thanBrouwer Add `AcceptContext::expect_key_value`
…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)
…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)
Rollup merge of #155831 - scrabsha:push-pqrumlqtlsyk, r=JonathanBrouwer Add `AcceptContext::expect_key_value`
View all comments
This PR adds
AcceptContext::expect_name_valuethat 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 asAcceptContext::expect_listandAcceptContext::singleintroduced in #155696.Having
expect_name_valuetaking care of all the error emission allowed me to remove every call toAttributeDiagnosticContext::expected_name_valuefrom outsiderustc_attr_parsing::contextand mark it as private.as_name_valueis 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: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_valueslightly 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.