-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Off-by-one spans in MIR borrowck errors #46885
Comments
I'll tackle this one. |
Here's what I've figured out so far: I've been tracing the span in the context of the rust/src/librustc_mir/borrow_check/error_reporting.rs Lines 323 to 329 in 51b47dc
This function is called (at least in the example given) by the rust/src/librustc_mir/borrow_check/mod.rs Lines 837 to 845 in 51b47dc
The span is passed to that by its caller, which is the rust/src/librustc_mir/borrow_check/mod.rs Lines 722 to 723 in 51b47dc
The span is passed to that function by its caller, which is the rust/src/librustc_mir/borrow_check/mod.rs Lines 414 to 422 in 51b47dc
We can see from the above snippet that the span is part of a rust/src/librustc_mir/dataflow/mod.rs Lines 340 to 349 in 51b47dc
By adding rust/src/librustc_mir/build/scope.rs Lines 906 to 914 in f536143
At the top of this function, we see that the span originates from the rust/src/librustc_mir/build/scope.rs Lines 835 to 846 in f536143
The caller of this function is rust/src/librustc_mir/build/scope.rs Lines 382 to 394 in f536143
If we print the value of the
We can see the |
So @davidtwco did some more investigation and narrowed the problem to the span produced by this line: rust/src/libsyntax/parse/parser.rs Line 4430 in 0b90e4e
It seems to me that the root problem is actually the span for end brace being |
After running all the ui tests with the change to
There are lots of test results like this. We'll need to dig a bit deeper and find out what is specifically happening in the cases we're seeing an issue with. It seems like in some cases, the span is rust/src/libsyntax/tokenstream.rs Lines 67 to 75 in 2e0ad5a
Then we find that the variables have the following values:
Given this, I think the issue is that the rust/src/libsyntax/parse/parser.rs Lines 305 to 337 in 2e0ad5a
Here we can see that |
So, a little more progress. In the rust/src/libsyntax/parse/lexer/mod.rs Lines 309 to 328 in 07f51fb
The call to If we modify the function to check if
However, in doing this, we end up modifying the borrowck error to:
This seems to suggest that this is dealt with somewhere in the borrowck code (or elsewhere) to move the rust/src/librustc_borrowck/borrowck/mod.rs Lines 1320 to 1327 in 78f24d8
Notice the call to rust/src/librustc_mir/build/scope.rs Lines 698 to 699 in 51b47dc
Except, there's no call to |
@davidtwco your write up on the sleuthing you've had to do is amazingly detailed! Thank you so much for taking the time to figuring this out! |
Fix off-by-one spans in MIR borrowck errors Fixes rust-lang#46885. r? @nikomatsakis
Fix off-by-one spans in MIR borrowck errors Fixes #46885. r? @nikomatsakis
This is a minor thing, but you can see in the below snippet that just below line 18, the
borrowed value only lives until here
is a character to the right of where it is in the Ast equivalent.I've seen it in the following tests and there are probably a handful of others:
The text was updated successfully, but these errors were encountered: