Skip to content

ICE: statement with overlapping memory #149748

Description

@matthiaskrgr

Code

//@compile-flags: --edition=2024 -Zmir-enable-passes=+Inline -Zmir-enable-passes=+ReferencePropagation -Zlint-mir

#![feature(gen_blocks)]
gen fn foo(z: i32) -> i32 {
    yield z;
    z;
}
pub fn main() {
    let mut iter = foo(3);
    assert_eq!(iter.next(), Some(3))
}

Meta

rustc --version --verbose:

rustc 1.94.0-nightly (ba86c0460 2025-12-06)
binary: rustc
commit-hash: ba86c0460b0233319e01fd789a42a7276eade805
commit-date: 2025-12-06
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.5

Error output

warning: unused variable: `x`
 --> code.rs:2:20
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                    ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: path statement with no effect
 --> code.rs:4:3
  |
4 |   z;
  |   ^^
  |
  = note: `#[warn(path_statements)]` (part of `#[warn(unused)]`) on by default

warning: 2 warnings emitted
Backtrace

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass ReferencePropagation) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyLocals-before-const-prop) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyLocals-after-value-numbering) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass MatchBranchSimplification) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SingleUseConsts) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyConstCondition-after-const-prop) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyComparisonIntegral) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyConstCondition-final) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass RemoveNoopLandingPads) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyCfg-final) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass CopyProp) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass SimplifyLocals-final) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass AddCallGuards) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after pass PreCodegen) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

error: internal compiler error: broken MIR in Item(DefId(0:8 ~ code[4f42]::main)) (after phase change to runtime-optimized) at bb7[1]:
                                encountered `((_2 as variant#3).0: &i32) = copy (_2.2: &i32)` statement with overlapping memory
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^
  |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:106:34 - disabled backtrace
 --> code.rs:2:44
  |
2 | gen fn foo<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
  |                                            ^

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/matthias/vcs/github/CRED/rustc-ice-2025-12-07T22_59_17-462340.txt` to your bug report

note: compiler flags: -Z mir-enable-passes=+Inline -Z mir-enable-passes=+ReferencePropagation -Z lint-mir

query stack during panic:
end of query stack

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    A-mir-optArea: MIR optimizations
    F-gen_blocks`gen {}` expressions that produce `Iterator`s
    on Dec 7, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 7, 2025
  3. matthiaskrgr commented on Dec 7, 2025

    @matthiaskrgr
    MemberAuthor

    bisects to #146566 🤷

  4. added
    S-has-bisectionStatus: A bisection has been found for this issue
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 8, 2025
  5. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Jun 28, 2026
  6. added 5 commits that reference this issue on Jul 30, 2026
    f18efa4
    bc888e5
    2466542
    91a4d35
    c6e3f2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.F-gen_blocks`gen {}` expressions that produce `Iterator`sI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions