]> git.lizzy.rs Git - rust.git/commit
[54015] NLL:Improve move error loop detection
authorRusty Blitzerr <rusty.blitzerr@gmail.com>
Fri, 28 Sep 2018 05:16:29 +0000 (22:16 -0700)
committerRusty Blitzerr <rusty.blitzerr@gmail.com>
Fri, 28 Sep 2018 11:43:48 +0000 (04:43 -0700)
commitd5ae6f7870ff937d69a20078bdbbc2093bde2279
treed96c5175b9e093c99b724a8a38c46db4c11c9f81
parent2ac6cdf6a187d5491af7da36b786b2bbd2fd6e39
[54015] NLL:Improve move error loop detection

Before this patch running the following command would generate the given output:
$ rustc +stage1 src/test/ui/liveness/liveness-move-in-while.rs -Zborrowck=mir -Ztwo-phase-borrows
error[E0382]: borrow of moved value: `y`
 --> src/main.rs:8:24
  |
8 |         println!("{}", y); //~ ERROR use of moved value: `y`
  |                        ^ value borrowed here after move
9 |         while true { while true { while true { x = y; x.clone(); } } }
  |                                                    - value moved here
  |
  = note: move occurs because `y` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait

We want to give the user more hint by telling them that the value was moved in the previous iteration of the
loop. After this patch, the error message adds the phrase "in previous iteration of loop" and in totality
looks like this:

$ rustc +stage1 src/test/ui/liveness/liveness-move-in-while.rs -Zborrowck=mir -Ztwo-phase-borrows
error[E0382]: borrow of moved value: `y`
  --> src/test/ui/liveness/liveness-move-in-while.rs:17:24
   |
17 |         println!("{}", y); //~ ERROR use of moved value: `y`
   |                        ^ value borrowed here after move
18 |         while true { while true { while true { x = y; x.clone(); } } }
   |                                                    - value moved here, in previous iteration of loop
   |
   = note: move occurs because `y` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs