Skip to content

Temporaries in match conditions should be freed if not required to stick around #38355

Closed
@Manishearth

Description

@Manishearth

Currently, the following code works:

    let x = RefCell::new(true);
    
    if *x.borrow() {
        x.borrow_mut();
    }

but this panics:

    let x = RefCell::new(true);
    
    match *x.borrow() {
        _ => { x.borrow_mut(); }
    }

(playpen)

Due to #12033 (implemented in #36029) we free temporaries from if conditions.

We should also free temporaries in match subjects if there are no active borrows from them.

This would be semantically a [breaking change]. I do not think it will change how things compile. I am not sure if we need an rfc for this because IMO the fact that this doesn't work is a bug.

cc @eddyb @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions