Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This second error is a bit surprising. I don't quite understand what it is saying, it looks a bit fishy.
cc @pnkfelix -- agreed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that there should be no error here at all? Or just that the error should be focused on prefixes of the field projections it is currently highlighting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think there should be an error at all, and certainly not with these spans. Usually something like this:
gives only one error, right?
i.e., one borrow comes first, and it "wins"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: https://play.rust-lang.org/?gist=695ae34722e06a4060c38df82a45c92d&version=nightly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, looking into this a little bit, here is what I've figured out:
rust/src/librustc_mir/util/borrowck_errors.rs
Lines 225 to 247 in fd0f292
The error is reported in the above function. That is called by the following function:
rust/src/librustc_mir/borrow_check/error_reporting.rs
Lines 259 to 272 in fdecb05
This is quite similar to the work done for #47607, in that PR, I added a set that contains the place/span of any errors reported so that they aren't reported again. In this case, the span on line 37 on the below error (that we want) would be in this set:
I'm not entirely sure what the unintended side effects of the following might be, but we could check if the
issued_spanis in the set (in the above example, that is the error on line 34, but in the second unintended error, that would refer to the same location as above on line 37) and if it is, skip this error. It would essentially silence errors that overlap where the second borrow location of the first error is the first borrow location in subsequent errors. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidtwco do you think you could gist the output from
-Zdump-mir=nllfor this function?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikomatsakis is this what you're looking for?
https://gist.github.com/nikomatsakis/b0ac3440933b3ae1d4dc3db02d738111
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep but I was hoping for a gist :) kind of hard to digest inline...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated your comment =)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a gist with some logging added in
access_placeandcheck_access_for_conflictthat should show the variable values. Lines 13730 to 13759 for the first error and lines 13912 to 13959 for the second error.