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

Improve move related error messages #47093

Closed
wants to merge 2 commits into from
Closed

Conversation

vramana
Copy link
Contributor

@vramana vramana commented Dec 31, 2017

Fixes #46599

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@vramana
Copy link
Contributor Author

vramana commented Dec 31, 2017

r? @arielb1

@vramana vramana force-pushed the fix-46599 branch 2 times, most recently from c3ad3ac to 6ce408c Compare January 1, 2018 14:21
@vramana vramana changed the title [WIP] Improve move related error messages Improve move related error messages Jan 1, 2018
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! A couple of nitpicks inline. Once addressed, r=me.

@@ -8,18 +8,22 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir

struct FancyNum {
num: u8,
}

fn main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're at this, could we move this file to test/ui?

struct FancyNum {
num: u8,
}

fn main() {
let fancy_num = FancyNum { num: 5 };
let mut fancy_num = FancyNum { num: 5 };
let fancy_ref = &fancy_num;

let x = move || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a secondary span label pointing at move || saying "moved into this closure"?

// If the move occurs due to a closure, then we want to show the span
// of the place where it's used in the closure.
let closure_span = this.find_closure_span(place_span.1, context.loc);
if let Some((_, var_span)) = closure_span {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first span is the args_span, you could use it to add a secondary span label pointing at move || saying "moved into this closure". That way there's no ambiguity (think of the case of nested closures).

let closure_span = this.find_closure_span(place_span.1, context.loc);
if let Some((_, var_span)) = closure_span {
let place_span = (place_span.0, var_span);
this.report_move_into_closure(context, place_span, &borrow);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

report_move_into_closure could be called from report_move_out_while_borrowed as it already has the context and place_span, the only things needed to verify wether it happened to be a closure move.

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 3, 2018
@nikomatsakis
Copy link
Contributor

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned arielb1 Jan 4, 2018
@carols10cents
Copy link
Member

r? @estebank

@carols10cents carols10cents added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2018
@kennytm
Copy link
Member

kennytm commented Jan 17, 2018

Hi @vramana! Would you like to fix the remaining nit picks in #47093 (review)? Thanks!

@vramana
Copy link
Contributor Author

vramana commented Jan 17, 2018

@kennytm Yes. I was a little busy the past week or so. I will fix the nits soon.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 24, 2018
@pietroalbini
Copy link
Member

Hi @vramana, could you address #47093 (review) so the PR can be merged?

@shepmaster
Copy link
Member

Thank you for your hard work, @vramana ! Unfortunately, we haven't head from you in a few weeks, so we are going to go ahead and close this PR to keep the queue tidy. Please feel free to address the feedback and reopen this PR!

@shepmaster shepmaster closed this Feb 9, 2018
@shepmaster shepmaster added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants