Uh oh!
There was an error while loading. Please reload this page.
NLL: Improve move error loop detection (was "First shot at #54015") - #54343
Conversation
rust-highfive
commented
Sep 19, 2018
(rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
commented
Sep 19, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rust-highfive
commented
Sep 21, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
nikomatsakis
left a comment
There was a problem hiding this comment.
Updates look good. It'd be nice, if you're up for it, to separate the "rustfmt run" into its own commit (I usually do this by rebasing and "inserting" a rustfmt commit before the "meat").
The main concern though is that the output looks wrong; but then I see there's a travis failure, maybe it just needs to be updated?
There was a problem hiding this comment.
Huh, interesting. This doesn't quite look right, since this location is not a move.
There was a problem hiding this comment.
Is this the current output?
There was a problem hiding this comment.
I expect to see "value used here after move", and the "value moved here..." annotation somewhere else.
nikomatsakis
commented
Sep 21, 2018
Ah, no, the travis failure is that the |
blitzerr
commented
Sep 22, 2018
joydeep$ rustc +stage2 src/test/ui/liveness/liveness-move-in-while.rs error: aborting due to previous error For more information about this error, try |
That is the current error when we compile the file. Expected: But we are getting: It completely ate up this line |
bors
commented
Sep 23, 2018
☔ The latest upstream changes (presumably #54229) made this pull request unmergeable. Please resolve the merge conflicts. |
blitzerr
commented
Sep 26, 2018
let move_site_vec = self.get_moved_indexes(context, mpi);debug!(
- "report_use_of_moved_or_uninitialized: mois={:?}",
+ "report_use_of_moved_or_uninitialized: vec<mois,back_edge>={:?}",
move_site_vec
);
- let mois = move_site_vec.clone().into_iter().map(|x| x.moi).collect();
+ let mois = move_site_vec
+ .clone()
+ .into_iter()
+ .map(|x| {
+ let location = self.move_data.moves[x.moi].source;
+ let span = self.mir.source_info(location).span;
+ debug!("moi {:?}: {:?}", x.moi, span);
+ x.moi
+ })
+ .collect();if move_site_vec.is_empty(){let root_place = self.prefixes(&place,PrefixSet::All).last().unwrap();
@@ -137,12 +146,19 @@ impl<'cx,'gcx,'tcx>MirBorrowckCtxt<'cx,'gcx,'tcx>{""};
- if move_site.traversed_back_edge{
+ // if move_site.traversed_back_edge {
+ // is_loop_move = true;
+ // err.span_label(
+ // span,
+ // format!("value moved{} here in previous iteration of loop", move_msg),
+ // );
+ // }
+ if span == move_span {
+ is_loop_move = true;
err.span_label(
span,format!("value moved{} here in previous iteration of loop", move_msg),);
- is_loop_move = true;}else{
err.span_label(move_span,format!("value moved{} here", move_msg));
move_spans.var_span_label(&mut err,"variable moved due to use in closure"); |
blitzerr
commented
Sep 26, 2018
This change is basically the same error reporting with the back-edge calculation done (but not used). >$ rustc +stage2 ./src/test/ui/liveness/liveness-move-in-while.rs
error[E0382]: borrow of moved value: `y`
--> ./src/test/ui/liveness/liveness-move-in-while.rs:18:24
|
18 | println!("{}", y); //~ ERROR borrow of moved value: `y`| ^ 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
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`.Compiled with stage 1, this is the output: >$ rustc +stage1 ./src/test/ui/liveness/liveness-move-in-while.rs
error[E0382]: borrow of moved value: `y`
--> ./src/test/ui/liveness/liveness-move-in-while.rs:18:24
|
18 | println!("{}", y); //~ ERROR borrow of moved value: `y`| ^ value borrowed here after move
19 |whiletrue { whiletrue { whiletrue { 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
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`. |
rust-highfive
commented
Sep 28, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
davidtwco
left a comment
There was a problem hiding this comment.
This looks really great! Just a couple small things I noticed when taking a look at this.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
nit: could you add is_back_edge to this debug! too? It's useful if someone else ever needs to make a change here and work out what is happening from the logging.
There was a problem hiding this comment.
Thank you. That is a good point.
There was a problem hiding this comment.
nit: perhaps add a comma in this message too.
davidtwco
commented
Sep 28, 2018
I couldn't this to the above review below since you didn't change these lines, but could you change the error message in the below snippet to have a comma so all of the "iteration of loop" messages are consistent? (I'm pretty sure this still makes sense gramatically) ie. rust/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs Lines 48 to 52 in c222479 |
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` traitrust-highfive
commented
Sep 28, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
rust-highfive
commented
Sep 28, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
nikomatsakis
commented
Oct 2, 2018
@bors r |
nikomatsakis
commented
Oct 2, 2018
@bors r+ |
bors
commented
Oct 2, 2018
📌 Commit 671e77d has been approved by |
bors
commented
Oct 2, 2018
bors
commented
Oct 2, 2018
☀️ Test successful - status-appveyor, status-travis |
Closes#54015