Skip to content

mgca: Don't ICE when evaluating ValTrees that contain error constants - #158401

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
lapla-cogito:issue_154632
Sep 3, 2026
Merged

mgca: Don't ICE when evaluating ValTrees that contain error constants#158401
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
lapla-cogito:issue_154632

Conversation

@lapla-cogito

@lapla-cogito lapla-cogito commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #154632
Fixes #150969

mir::Const::eval now checks error_reported() and returns Err instead of converting such values to ConstValue.

@rustbot

rustbot commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@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 Jun 25, 2026
@rustbot

rustbot commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

r? @camelid

rustbot has assigned @camelid.
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 73 candidates
  • Random selection from 19 candidates

@camelid camelid added the A-const-generics Area: const generics (parameters and arguments) label Jun 25, 2026

@lapla-cogito lapla-cogito Jun 25, 2026

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.

The case reported in the original issue goes through lower_const_arg_struct(). I found that a similar ICE can also occur through lower_const_arg_tuple_call(), and this serves as a regression test for that case.

View changes since the review

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.

Is it a similar ICE or literally the same ICE? I'm not sure if it makes sense to have multiple tests for it since they all have the same root cause.

@lapla-cogito lapla-cogito Aug 27, 2026

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.

Ah, indeed. When I was investigating using the old fix approach, they appeared to be different paths causing ICE, but now I see these are indeed the same issue. Thanks.

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated

@camelid camelid left a comment

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'm not sure if this is the right place to be fixing the problem. Given that ValTrees can have arbitrary ty::Const, it feels like they should be able to have error constants in them.

@BoxyUwU do you have thoughts about the best way to handle this?

View changes since this review

Comment thread compiler/rustc_middle/src/ty/consts.rs Outdated
branches: impl IntoIterator<Item = ty::Const<'tcx>>,
ty: Ty<'tcx>,
) -> Const<'tcx> {
let branches: Vec<_> = branches.into_iter().collect();

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.

Hmm I don't love that this requires collecting the iterator, looking through all the branches, and then passing it on.

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.

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.

No worries. The TLDR is that we should probably instead make other parts of the compiler handle errors inside valtrees gracefully, rather than avoiding creating valtrees that contain errors in an ad hoc way like this PR does.

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 for waiting! A recent change required additional #![feature(macroless_generic_const_args)] to reproduce ICE in the added tests, so I added it and made the fix.

@camelid camelid 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 Jul 13, 2026
@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@lapla-cogito lapla-cogito changed the title mgca: Propagate errors in const-to-valtree lowering mgca: Don't ICE when evaluating ValTrees that contain error constants Aug 9, 2026
@lapla-cogito

Copy link
Copy Markdown
Contributor Author

@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 Aug 9, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

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.

@lapla-cogito
lapla-cogito force-pushed the issue_154632 branch 2 times, most recently from d2c620d to bce6199 Compare August 9, 2026 10:24

@camelid camelid left a comment

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.

Sorry for my delay with this. Looks good overall, but I have a question.

View changes since this review

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.

Is it a similar ICE or literally the same ICE? I'm not sure if it makes sense to have multiple tests for it since they all have the same root cause.

@camelid camelid 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 Aug 27, 2026
@rustbot

rustbot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

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.

@lapla-cogito

Copy link
Copy Markdown
Contributor Author

@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 Aug 27, 2026

@camelid camelid left a comment

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.

@camelid

camelid commented Sep 2, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit db8797e has been approved by camelid

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 Sep 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 2, 2026
mgca: Don't ICE when evaluating ValTrees that contain error constants

Fixes rust-lang#154632
Fixes rust-lang#150969

`mir::Const::eval` now checks `error_reported()` and returns `Err` instead of converting such values to `ConstValue`.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 2, 2026
mgca: Don't ICE when evaluating ValTrees that contain error constants

Fixes rust-lang#154632
Fixes rust-lang#150969

`mir::Const::eval` now checks `error_reported()` and returns `Err` instead of converting such values to `ConstValue`.
rust-bors Bot pushed a commit that referenced this pull request Sep 2, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #162164 (Revert "Implement Debug for C-like enums with a concatenated string")
 - #160564 (volatile: allow accesses to non-AM memory to trap)
 - #161579 (suggest calling a fn item used as the iterator of a `for` loop)
 - #162044 (coverage: Resolve spans to file-coordinates in a separate step)
 - #162120 (Introduce `PerOwnerLoweringState`)
 - #162151 (Test itanium mangling of `f16` and `f128`)
 - #162162 (Don't special-case `!` in stability checks anymore)
 - #162181 (Remove wrong UnusedBraces lint for iterator loop in edition 2024 )
 - #162187 (Rename `thir::ExprKind::Use` to `ValueExpr`)
 - #158401 (mgca: Don't ICE when evaluating ValTrees that contain error constants)
 - #159873 (fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia)
 - #161847 (Preserve visibility in nested macro import suggestions)
 - #161972 (Improve tests for `#[track_caller]` in async)
 - #162008 (Render the `box` pattern removal diagnostic more actionable & remove `box` expression recovery)
 - #162065 (std: don't reference `libc::O_NOFOLLOW` on VxWorks in `set_perm_nofollow`)
 - #162076 (docs(num): clarify conditions under which error occurs in `impl TryFrom<int> for int`)
 - #162152 (Revert "retrieve supported GCC targets from the sysroot")
 - #162153 (Prefer `LLVMGetVersion` for runtime info)
 - #162168 (fix ICE in project_goals/inherent)
 - #162171 (Explain LoongArch f16 NaN-boxing in inline asm)
 - #162173 (fix supposedly unreachable `bug!` being reachable)
 - #162191 (core: mark float `ClampBounds` methods as `#[inline]`)
 - #162199 (docs(time): clarify exact seconds for hour and minute)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 2, 2026
mgca: Don't ICE when evaluating ValTrees that contain error constants

Fixes rust-lang#154632
Fixes rust-lang#150969

`mir::Const::eval` now checks `error_reported()` and returns `Err` instead of converting such values to `ConstValue`.
rust-bors Bot pushed a commit that referenced this pull request Sep 3, 2026
Rollup of 23 pull requests

Successful merges:

 - #157808 (sanitizers: Implement support for the sanitize ignorelist)
 - #160564 (volatile: allow accesses to non-AM memory to trap)
 - #161579 (suggest calling a fn item used as the iterator of a `for` loop)
 - #162044 (coverage: Resolve spans to file-coordinates in a separate step)
 - #162120 (Introduce `PerOwnerLoweringState`)
 - #162151 (Test itanium mangling of `f16` and `f128`)
 - #162162 (Don't special-case `!` in stability checks anymore)
 - #162181 (Remove wrong UnusedBraces lint for iterator loop in edition 2024 )
 - #162187 (Rename `thir::ExprKind::Use` to `ValueExpr`)
 - #158401 (mgca: Don't ICE when evaluating ValTrees that contain error constants)
 - #159873 (fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia)
 - #161847 (Preserve visibility in nested macro import suggestions)
 - #161972 (Improve tests for `#[track_caller]` in async)
 - #162008 (Render the `box` pattern removal diagnostic more actionable & remove `box` expression recovery)
 - #162065 (std: don't reference `libc::O_NOFOLLOW` on VxWorks in `set_perm_nofollow`)
 - #162076 (docs(num): clarify conditions under which error occurs in `impl TryFrom<int> for int`)
 - #162152 (Revert "retrieve supported GCC targets from the sysroot")
 - #162153 (Prefer `LLVMGetVersion` for runtime info)
 - #162168 (fix ICE in project_goals/inherent)
 - #162171 (Explain LoongArch f16 NaN-boxing in inline asm)
 - #162173 (fix supposedly unreachable `bug!` being reachable)
 - #162191 (core: mark float `ClampBounds` methods as `#[inline]`)
 - #162199 (docs(time): clarify exact seconds for hour and minute)
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 3, 2026
mgca: Don't ICE when evaluating ValTrees that contain error constants

Fixes rust-lang#154632
Fixes rust-lang#150969

`mir::Const::eval` now checks `error_reported()` and returns `Err` instead of converting such values to `ConstValue`.
rust-bors Bot pushed a commit that referenced this pull request Sep 3, 2026
Rollup of 29 pull requests

Successful merges:

 - #161694 (add `Complex` ABI run-make test)
 - #162014 (Move more `rustdoc-html` tests using `--test` into the right folder)
 - #162164 (Revert "Implement Debug for C-like enums with a concatenated string")
 - #160564 (volatile: allow accesses to non-AM memory to trap)
 - #161579 (suggest calling a fn item used as the iterator of a `for` loop)
 - #162044 (coverage: Resolve spans to file-coordinates in a separate step)
 - #162120 (Introduce `PerOwnerLoweringState`)
 - #162132 (std: improve safety documentation in UNIX stack overflow code)
 - #162151 (Test itanium mangling of `f16` and `f128`)
 - #162162 (Don't special-case `!` in stability checks anymore)
 - #162181 (Remove wrong UnusedBraces lint for iterator loop in edition 2024 )
 - #162187 (Rename `thir::ExprKind::Use` to `ValueExpr`)
 - #158401 (mgca: Don't ICE when evaluating ValTrees that contain error constants)
 - #159873 (fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia)
 - #161847 (Preserve visibility in nested macro import suggestions)
 - #161951 (Windows: add fallback if `canonicalize` fails)
 - #161972 (Improve tests for `#[track_caller]` in async)
 - #162008 (Render the `box` pattern removal diagnostic more actionable & remove `box` expression recovery)
 - #162065 (std: don't reference `libc::O_NOFOLLOW` on VxWorks in `set_perm_nofollow`)
 - #162076 (docs(num): clarify conditions under which error occurs in `impl TryFrom<int> for int`)
 - #162152 (Revert "retrieve supported GCC targets from the sysroot")
 - #162153 (Prefer `LLVMGetVersion` for runtime info)
 - #162168 (fix ICE in project_goals/inherent)
 - #162171 (Explain LoongArch f16 NaN-boxing in inline asm)
 - #162173 (fix supposedly unreachable `bug!` being reachable)
 - #162180 (remove outdated next-solver FIXMEs)
 - #162191 (core: mark float `ClampBounds` methods as `#[inline]`)
 - #162195 (docs(time): clarify exact seconds for week and day)
 - #162199 (docs(time): clarify exact seconds for hour and minute)
rust-bors Bot pushed a commit that referenced this pull request Sep 3, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #161694 (add `Complex` ABI run-make test)
 - #162014 (Move more `rustdoc-html` tests using `--test` into the right folder)
 - #162164 (Revert "Implement Debug for C-like enums with a concatenated string")
 - #160564 (volatile: allow accesses to non-AM memory to trap)
 - #161579 (suggest calling a fn item used as the iterator of a `for` loop)
 - #162044 (coverage: Resolve spans to file-coordinates in a separate step)
 - #162120 (Introduce `PerOwnerLoweringState`)
 - #162132 (std: improve safety documentation in UNIX stack overflow code)
 - #162151 (Test itanium mangling of `f16` and `f128`)
 - #162162 (Don't special-case `!` in stability checks anymore)
 - #162181 (Remove wrong UnusedBraces lint for iterator loop in edition 2024 )
 - #162187 (Rename `thir::ExprKind::Use` to `ValueExpr`)
 - #158401 (mgca: Don't ICE when evaluating ValTrees that contain error constants)
 - #159873 (fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia)
 - #161135 (Add `f16` and `f128` inline ASM support for PowerPC)
 - #161847 (Preserve visibility in nested macro import suggestions)
 - #161972 (Improve tests for `#[track_caller]` in async)
 - #162008 (Render the `box` pattern removal diagnostic more actionable & remove `box` expression recovery)
 - #162065 (std: don't reference `libc::O_NOFOLLOW` on VxWorks in `set_perm_nofollow`)
 - #162076 (docs(num): clarify conditions under which error occurs in `impl TryFrom<int> for int`)
 - #162111 (Update mailmap for Will Crichton and Petr Hosek)
 - #162152 (Revert "retrieve supported GCC targets from the sysroot")
 - #162153 (Prefer `LLVMGetVersion` for runtime info)
 - #162168 (fix ICE in project_goals/inherent)
 - #162171 (Explain LoongArch f16 NaN-boxing in inline asm)
@rust-bors
rust-bors Bot merged commit 2417275 into rust-lang:main Sep 3, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 3, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 3, 2026
Rollup merge of #158401 - lapla-cogito:issue_154632, r=camelid

mgca: Don't ICE when evaluating ValTrees that contain error constants

Fixes #154632
Fixes #150969

`mir::Const::eval` now checks `error_reported()` and returns `Err` instead of converting such values to `ConstValue`.
@lapla-cogito
lapla-cogito deleted the issue_154632 branch September 3, 2026 17:12
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (3b029aa): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: missing data
Artifact size: 401.86 MiB -> 400.99 MiB (-0.22%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-generics Area: const generics (parameters and arguments) 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.

[ICE]: expected ConstKind::Value, got {const error} ICE: valtrees: 'called Result::unwrap() on an Err value: ReferencesError(ErrorGuaranteed(()))'

5 participants