Skip to content

Conversation

@Bryntet
Copy link
Contributor

@Bryntet Bryntet commented Dec 20, 2025

Please note the test changes, and deprecation of E0778 and E0779

In my opinion, all errors related to this attribute are improved I think, except for if you have #[instruction_set(arm::)] in which case there's an error: expected identifier, found <eof>, which is quite unhelpful I think, but this seems to be a limitation of the general attribute parsing flow

r? @JonathanBrouwer

@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 20, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Bryntet Bryntet force-pushed the parse_instruction_set branch 4 times, most recently from 2815243 to 25f9a74 Compare December 20, 2025 16:42
@Bryntet
Copy link
Contributor Author

Bryntet commented Dec 20, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 20, 2025
@Bryntet Bryntet force-pushed the parse_instruction_set branch from 25f9a74 to 6fd2c64 Compare December 20, 2025 17:19
@Bryntet Bryntet force-pushed the parse_instruction_set branch from 6fd2c64 to d42c32b Compare December 20, 2025 17:32
@JonathanBrouwer
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 20, 2025

📌 Commit d42c32b has been approved by JonathanBrouwer

It is now in the queue for this repository.

@bors bors 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 Dec 20, 2025
@JonathanBrouwer
Copy link
Contributor

@bors r-
Sorry one more thing

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 20, 2025

impl<S: Stage> SingleAttributeParser<S> for InstructionSetParser {
const PATH: &[Symbol] = &[sym::instruction_set];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer Dec 20, 2025

Choose a reason for hiding this comment

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

The allowed targets list is not correct.
According to the spec, the allowed targets are:

The instruction_set attribute may only be applied to functions with bodiesclosures, async blocks, free functions, associated functions in an inherent impl or trait impl, and associated functions in a trait definition when those functions have a default definition .

(https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also just realised this is a stable attribute and we haven't been checking the targetlist previously, so I added these and made the rest warn

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get a test for this? Would specifically like to see whether async blocks are indeed included under Target::Closure

@Bryntet Bryntet force-pushed the parse_instruction_set branch from d42c32b to 0516456 Compare December 20, 2025 18:06
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests/ui/attributes/invalid-instruction-set-target.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/attributes/invalid-instruction-set-target/invalid-instruction-set-target.stderr`
diff of stderr:

- error: target `x86_64-unknown-linux-gnu` does not support `#[instruction_set(arm::*)]`
-   --> $DIR/invalid-instruction-set-target.rs:4:1
+ error[E0463]: can't find crate for `std`
3    |
- LL | #[instruction_set(arm::a32)]
-    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---
To only update this specific test, also pass `--test-args attributes/invalid-instruction-set-target.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/rustc" "/checkout/tests/ui/attributes/invalid-instruction-set-target.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" "--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" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/attributes/invalid-instruction-set-target" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--target" "x86_64-unknown-linux-gnu"
stdout: none
--- stderr -------------------------------
error[E0463]: can't find crate for `std`
   |
   = note: the `x86_64-unknown-linux-gnu` target may not be installed
---
---- [ui] tests/ui/error-codes/E0778.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/error-codes/E0778/E0778.stderr`
diff of stderr:

- error[E0778]: `#[instruction_set]` requires an argument
+ error[E0539]: malformed `instruction_set` attribute input
2   --> $DIR/E0778.rs:1:1
3    |
4 LL | #[instruction_set()]

5    | ^^^^^^^^^^^^^^^^^^^^
+    | |
+    | valid arguments are `arm::a32` or `arm::t32`
+    | help: must be of the form: `#[instruction_set(set)]`
+    |
+    = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute>
6 
7 error: aborting due to 1 previous error
8 
---
To only update this specific test, also pass `--test-args error-codes/E0778.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/rustc" "/checkout/tests/ui/error-codes/E0778.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" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/error-codes/E0778" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0539]: malformed `instruction_set` attribute input
##[error]  --> /checkout/tests/ui/error-codes/E0778.rs:1:1
   |
LL | #[instruction_set()] //~ ERROR
   | ^^^^^^^^^^^^^^^^^^^^
   | |
   | valid arguments are `arm::a32` or `arm::t32`
   | help: must be of the form: `#[instruction_set(set)]`
   |
   = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute>

error: aborting due to 1 previous error

---
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/error-codes/E0779/E0779.stderr`
diff of stderr:

- error[E0779]: invalid instruction set specified
+ error: target `aarch64-unknown-linux-gnu` does not support `#[instruction_set(arm::*)]`
2   --> $DIR/E0779.rs:1:1
3    |
4 LL | #[instruction_set(arm::magic)]

6 
7 error: aborting due to 1 previous error
---
To only update this specific test, also pass `--test-args error-codes/E0779.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/rustc" "/checkout/tests/ui/error-codes/E0779.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" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/error-codes/E0779" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: target `aarch64-unknown-linux-gnu` does not support `#[instruction_set(arm::*)]`
##[error]  --> /checkout/tests/ui/error-codes/E0779.rs:1:1
   |
LL | #[instruction_set(arm::magic)] //~ ERROR
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------

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.

5 participants