-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
add suggestion applicabilities to librustc and libsyntax #50724
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
4d43eb1
to
94965b9
Compare
Thanks for filing #50723 and starting this! This looks pretty good already. There is one more thing I'd do, though: Whenever we say something is |
err.span_suggestion_short(sp, consider, suggestion); | ||
err.span_suggestion_short_with_applicability( | ||
sp, consider, suggestion, Applicability::MaybeIncorrect | ||
); |
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.
Can applicabilities that aren't MachineApplicable all have a comment explaining why?
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.
In most cases, the explanation is just "I don't feel Overwhelmingly Confident that this suggestion will always be what the user wants, even if I don't have an explicit counterexample of reasonable code for which this suggestion is incorrect", because I was imagining MachineApplicability
was a very high standard. (Like you said, we don't want rustfix to guess when it doesn't know.)
If the standard is slightly lower than that (such that MaybeIncorrect
requires a commentable justification stronger than "Well, I'm not sure that it's always correct"), then I'd want to change a lot of these to MachineApplicable
. Thinking on it, that's probably the best long-term decision, for the same reason assertions and static typing are good ideas: better to make slightly too strong assumptions (and then fix the bugs as they're reported), rather than too weak assumptions (and have no way of knowing whether we could successfully auto-fix more things).
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 feel that having the convention of having a comment outlining the reasons the suggestion might be incorrect could be a good start. We can in the future encode this using types.
err.span_suggestion(sp, "try ignoring the field", | ||
format!("{}: _", name)); | ||
err.span_suggestion_with_applicability(sp, "try ignoring the field", | ||
format!("{}: _", name), |
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.
These may need macro checks?
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'm not happy with the situation at the moment. Almost every single suggestion needs to have macro checks. I'll be trying something out to encode this in the API and avoid the current game of whack-a-mole.
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.
Yeah.
So in clippy my plan was that span_to_snippet
would take an &mut applicability
parameter, and whenever it detects a macro in the thing you're using it would automatically flip the applicability.
But also the span you're suggesting for would need a good macro check. idk.
Yeah, the bar is slightly higher for edition stuff.
It's basically that _known_ and _likely_ problems should not be autofixed.
But this is speculative, it's better to mark it machine applicable and then
fix in case there are bugs.
…On Mon, May 14, 2018, 1:08 AM Zack M. Davis ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/librustc/infer/error_reporting/mod.rs
<#50724 (comment)>:
> @@ -1097,7 +1097,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let Some((sp, has_lifetimes)) = type_param_span {
let tail = if has_lifetimes { " + " } else { "" };
let suggestion = format!("{}: {}{}", bound_kind, sub, tail);
- err.span_suggestion_short(sp, consider, suggestion);
+ err.span_suggestion_short_with_applicability(
+ sp, consider, suggestion, Applicability::MaybeIncorrect
+ );
In most cases, the explanation is just "I don't feel Overwhelmingly
Confident that this suggestion will always be what the user wants, even if
I don't have an explicit counterexample of reasonable code for which this
suggestion is incorrect", because I was imagining MachineApplicability
was a very high standard. (Like you said
<#50476 (comment)>, we
don't want rustfix to guess when it doesn't *know*.)
If the standard is slightly lower than that (such that MaybeIncorrect
requires a commentable justification stronger than "Well, I'm not *sure*
that it's always correct"), then I'd want to change a lot of these to
MachineApplicable. Thinking on it, that's probably the best long-term
decision, for the same reason assertions and static typing are good ideas:
better to make slightly too strong assumptions (and then fix the bugs as
they're reported), rather than too weak assumptions (and have no way of
knowing whether we could successfully auto-fix more things).
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#50724 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABivSM54C8hp7ESzN8oKolLJ79-EG4cuks5tyR9rgaJpZM4T89d0>
.
|
☔ The latest upstream changes (presumably #50566) made this pull request unmergeable. Please resolve the merge conflicts. |
Some would argue that this 40-character method name is ludicrously unwieldy (even ironic), but it's the unique continuation of the precedent set by the other suggestion methods. (And there is some hope that someday we'll just fold `Applicability` into the signature of the "basic" method `span_suggestion`.) This is in support of rust-lang#50723.
94965b9
to
fe0bece
Compare
This comment has been minimized.
This comment has been minimized.
Consider this a down payment on rust-lang#50723. To recap, an `Applicability` enum was recently (rust-lang#50204) added, to convey to Rustfix and other tools whether we think it's OK for them to blindly apply the suggestion, or whether to prompt a human for guidance (because the suggestion might contain placeholders that we can't infer, or because we think it has a sufficiently high probability of being wrong even though it's— presumably—right often enough to be worth emitting in the first place). When a suggestion is marked as `MaybeIncorrect`, we try to use comments to indicate precisely why (although there are a few places where we just say `// speculative` because the present author's subjective judgement balked at the idea that the suggestion has no false positives). The `run-rustfix` directive is opporunistically set on some relevant UI tests (and a couple tests that were in the `test/ui/suggestions` directory, even if the suggestions didn't originate in librustc or libsyntax). This is less trivial than it sounds, because a surprising number of test files aren't equipped to be tested as fixed even when they contain successfully fixable errors, because, e.g., there are more, not-directly-related errors after fixing. Some test files need an attribute or underscore to avoid unused warnings tripping up the "fixed code is still producing diagnostics" check despite the fixes being correct; this is an interesting contrast-to/inconsistency-with the behavior of UI tests (which secretly pass `-A unused`), a behavior which we probably ought to resolve one way or the other (filed issue rust-lang#50926). A few suggestion labels are reworded (e.g., to avoid phrasing it as a question, which which is discouraged by the style guidelines listed in `.span_suggestion`'s doc-comment).
fe0bece
to
98a0429
Compare
@Manishearth (updated to be less conservative about choosing |
Ping from triage @Manishearth! This PR needs your review. |
err.span_suggestion(span, "try an outer attribute", suggestion); | ||
err.span_suggestion_with_applicability( | ||
span, "try an outer attribute", suggestion, | ||
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT |
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.
lol
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.
LGTM
@bors r+ thanks! Are there more left? FWIW there are also a bunch of "suggestions" that don't use the suggestion API; for example I think some of the "maybe try this variable name instead" suggestions don't use the suggestion API. With PossiblyIncorrect we can still have rustfix prompt about these in interactive mode. |
📌 Commit 98a0429 has been approved by |
add suggestion applicabilities to librustc and libsyntax A down payment on #50723. Interested in feedback on whether my `MaybeIncorrect` vs. `MachineApplicable` judgement calls are well-calibrated (and that we have a consensus on what this means). r? @Manishearth cc @killercup @estebank
☀️ Test successful - status-appveyor, status-travis |
Yes, I semi-arbitrarily chose two crates (libsyntax and librustc) for this initial PR. (More convenient to get and iterate on feedback on this than a diff that would be five times as large.) |
…ebank App-lint-cability @eminence recently pointed out (rust-lang/cargo#5846) that it's surprising that `cargo fix` (now shipping with Cargo itself!) doesn't fix very common lint warnings, which is as good of a reminder as any that we should finish rust-lang#50723. (Previously, we did this on the librustc and libsyntax crates in rust-lang#50724. I filed rust-lang/this-week-in-rust#685 in hopes of recruiting new contributors to do the rest.) r? @estebank
A down payment on #50723. Interested in feedback on whether my
MaybeIncorrect
vs.MachineApplicable
judgement calls are well-calibrated (and that we have a consensus on what this means).r? @Manishearth
cc @killercup @estebank