Closed
Description
NLL combined with a struct field assignment gives an error mentioning the use/borrow of an uninitialized variable instead of the use/borrow of a moved variable.
Reproduction example
Simplified code based on @Yatekii's question on IRC
Playground
#![feature(nll)]
struct A {
b: B,
}
#[derive(Clone)]
struct B;
fn foo(_: A) {}
fn bar(mut a: A) -> B {
// Commenting the line below gives a move error instead of uninitialized
// error.
a.b = B;
foo(a);
a.b.clone()
}
fn main() {}
Expected behavior
The compiler gives an error about using a moved value, similar to the following:
Without NLL:
error[E0382]: use of moved value: `a.b`
--> src/main.rs:17:5
|
16 | foo(a);
| - value moved here
17 | a.b.clone()
| ^^^ value used here after move
|
= note: move occurs because `a` has type `A`, which does not implement the `Copy` trait
With NLL but without the field assignment:
error[E0382]: borrow of moved value: `a.b`
--> src/main.rs:17:5
|
16 | foo(a);
| - value moved here
17 | a.b.clone()
| ^^^ value borrowed here after move
|
= note: move occurs because `a` has type `A`, which does not implement the `Copy` trait
Actual behavior
The error mentions an uninitialized value instead of a moved value:
error[E0381]: borrow of possibly uninitialized variable: `a.b`
--> src/main.rs:17:5
|
17 | a.b.clone()
| ^^^ use of possibly uninitialized `a.b`