-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
NLL: rewrites should include actual source input, not solely the hypothesized rewrites #52877
Comments
One thing that bothers me about this ticket: the rust/src/librustc_mir/borrow_check/move_errors.rs Lines 354 to 360 in 8961132
But if that code isn't doing anything weird to try to construct this diagnostic, then is this in fact a kind of diagnostic that we expect to see in practice? (Note: I am not saying that I dislike printing out lines of hypothetical code. My whole problem here is just about the row of " |
Note also that in comparing with the AST-borrowck code: rust/src/librustc_borrowck/borrowck/gather_loans/move_error.rs Lines 172 to 188 in 8961132
it should indeed be really easy to try to recreate the same combined set of diagnostics here that AST-borrowck is able to produce. if we want that (e.g. by switching to span_label instead of span_diagnostic ...)
|
Okay, after quite a bit of review, I tracked down code in the compiler that decides whether to emit the rust/src/librustc_errors/emitter.rs Lines 1217 to 1222 in ed8d14d
And after I found that line, I was able to find its associated PR, and thus find an example of a test that is making use of this ... "feature" ...: rust/src/test/ui/impl-trait/impl-generic-mismatch.stderr Lines 20 to 25 in ed8d14d
However, that example has a crucial difference. Yes, it prints a rewrite of the code (and highlights the rewritten portion). But, it only does so after it has printed an error that highlights the problem in the original source. And that seems like one potential way to resolve this problem in our case. |
…e-should-precede-suggestions, r=petrochenkov NLL: On "cannot move out of type" error, print original before rewrite NLL: On "cannot move out of type" error, print original source before rewrite. * Arguably this change is sometimes injecting noise into the output (namely in the cases where the suggested rewrite is inline with the suggestion and we end up highlighting the original source code). I would not be opposed to something more aggressive/dynamic, like revising the suggestion code to automatically print the original source when necessary (e.g. when the error does not have a span that includes the span of the suggestion). * Also, as another note on this change: The doc comment for `Diagnostic::span_suggestion` says: ```rust /// The message /// /// * should not end in any punctuation (a `:` is added automatically) /// * should not be a question /// * should not contain any parts like "the following", "as shown" ``` * but the `:` is *not* added when the emitted line appears out-of-line relative to the suggestion. I find that to be an unfortunate UI experience. ---- As a drive-by fix, also changed code to combine multiple suggestions for a pattern into a single multipart suggestion (which vastly improves user experience IMO). ---- Includes the updates to expected NLL diagnostics. Fix rust-lang#52877
…e-should-precede-suggestions, r=petrochenkov NLL: On "cannot move out of type" error, print original before rewrite NLL: On "cannot move out of type" error, print original source before rewrite. * Arguably this change is sometimes injecting noise into the output (namely in the cases where the suggested rewrite is inline with the suggestion and we end up highlighting the original source code). I would not be opposed to something more aggressive/dynamic, like revising the suggestion code to automatically print the original source when necessary (e.g. when the error does not have a span that includes the span of the suggestion). * Also, as another note on this change: The doc comment for `Diagnostic::span_suggestion` says: ```rust /// The message /// /// * should not end in any punctuation (a `:` is added automatically) /// * should not be a question /// * should not contain any parts like "the following", "as shown" ``` * but the `:` is *not* added when the emitted line appears out-of-line relative to the suggestion. I find that to be an unfortunate UI experience. ---- As a drive-by fix, also changed code to combine multiple suggestions for a pattern into a single multipart suggestion (which vastly improves user experience IMO). ---- Includes the updates to expected NLL diagnostics. Fix rust-lang#52877
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-move-out-of-vec-tail.nll.stderr
Lines 6 to 13 in fefe816
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: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 "writeis
instead ofbe
" or even just "writeis
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 aref
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.The text was updated successfully, but these errors were encountered: