NLL: rewrites should include actual source input, not solely the hypothesized rewrites #52877
Description
While working on #52663, I noticed something I had not seen before: the .nll.stderr
files for borrowck-move-out-of-vec-tail.nll.stderr and borrowck-vec-pattern-nesting.nll.stderr have an odd characteristic: they print out highlighted spans that do not actually correspond to the actual input source code, but rather correspond to the hypothetical rewritten code that we are asking the user to type in.
Let me explain with actual pointers to lines in the files:
This is what the .nll.stderr
files say we expect to see from the compiler (and what the compiler is actually printing under NLL mode, modulo details like the specific line numbers in the left-hand column):
rust/src/test/ui/borrowck/borrowck-vec-pattern-nesting.nll.stderr
Lines 65 to 76 in fefe816
In the .nll.stderr
files that I linked above, the highlighted spans correspond to these lines:
rust/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.rs
Lines 29 to 34 in fefe816
rust/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs
Lines 77 to 79 in fefe816
(Do you see the problem? If not, read on...)
The problem I have with this is that when I see output from rustc
like:
here be some code
^^
I expect to actually find the actual text here is some code
in my source file. If the diagnostic wants to include a suggestion that we replace "be" with "is", then I expect that to appear as help text that says something like "write is
instead of be
" or even just "write is
here" (with the "be" highlighted, as above)
In short, the user experience (at least for me) from the current NLL is a bit frustrating, because when I see the error message, it seems like it is saying "insert a ref
here", but then from my point of view it is printing out the source code and my reaction is "there already is a ref
there" (because I'm staring at the print-out in the user terminal and not the source code in my text editor).
The fix for this should be simple: identify the cases that are creating these strange diagnostics, and replace them with something more traditional. Note in particular that in both the cases above, the AST-borrowck generated error is more normal:
rust/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr
Lines 4 to 14 in fefe816
rust/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr
Lines 64 to 69 in fefe816
However, if someone can point me at at an established precedent for this pattern (lets say at least three examples) in the current rustc
, then I would also be willing to accept that this is something we already do and that I am just an old fogie who is unaware of how the UX tide is shifting.