-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"borrow of possibly uninitialized variable" instead of "use of moved value" #52669
Comments
I would classify this as a "minor diagnostic improvement". I'm moving to the Milestone and marking as E-needs-mentor. |
EDIT: Duplicate of #21232 this issue may caused by rust/src/librustc_mir/borrow_check/mod.rs Line 1620 in 71a1ef1
rust/src/librustc_mir/borrow_check/mod.rs Line 1631 in 71a1ef1
the comments reason why the uninitialized lint emitted here: for place a.b , if a is moved, then the usage of projection a.b will be treated as uninitialized , let's take an experiment:https://play.rust-lang.org/?gist=12d7880fc733e74b5bac20119465ada3&version=nightly&mode=debug&edition=2015 fn bar(mut a: A) -> B {
a.b = B;
foo(a);
a.b
} =>
========== instead of using place ```rust
fn too(mut a: A) -> A {
a.b = B;
foo(a);
a
} =>
|
Clearly not an RC blocker |
Seems worth fixing to me for RC2 — this could be a "new user stumbling point". |
Might be a good fit for @spastorino, who recently did #46590, which is touching the same code that produces this error. Thoughts @spastorino ? |
…sakis Inspect parents paths when checking for moves Closes #52669
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
Expected behavior
The compiler gives an error about using a moved value, similar to the following:
Without NLL:
With NLL but without the field assignment:
Actual behavior
The error mentions an uninitialized value instead of a moved value:
The text was updated successfully, but these errors were encountered: