Skip to content
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

MIR-borrowck: should distinguish "uninitalized" from "moved out of" #45363

Closed
pnkfelix opened this issue Oct 18, 2017 · 1 comment · Fixed by #45877
Closed

MIR-borrowck: should distinguish "uninitalized" from "moved out of" #45363

pnkfelix opened this issue Oct 18, 2017 · 1 comment · Fixed by #45877
Labels
A-borrow-checker Area: The borrow checker T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

The AST-borrowck is often able to distinguish a path that was never assigned into (i.e. "uninitialized") from a path that had previously held a value but that value was subsequently moved elsewhere (i.e. "moved out of").

The MIR-borrowck currently uniformly reports both cases as instances of "uninitialized" state.

As an example: for the test src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs, we have these diagnostics emitted:

% ./build/x86_64-unknown-l\
inux-gnu/stage1/bin/rustc -Z borrowck-mir ../src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs
error[E0382]: use of moved value: `x` (Ast)
  --> ../src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs:31:20
   |
31 |     let _y = {x} + x.clone(); // the `{x}` forces a move to occur
   |               -    ^ value used here after move
   |               |
   |               value moved here
   |
   = note: move occurs because `x` has type `foo`, which does not implement the `Copy` trait

error[E0381]: borrow of possibly uninitialized variable: `x` (Mir)
  --> ../src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs:31:20
   |
31 |     let _y = {x} + x.clone(); // the `{x}` forces a move to occur
   |                    ^ use of possibly uninitialized `x`

error: aborting due to 2 previous errors

The first one is AST-borrowck, the second one MIR-borrowck.

Note in particular that AST-borrowck not only uses more precise language, but more importantly, it reports the specific span where the preceding move out occurred. This is perhaps the most important aspect of the diagnostic (especially for new-comers to Rust and move-semantics).

@pnkfelix pnkfelix added WG-compiler-nll A-borrow-checker Area: The borrow checker T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2017
@mikhail-m1
Copy link
Contributor

I'd like to take it.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 11, 2017
…d, r=arielb1

restore move out dataflow, add report of move out errors

fix rust-lang#45363
r? @arielb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants