Closed
Description
#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