rust-lang / rust-lang/rust

ICE: `statement with overlapping memory`

Open
#149,748 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-mir-opt C-bug F-gen_blocks I-ICE S-bug-has-test S-has-bisection S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE from the code.rs example using the listed nightly compiler flags. Start at compiler/rustc_mir_transform/src/lint.rs:106 and inspect how the MIR passes report the overlapping-memory statement. Done means the example no longer produces an internal compiler error while MIR linting and the listed optimization passes are enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.