Skip to content

MIR borrowck: error message confuses locals and temporaries #46598

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

Merged
merged 7 commits into from
Dec 12, 2017
Merged

MIR borrowck: error message confuses locals and temporaries #46598

merged 7 commits into from
Dec 12, 2017

Conversation

davidtwco
Copy link
Member

@davidtwco davidtwco commented Dec 9, 2017

Fixes #46471 and fixes #46472 (see this Gitter comment).

r? @arielb1

@davidtwco
Copy link
Member Author

davidtwco commented Dec 9, 2017

This isn't quite there yet, the error output is approximately correct, but the spans are a character to the left of what they should be to match exactly. I think this was a issue with tabs locally, not seeing it anymore so consider this resolved.

I'm also not sure that the condition I'm checking is what I should be using for this, but it works.

static lifetime is also hardcoded at the moment, I've seen the note_and_explain_region function and tried to use that but I struggled to find a ScopeTree to pass to it (flow_state.borrows.base_results.operator().scope_tree was closest I could find but was private).

I think it might also be worth splitting the report_borrowed_value_does_not_live_long_enough function into two smaller functions and moving the condition to the callers, it seems to be doing two different things. Interested to hear thoughts on this.

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 9, 2017
@davidtwco davidtwco changed the title WIP: MIR borrowck: error message confuses locals and temporaries MIR borrowck: error message confuses locals and temporaries Dec 10, 2017
@davidtwco
Copy link
Member Author

I've fixed issues referenced in my previous comment and also fixed #46472 as mentioned in this Gitter comment.

I think the function might be getting a bit a unwieldly since it's handling a bunch of cases. I've adjusted tests to allow the handful of places where spans are off by a character.

err.emit();
match &self.describe_place(place) {
Some(description) => {
let mut err = self.tcx.path_does_not_live_long_enough(
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't handle the case where a local needs to live until an end_span, aka

let x = {
    let y = 0;
    &y
};

Copy link
Member Author

Choose a reason for hiding this comment

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

This should now be being handled.

@arielb1
Copy link
Contributor

arielb1 commented Dec 10, 2017

Nice!

@bors r+ p=1

This should go before #46558, which changes the same code.

@bors
Copy link
Collaborator

bors commented Dec 10, 2017

📌 Commit e1723d2 has been approved by arielb1

@arielb1
Copy link
Contributor

arielb1 commented Dec 10, 2017

@bors p=0

This hasn't passed travis yet

@kennytm
Copy link
Member

kennytm commented Dec 10, 2017

@bors r-

Travis failed.

[00:57:14] failures:
[00:57:14]     [ui] ui/nll/capture-ref-in-struct.rs
[00:57:14]     [ui] ui/nll/closure-requirements/escape-argument.rs
[00:57:14]     [ui] ui/nll/closure-requirements/escape-upvar-nested.rs
[00:57:14]     [ui] ui/nll/closure-requirements/escape-upvar-ref.rs

@davidtwco
Copy link
Member Author

I've fixed the previous issue where a local might need to live until an end_span. I've not looked at the other tests which are failing in the Travis build - do these just need updated to have the improved error messages or is this an issue with this PR @arielb1?

@davidtwco
Copy link
Member Author

I've updated the existing tests to use the new error messages. This should now pass Travis.

// See test ui/issue-46471.rs for this case.
RegionKind::ReEarlyBound(_) | RegionKind::ReFree(_) => proper_span,
// See test compile-fail/issue-36082.rs for this case.
_ if name == "borrowed value" => span,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use if !with_name

};

let mut err = self.tcx.path_does_not_live_long_enough(err_span, &name, Origin::Mir);
match borrow.region {
Copy link
Contributor

Choose a reason for hiding this comment

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

There looks to be quite some connection between the span and the error message, so I would prefer to have 4 separate functions - 1 for each distinct error messagee

@kennytm
Copy link
Member

kennytm commented Dec 11, 2017

Travis is still failing.
[00:59:30] ---- [compile-fail] compile-fail/borrowck/borrowck-local-borrow-outlives-fn.rs stdout ----
[00:59:30] 	
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/borrowck/borrowck-local-borrow-outlives-fn.rs:15: unexpected error: '15:5: 15:7: `x` does not live long enough [E0597]'
[00:59:30] 
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/borrowck/borrowck-local-borrow-outlives-fn.rs:16: expected error not found: borrowed value does not live long enough
[00:59:30] 
[00:59:30] error in revision `mir`: 1 unexpected errors found, 1 expected errors not found
...
[00:59:30] ---- [compile-fail] compile-fail/borrowck/borrowck-local-borrow-with-panic-outlives-fn.rs stdout ----
[00:59:30] 	
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/borrowck/borrowck-local-borrow-with-panic-outlives-fn.rs:16: unexpected error: '16:15: 16:23: `z.1` does not live long enough [E0597]'
[00:59:30] 
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/borrowck/borrowck-local-borrow-with-panic-outlives-fn.rs:18: expected error not found: [E0597]
[00:59:30] 
[00:59:30] error in revision `mir`: 1 unexpected errors found, 1 expected errors not found
...
[00:59:30] ---- [compile-fail] compile-fail/region-borrow-params-issue-29793-big.rs stdout ----
[00:59:30] 	
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/region-borrow-params-issue-29793-big.rs:84: unexpected error: '84:5: 84:6: `x` does not live long enough [E0597]'
[00:59:30] 
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/region-borrow-params-issue-29793-big.rs:84: unexpected error: '84:5: 84:6: `y` does not live long enough [E0597]'
[00:59:30] 
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/region-borrow-params-issue-29793-big.rs:84: expected error not found: borrowed value does not live long enough
[00:59:30] 
[00:59:30] error in revision `mir`: /checkout/src/test/compile-fail/region-borrow-params-issue-29793-big.rs:84: expected error not found: borrowed value does not live long enough
[00:59:30] 
[00:59:30] error in revision `mir`: 2 unexpected errors found, 2 expected errors not found

If nothing goes wrong, #46558 will be merged soon, so you'll likely need to rebase.

@arielb1
Copy link
Contributor

arielb1 commented Dec 11, 2017

@kennytm

We're working on it.

@bors
Copy link
Collaborator

bors commented Dec 11, 2017

☔ The latest upstream changes (presumably #46558) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco
Copy link
Member Author

All previous issues should be resolved and it's now rebased on top of the current master (or as of an hour ago).

},
// This case should not happen.
RegionKind::ReLateBound(_, _) | RegionKind::ReSkolemized(_, _) |
RegionKind::ReErased => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indentation

@davidtwco
Copy link
Member Author

Alright, fifth time lucky. I've fixed the indentation and other requested changes from Gitter and updated the failing tests from the recent Travis run.

@arielb1
Copy link
Contributor

arielb1 commented Dec 12, 2017

That's cool!

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 12, 2017

📌 Commit 3dbc11b has been approved by arielb1

@bors
Copy link
Collaborator

bors commented Dec 12, 2017

⌛ Testing commit 3dbc11b with merge 7245006...

bors added a commit that referenced this pull request Dec 12, 2017
MIR borrowck: error message confuses locals and temporaries

Fixes #46471 and fixes #46472 (see [this Gitter comment](https://gitter.im/rust-impl-period/WG-compiler-nll?at=5a2d5cb53ae2aa6b3facf0c2)).

r? @arielb1
@bors
Copy link
Collaborator

bors commented Dec 12, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing 7245006 to master...

@bors bors merged commit 3dbc11b into rust-lang:master Dec 12, 2017
@davidtwco davidtwco deleted the issue-46471 branch December 20, 2017 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
4 participants