Closed
Description
This example causes a misleading error message:
struct FooInner {
value1: Option<String>,
value2: Option<String>,
}
struct Foo(Box<FooInner>);
fn main() {
let foo = Foo(Box::new(FooInner {
value1: Some("Hello World".to_string()),
value2: Some("Hello World".to_string()),
}));
let inner = foo.0;
// uncoment this line to fix the error
//let inner = *inner;
let x = inner.value1;
let y = inner.value2;
println!("{:?}", x);
println!("{:?}", y);
}
Error message:
error[E0382]: use of moved value: `inner`
--> src/main.rs:16:9
|
15 | let x = inner.value1;
| - value moved here
16 | let y = inner.value2;
| ^ value used here after move
|
= note: move occurs because `inner.value1` has type `std::option::Option<std::string::String>`, which does not implement the `Copy` trait
I would have expected the compiler informing me that the entire struct was moved due to the box involved.