-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsfixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsfixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]Misleading error due to Box causing move of struct[/-][+]Misleading error message due to Box causing move of struct[/+]Auto merge of #59114 - matthewjasper:enable-migate-2015, r=<try>
Auto merge of #59114 - matthewjasper:enable-migate-2015, r=pnkfelix
Auto merge of #59114 - matthewjasper:enable-migate-2015, r=pnkfelix