-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
regression: rustc suggests .as_ref()
at incorrect location and other spans have regressed
#90286
Comments
My hunch is that this regression is caused by the change in error spans between stable and beta, which also feels like a regression to me since it makes the span less specific: stable:
beta:
|
searched nightlies: from nightly-2021-09-29 to nightly-2021-10-21 bisected with cargo-bisect-rustc v0.6.1Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --preserve --test-dir=tstdr --end=2021-10-21 --script=./test.sh
#!/bin/sh
cargo check 2>&1 | grep " ^^^ move occurs because" |
The new spans caused this suggestion regression, and I feel like they make the errors harder to read in some cases. |
@camelid: Setting aside the incorrect suggestion for the moment, I think the new span is better. By itself, pointing to However, I think adding a note could help emphasize that the method is causing the move (we already do this for other borrowcheck errors). The incorrect suggestion is tricky - I'll see if I can do something about that. |
I understand, and I can see how highlighting the whole call is more correct in some ways, but then a lot of code is highlighted, which can be visually distracting. I wonder if it could make sense to highlight just the method name?
Although that looks a bit weird. Another option is something like this:
Additionally, a large part of why I feel the new span is visually distracting is that |
When a function call is multiline a lot of unnecessary context is also included:
I personally agree with @camelid that a diagnostic like this would be better:
While it's nice to highlight the function call that caused the move, I don't think that it's necessary to highlight all arguments. And the function probably shouldn't be highlighted with the receiver, they are in a sense separate entities that contributed to the error, so their highlighting should be split/different. |
I'll see if I can experiment with some different solutions and see how well they work in practice. |
Hmm, I'm not sure if there's a way to separately point to the variable and the function name without either making For now, I think I could split the label into a label and a note like discussed above without it being too big of a change. But that also wouldn't fix this regression. |
Some of the diagnostic changes in #89110 IMO feel like they make the errors much more confusing: error[E0597]: `z` does not live long enough
--> $DIR/regions-escape-loop-via-vec.rs:7:17
|
LL | _y.push(&mut z);
- | -- ^^^^^^ borrowed value does not live long enough
- | |
+ | --------^^^^^^-
+ | | |
+ | | borrowed value does not live long enough
| borrow later used here Does it make sense to revert that PR for now until we can figure out a way to improve the errors that doesn't cause regressions and make some errors more confusing? |
I'm also surprised that there wasn't a test for the |
Another thing I wanted to note is that changing the spans of expressions may reduce debuginfo precision, as the - let mut _3: &str; // in scope 0 at $DIR/no-spurious-drop-after-call.rs:9:20: 9:22
+ let mut _3: &str; // in scope 0 at $DIR/no-spurious-drop-after-call.rs:9:20: 9:34 |
.as_ref()
at incorrect location.as_ref()
at incorrect location and other spans have regressed
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-high |
@rustbot claim |
@pnkfelix we're ~1 week out from release, will you be able to prepare the revert in time, or do we need to find someone else to do that? |
I'd looked at this a few weeks back: the problem is that reverting this causes another bug to resurface. We need two different spans for both these suggestions (and the one that were "fixed" by the PR with the regression) to work correctly :-/ If needed I can try and fix it next week before the release, but I'll need someone to be responsive for the review. |
Could, as a temporary somewhat-partial mitigation, the |
Triage: fixed in current beta:
|
add a ui test for `.as_ref` suggestion Closes rust-lang#90286
add a ui test for `.as_ref` suggestion Closes rust-lang#90286
Hm, it seems like there are already tests for |
should we wait for the commits which seem to fix this to hit stable, or can we close this already? |
We can close now. |
…stment-error, r=oli-obk (re-)tighten sourceinfo span of adjustments in MIR Diagnostics rely on the spans of MIR statements being (approximately) correct in order to give suggestions relative to that span (i.e. `shrink_to_hi` and `shrink_to_lo`). I discovered that we're *intentionally* lowering THIR exprs with their parent expr's span if they come from adjustments that are due to a parent expression. While I understand why that may be desirable to demonstrate the relationship of an adjustment and the expression that requires it, it leads to 1. very verbose borrowck output 2. incorrect spans for suggestions Some diagnostics get around that by giving suggestions relative to other spans we've collected during MIR lowering, such as the span of the method's identifier (e.g. `name` in `.name()`), but this doesn't work too well when things come from desugaring. I assume it also has lead to numerous tweaks and complications to diagnostics code down the road, which this PR doesn't necessarily aim to fix but may open the gates to fixing later... The last three commits are simplifications due to the fact that we can assume that the move span actually points to what is being moved (and a test). This regressed in rust-lang#89110, which was debated somewhat in rust-lang#90286. cc `@Aaron1011` who originally made this change. r? diagnostics Fixes rust-lang#113547 Fixes rust-lang#111016
Code
Playground (regressed rustc version)
Output (stable 1.56.0, good)
Output (beta 1.57.0-beta.2, incorrect)
The text was updated successfully, but these errors were encountered: