Skip to content

Values moved in a match get dropped too late #15438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dotdash opened this issue Jul 4, 2014 · 1 comment
Closed

Values moved in a match get dropped too late #15438

dotdash opened this issue Jul 4, 2014 · 1 comment
Labels
A-codegen Area: Code generation A-destructors Area: Destructors (`Drop`, …)

Comments

@dotdash
Copy link
Contributor

dotdash commented Jul 4, 2014

#15076 removed the extra alloca created for by-value bindings in a match. Unfortunately, that also changed at which point the value gets dropped. The previous (and IMHO desired/correct) behaviour was to drop the value when the match binding goes out of scope, but now the value gets dropped when the matched value goes out of scope.

Example:

struct S {
name: &'static str,
}

impl Drop for S {
    fn drop(&mut self) {
        println!("Dropping {}", self.name);
    }
}

pub fn main() {
    let matched = S { name: "Matched" };
    let outer = S { name: "Outer" };
    {
        match matched {
            s => {
            }
        }
        let inner = S { name: "Inner" }; 
    }
}

Output:

Old (rustc 0.11.0-pre (bab614f5fa725d248afc5f0530c835f37998ce8f 2014-06-25 08:06:21 +0000)):
===
Dropping Matched
Dropping Inner
Dropping Outer

New (rustc 0.11.0 (36d7d746c8366d78b332cffdff85318e709b38ca 2014-07-04 10:16:21 +0000)):
===
Dropping Inner
Dropping Outer
Dropping Matched
@dotdash
Copy link
Contributor Author

dotdash commented Jul 4, 2014

This caused memory usage to go up quite a bit. Compiling librustc goes from hovering around 1GB and peaking around 1.6G to hovering around 2G and peaking and 2.5G.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-destructors Area: Destructors (`Drop`, …)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants