Closed
Description
Currently, moving out of a managed box in a match yields an unclear error message that's sometimes difficult to track down:
$ cat foo.rs
struct A {
a: ~int
}
fn free<T>(_: T) {}
fn main() {
let a = &A { a: ~1 };
match a.a {
n => { free(n) }
}
free(a)
}
$ rustc foo.rs
foo.rs:9:10: 9:13 error: cannot move out of dereference of `&`-pointer
foo.rs:9 match a.a {
^~~
error: aborting due to previous error
However when using owned boxes, you get a very nice and clear error message
$ cat foo.rs
struct A {
a: ~int
}
fn free<T>(_: T) {}
fn main() {
let a = ~A { a: ~1 };
match a.a {
n => { free(n) }
}
free(a)
}
$ rustc foo.rs
foo.rs:12:9: 12:10 error: use of partially moved value: `a`
foo.rs:12 free(a)
^
foo.rs:10:8: 10:9 note: `(*a).a` moved here because it has type `~int`, which is moved by default (use `ref` to override)
foo.rs:10 n => { free(n) }
^
error: aborting due to previous error
It'd be awesome to have similar behavior (the extra note) in the managed case as well.