Skip to content

Let-else does not drop temporaries at the end of the statement #98672

@camsteffen

Description

@camsteffen

This bug has already been identified but I wanted to open an issue for it.

The following code should print I've been dropped first. (playground)

#![feature(let_else)]

#[derive(Default)]
struct Droppy { inner: u32 }

impl Drop for Droppy {
    fn drop(&mut self) {
        println!("I've been dropped");
    }
}

fn main() {
    let 0 = Droppy::default().inner else { return };
    println!("Should have dropped 👆");
}

I believe there is an unanswered question: Should temporaries be dropped before the else block?

    let 1 = Droppy::default().inner else {
        println!("Should have dropped?????");
        return;
    };

@nikomatsakis said this issue is being investigated at #93628 (comment).

This issue has been assigned to @dingxiangfei2009 via this comment.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-let_elseIssues related to let-else statements (RFC 3137)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions