Closed
Description
use std::io;
fn main() {
// This is ok
match &[(~5,~7)] {
ps => {
let (ref y, _) = ps[0];
io::println(fmt!("1. y = %d", **y));
assert!(**y == 5);
}
}
// This is not entirely ok
match Some(&[(~5,)]) {
Some(ps) => {
let (ref y,) = ps[0];
io::println(fmt!("2. y = %d", **y));
if **y != 5 { io::println("sadness"); }
}
None => ()
}
// This is not ok
match Some(&[(~5,~7)]) {
Some(ps) => {
let (ref y, ref z) = ps[0];
io::println(fmt!("3. y = %d z = %d", **y, **z));
assert!(**y == 5);
}
None => ()
}
}
The output:
1. y = 5
2. y = 5
sadness
3. y = 2 z = 3458764513820540928
task <unnamed> failed at 'assertion failed: **y == 5', /Users/tjc/rust/src/test/run-pass/spawn-env-2.rs:28
In the second match
, the first print statement prints out the right answer, but reading **y
for the second time yields garbage (perhaps y
is wrongly getting moved out of here even though it's a ref binding?). The third match
just prints out garbage.