Skip to content

EndRegion and StorageDead are emitted in the wrong order #43481

Closed
@RalfJung

Description

@RalfJung

This code

fn slice_index() -> u8 {
    let arr: &[_] = &[101, 102, 103, 104, 105, 106];
    arr[5]
}

results in the following MIR (before region erasure):

_3 = &ReScope(Remainder(BlockRemainder { block: NodeId(92), first_statement_index: 0 })) _4;
...
StorageDead(_4);
EndRegion(ReScope(Remainder(BlockRemainder { block: NodeId(92), first_statement_index: 0 })));

So, _4 is borrowed for this scope, but actually it is marked dead before the scope ends. That seems wrong to me, shouldn't _4 have to be live at least until the region ends?

Cc @pnkfelix @nikomatsakis

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.T-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