Skip to content

tweak temporary lifetime rules for if and while conditions #12033

Closed
@nikomatsakis

Description

@nikomatsakis

I think that if and while conditions should free any temporaries that occur within them (for while conditions it's mandatory, actually, since the condition is evaluated many times).

That is, if I write:

if my_set().borrow().contains(&key) { ... }

the temporary returned by borrow() should be freed once the condition is evaluated, before entering the body of the if.

The same holds for whiles.

What makes these expressions different from other compound forms is that the conditions are evaluated to scalar booleans, and hence can never create lasting aliases that might need to be preserved.

In the case of a while, this is needed because temporaries can never outlive conditional or repeated scopes, and the condition of a while is a repeated scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions