Skip to content

Fix ICE of layout mismatch during const eval - #165898

Closed
frank-king wants to merge 2 commits into
rust-lang:mainfrom
frank-king:fix/161532
Closed

frank-king wants to merge 2 commits into
rust-lang:mainfrom
frank-king:fix/161532

Conversation

@frank-king

@frank-king frank-king commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

@rustbot rustbot added 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 Nov 13, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@frank-king
frank-king marked this pull request as ready for review November 16, 2026 05:33
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 16, 2026
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@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 Nov 16, 2026
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 20 candidates

@rustbot

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
test [ui] tests/ui/zero-sized/zero-sized-btreemap-insert.rs ... ok

failures:

---- [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-add stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/consts/const-eval/const-eval-type-mismatch-gca.debug-assertions-add/const-eval-type-mismatch-gca.debug-assertions-add.stderr`
diff of stderr:

2   --> $DIR/const-eval-type-mismatch-gca.rs:33:1
3    |
4 LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
+    | ^^^^^^^^^^----------------------^^^^^^^^
+    | |         |
+    | |         `N` defined here
5    | expected `usize`, found `u64`
6 
---
To only update this specific test, also pass `--test-args consts/const-eval/const-eval-type-mismatch-gca.rs`

error in revision `debug-assertions-add`: 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/consts/const-eval/const-eval-type-mismatch-gca.rs" "-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" "--cfg" "debug_assertions_add" "--check-cfg" "cfg(test,FALSE,debug_assertions_add,no_debug_assertions_add,debug_assertions_and,no_debug_assertions_and,debug_assertions_not,no_debug_assertions_not)" "-Zthreads=1" "--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/consts/const-eval/const-eval-type-mismatch-gca.debug-assertions-add" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015" "-Znext-solver=globally" "-Cdebug_assertions=yes"
stdout: none
--- stderr -------------------------------
error: the constant `N` is not of type `usize`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:33:1
   |
LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
   | ^^^^^^^^^^----------------------^^^^^^^^
   | |         |
   | |         `N` defined here
   | expected `usize`, found `u64`

error: the constant `INNER::<N>` is not of type `usize`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:33:1
   |
LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found a different `usize`

error[E0271]: type mismatch resolving `GCA<0> == _`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:37:47
   |
LL | const ARR: [(); gca!(INNER::<0>)] = [(); gca!(GCA::<0>)];
   |                                               ^^^^^^^^ types differ

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0271`.
------------------------------------------

---- [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-add stdout end ----
---- [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-and stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/consts/const-eval/const-eval-type-mismatch-gca.debug-assertions-and/const-eval-type-mismatch-gca.debug-assertions-and.stderr`
diff of stderr:

2   --> $DIR/const-eval-type-mismatch-gca.rs:33:1
3    |
4 LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
+    | ^^^^^^^^^^----------------------^^^^^^^^
+    | |         |
+    | |         `N` defined here
5    | expected `usize`, found `u64`
6 
---
To only update this specific test, also pass `--test-args consts/const-eval/const-eval-type-mismatch-gca.rs`

error in revision `debug-assertions-and`: 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/consts/const-eval/const-eval-type-mismatch-gca.rs" "-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" "--cfg" "debug_assertions_and" "--check-cfg" "cfg(test,FALSE,debug_assertions_add,no_debug_assertions_add,debug_assertions_and,no_debug_assertions_and,debug_assertions_not,no_debug_assertions_not)" "-Zthreads=1" "--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/consts/const-eval/const-eval-type-mismatch-gca.debug-assertions-and" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015" "-Znext-solver=globally" "-Cdebug_assertions=yes"
stdout: none
--- stderr -------------------------------
error: the constant `N` is not of type `usize`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:33:1
   |
LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
   | ^^^^^^^^^^----------------------^^^^^^^^
   | |         |
   | |         `N` defined here
   | expected `usize`, found `u64`

error: the constant `INNER::<N>` is not of type `usize`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:33:1
   |
LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found a different `usize`

error[E0271]: type mismatch resolving `GCA<0> == _`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:37:47
   |
LL | const ARR: [(); gca!(INNER::<0>)] = [(); gca!(GCA::<0>)];
   |                                               ^^^^^^^^ types differ

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0271`.
------------------------------------------

---- [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-and stdout end ----
---- [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-not stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/consts/const-eval/const-eval-type-mismatch-gca.debug-assertions-not/const-eval-type-mismatch-gca.debug-assertions-not.stderr`
diff of stderr:

2   --> $DIR/const-eval-type-mismatch-gca.rs:33:1
3    |
4 LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
+    | ^^^^^^^^^^----------------------^^^^^^^^
+    | |         |
+    | |         `N` defined here
5    | expected `usize`, found `u64`
6 
---
To only update this specific test, also pass `--test-args consts/const-eval/const-eval-type-mismatch-gca.rs`

error in revision `debug-assertions-not`: 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/consts/const-eval/const-eval-type-mismatch-gca.rs" "-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" "--cfg" "debug_assertions_not" "--check-cfg" "cfg(test,FALSE,debug_assertions_add,no_debug_assertions_add,debug_assertions_and,no_debug_assertions_and,debug_assertions_not,no_debug_assertions_not)" "-Zthreads=1" "--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/consts/const-eval/const-eval-type-mismatch-gca.debug-assertions-not" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015" "-Znext-solver=globally" "-Cdebug_assertions=yes"
stdout: none
--- stderr -------------------------------
error: the constant `N` is not of type `usize`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:33:1
   |
LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
   | ^^^^^^^^^^----------------------^^^^^^^^
   | |         |
   | |         `N` defined here
   | expected `usize`, found `u64`

error: the constant `INNER::<N>` is not of type `usize`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:33:1
   |
LL | const GCA<const N: ConcreteUsize>: usize = gca!(INNER::<N>);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found a different `usize`

error[E0271]: type mismatch resolving `GCA<0> == _`
##[error]  --> /checkout/tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs:37:47
   |
LL | const ARR: [(); gca!(INNER::<0>)] = [(); gca!(GCA::<0>)];
   |                                               ^^^^^^^^ types differ

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0271`.
------------------------------------------

---- [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-not stdout end ----

failures:
    [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-add
    [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-and
    [ui] tests/ui/consts/const-eval/const-eval-type-mismatch-gca.rs#debug-assertions-not

known_layout.ty,
check_layout.ty,
);
span_delayed_layout_mismatch_bug(

@RalfJung RalfJung Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is a good idea. The MIR is apparently invalid, we should not try to continue evaluating broken MIR.

View changes since the review

@RalfJung RalfJung Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, you are also throwing an error. The function name is misleading then.

But also, I am not sure that's a good idea. Something is wrong elsewhere in the compiler if we are asked to interpreted ill-typed MIR. There are a lot of places where the interpreter assumes that things are well-typed, this PR is only scratching the surface. Accepting this PR means entering a never-ending game of whack-a-mole to find them all, making the code harder to read and harder to maintain while replacing assertions with softer errors. That's a bad idea IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Let me see if the type error could be blocked during typeck.

@frank-king

Copy link
Copy Markdown
Contributor Author

@rustbot author

@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 Nov 16, 2026
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

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

@RalfJung

RalfJung commented Nov 16, 2026 via email

Copy link
Copy Markdown
Member

@frank-king

Copy link
Copy Markdown
Contributor Author

Find this PR: #160466.

@frank-king

Copy link
Copy Markdown
Contributor Author

Close in favor of #160237.

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

Labels

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 left == right failed: scalar immediate size does not match layout

5 participants