Skip to content

Conversation

@chenyukang
Copy link
Member

@chenyukang chenyukang commented Nov 7, 2025

Fixes #148634

The ICE happened because

attr::ReprSimd => ReprFlags::IS_SIMD,

will always set IS_SIMD according to get_all_attrs, and since we already report error attribute should be applied to a struct, it's OK to bypass here.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Kivooeo
Copy link
Member

Kivooeo commented Nov 7, 2025

r=me when ci is green

@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)

failures:

---- [ui] tests/ui/asm/invalid-repr-simd-on-enum-148634.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/asm/invalid-repr-simd-on-enum-148634/invalid-repr-simd-on-enum-148634.stderr`
diff of stderr:

1 error[E0517]: attribute should be applied to a struct
-   --> $DIR/invalid-repr-simd-on-enum.rs:5:8
+   --> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8
---
19 error: cannot use value of type `Es` for inline assembly
-   --> $DIR/invalid-repr-simd-on-enum.rs:13:29
+   --> $DIR/invalid-repr-simd-on-enum-148634.rs:13:29
21    |
22 LL |         asm!("{}", out(reg) x);
23    |                             ^

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs:5:8
-   --> /checkout/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs:5:8
---
To only update this specific test, also pass `--test-args asm/invalid-repr-simd-on-enum-148634.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/asm/invalid-repr-simd-on-enum-148634.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/asm/invalid-repr-simd-on-enum-148634" "-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[E0517]: attribute should be applied to a struct
##[error]  --> /checkout/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs:5:8
   |
---

error: cannot use value of type `Es` for inline assembly
##[error]  --> /checkout/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs:13:29
   |
LL |         asm!("{}", out(reg) x);
   |                             ^
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: aborting due to 3 previous errors

@lcnr
Copy link
Contributor

lcnr commented Nov 7, 2025

hmm, would it be possible to instead filter the ReprOptions so that we don't end up with unsupported ones? It feels brittle to simply handle incorrect info by ignoring it, e.g. it adds an implicit assumption that repr(simd) is only ever used for structs, and if we were to idk, extend support to unions at some point (even if unlikely) this code would suddenly be incorrect

alternatively, accept all Adts, but then match on the kind and skip + span_delay_bug if it's not a struct

@Kivooeo
Copy link
Member

Kivooeo commented Nov 7, 2025

it adds an implicit assumption that repr(simd) is only ever used for structs

according to the rfc it seems (at least for me) that this is only for structs https://github.com/rust-lang/rfcs/blob/master/text/1199-simd-infrastructure.md#types

@lcnr
Copy link
Contributor

lcnr commented Nov 7, 2025

Yes, but is this a guarantee that we'll never extend it to unions? My point is not that the code is wrong, it's that this code adds an implicit dependency which may result in bugs in the future.

Most bugs in large projects happen by:

  • somebody writes code which has an unchecked assumption which holds right now
  • somebody else modifies another part of the project, causing this assumption to no longer hold, resulting in a bug in entirely untouched code

This implies that a good way to avoid bugs in large projects it to avoid unchecked assumptions. It's why exhaustive matches are so powerful. It's also why we do stuff like

// This causes a compiler error if any new float kinds are added.
let (ty::FloatTy::F16 | ty::FloatTy::F32 | ty::FloatTy::F64 | ty::FloatTy::F128);
let possible_floats = [
ty::SimplifiedType::Float(ty::FloatTy::F16),
ty::SimplifiedType::Float(ty::FloatTy::F32),
ty::SimplifiedType::Float(ty::FloatTy::F64),
ty::SimplifiedType::Float(ty::FloatTy::F128),
];

@Kivooeo Kivooeo 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 Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

ICE: assertion failed: self.is_struct() || self.is_union()

5 participants