Skip to content

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Sep 27, 2025

When lowering non-overloaded indexing operations to MIR, this uses the temporary lifetime of the index expression for the index temporary, rather than applying the temporary lifetime of the indexing operation as a whole to the index.

For example, in

let x = &xs[i];

previously, the temporary containing the result of evaluating i would live until the end of the block due to the indexing operation being lifetime-extended. Under this PR, the temporary only lives to the end of the let statement because it uses the more precise temporary lifetime of the index expression.

I don't think this will affect semantics in an observable way, but it's consistent with the Reference specification (indices' lifetimes don't get extended) and the more precise StorageDead placement may slightly improve analysis/codegen performance.

r? mir

When lowering non-overloaded indexing operations to MIR, this uses the
temporary lifetime of the index expression for the index, rather than
applying the temporary lifetime of the indexing operation as a whole to
the index.
@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 Sep 27, 2025
@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-lang-radar Items that are on lang's radar and will need eventual work or consideration. 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.

4 participants