Skip to content

Fix ICE when const closure appears inside a non-const trait method#154957

Open
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito:issue_153891
Open

Fix ICE when const closure appears inside a non-const trait method#154957
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito:issue_153891

Conversation

@lapla-cogito
Copy link
Copy Markdown
Contributor

@lapla-cogito lapla-cogito commented Apr 7, 2026

Fixes #153891

hir_body_const_context() unconditionally delegated to the parent's const context for const closures, returning None when the parent had no const context. This caused mir_const_qualif() to hit a span_bug!, since mir_promoted() had already decided to call it based on the closure's own syntactic constness. Fall back to ConstContext::ConstFn when the parent's const context is None, so that the const closure body is still properly const-checked rather than triggering an ICE.

Examining another attempt at this issue (which has already been closed), I thought that its approach represents a workaround fix to avoid inconsistencies in the caller of mir_promoted(), whereas I think the correct behavior is for hir_body_const_context() itself to return the proper value.

@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 Apr 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 7, 2026

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
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 69 candidates
  • Random selection from 10 candidates

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: mir_const_qualif should only be called on const fns and const items

3 participants