Skip to content

fix(coroutine): split overlapping state assignments#155841

Open
MilkBlock wants to merge 5 commits intorust-lang:mainfrom
MilkBlock:fix-overlapping-memory-lint-in-coroutine
Open

fix(coroutine): split overlapping state assignments#155841
MilkBlock wants to merge 5 commits intorust-lang:mainfrom
MilkBlock:fix-overlapping-memory-lint-in-coroutine

Conversation

@MilkBlock
Copy link
Copy Markdown

@MilkBlock MilkBlock commented Apr 26, 2026

r? @cijiugechu

Fix #149748

coroutine.rs generated self-assign stmt when crossing yield stmt, which confused the linter.

This PR inserts additional temporary variable to make linter happy.

Before Patch

  bb1: {
      StorageLive(_3);
      _3 = copy ((*_1).0: &i32);
      StorageLive(_4);
      _4 = copy ((*_1).1: &i32);
      nop;
      (((*_1) as variant#3).0: &i32) = copy ((*_1).2: &i32);
      StorageLive(_6);
      StorageLive(_7);
      _7 = copy _4;
      _0 = Option::<&i32>::Some(move _7);
  }
  

After Patch

  bb1: {
      StorageLive(_3);
      _3 = copy ((*_1).0: &i32);
      StorageLive(_4);
      _4 = copy ((*_1).1: &i32);
      nop;
      _10 = copy ((*_1).2: &i32);
      (((*_1) as variant#3).0: &i32) = move _10;
      StorageLive(_6);
      StorageLive(_7);
      _7 = copy _4;
      _0 = Option::<&i32>::Some(move _7);
  }

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

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

This comment has been minimized.

@saethlin
Copy link
Copy Markdown
Member

saethlin commented Apr 26, 2026

r? saethlin (the person you selected is not a compiler reviewer)

Did you check that the ICE reported still happens? I can't make the compiler hit it.

@rustbot rustbot assigned saethlin and unassigned cijiugechu Apr 26, 2026
@MilkBlock
Copy link
Copy Markdown
Author

r? saethlin (the person you selected is not a compiler reviewer)

Did you check that the ICE reported still happens? I can't make the compiler hit it.

This can be reproduced by

rustc +nightly --edition=2024 \
    -Zmir-enable-passes=+Inline,+ReferencePropagation \
    -Zlint-mir \
    ./tests/ui/coroutine/issue-149748.rs
rustc +nightly --version
rustc 1.97.0-nightly (ca9a134e0 2026-04-26)

given code in issue-149748.rs

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

#![feature(gen_blocks)]
#![allow(unused_variables, path_statements)]

struct NonCopy(i32);

gen fn refs<'a, 'b>(x: &'a i32, y: &'b i32, z: &'b i32) -> &'b i32 {
    yield y;
    z;
}

gen fn moves(x: NonCopy, y: NonCopy, z: NonCopy) -> NonCopy {
    yield y;
    z;
}

fn main() {
    let z = 3;
    let mut refs_iter = refs(&1, &2, &z);
    assert_eq!(refs_iter.next(), Some(&3));

    let mut moves_iter = moves(NonCopy(1), NonCopy(2), NonCopy(3));
    assert!(matches!(moves_iter.next(), Some(_)));
}

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

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: statement with overlapping memory

5 participants