-
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
Distinguish guesses from suggestions #39458
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
cc @killercup |
failures are legit, but just related to spans in ui tests. I'm fixing them now. |
@oli-obk It looks like you've made |
@@ -1135,6 +1135,7 @@ actual:\n\ | |||
Some(ErrorKind::Error) => true, | |||
Some(ErrorKind::Warning) => true, | |||
Some(ErrorKind::Suggestion) => false, | |||
Some(ErrorKind::Guess) => false, |
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.
guesses are not mandatory
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.
You have just added these annotations to many tests, so I thought they are mandatory now.
yes, about that... I'd like suggestions and guesses to show their help message just like notes are shown. There's no advantage to showing a full help. |
| ^^^ | ||
| | ||
help: did you intend to call a method of the same name? | ||
| self.baz(); |
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.
Suggestions from resolve were intentionally reported "in place" as labels.
See #38154, especially @jonathandturner's comments.
This is a pretty big regression IMO.
src/librustc_errors/diagnostic.rs
Outdated
self | ||
} | ||
|
||
pub fn guess(&mut self, sp: Span, msg: &str, guess: String) -> &mut Self { |
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 thinks span_guess
is a better name, because all other functions taking a span have span in the name. ( for exanple span_suggestion
)
err.span_label(span, &format!("did you mean `self.{}(...)`?", | ||
path_str)); | ||
err.guess(span, "did you intend to call a method of the same name?", | ||
format!("self.{}", path_str)); |
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 prefer self.{}(...)
over self.{}
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.
for foo(5)
that would give the suggestion self.foo(...)(5)
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 though that the span was for the entire call, instead of just the self.{}
part
span, | ||
&format!("did you mean to call the function \ | ||
stored in the `{}` field?", item_name), | ||
format!("({}.{})", expr_string, item_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.
I prefer ({}.{})(...)
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.
see above.
I'm a bit dubious about adding yet another category of error to the compiler. Why do we need |
cc @rust-lang/compiler @rust-lang/tools |
because the suggestion API outputs a copyable snippet of code with context, and help doesn't, because there's usually no need to. |
If we want the user to copy, then why not use a suggestion? |
Because it may have placeholders or be otherwise something that can't directly be copied. We have different types of notes:
|
One thing about guesses is that there can be multiple guesses. E.g.
My proposal is to move this to guesses in json and keep it the same in textual output. The guesses should supply the entire |
☔ The latest upstream changes (presumably #39463) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm not persuaded that it is necessary to separate guesses and suggestions. My work flow for 'automatic application' is that the user opts in to doing this in an IDE or rustfix tool, possibly with some further input. I don't think there is a need or expectation that after such an application the resulting code is guaranteed to be logically correct or even to compile. So, I think a suggestion with placeholders would be fine as would a suggestion with multiple choices. In other words, I'd rather make suggestions more flexible than add another category of error. I strongly dislike the idea that JSON and plain text error messages might be different (JSON might have more info, e.g., show all choices rather than the first 8, or contain full text where the human text elides some source code with elipses, etc.). I think it would be confusing for users to get (semantically) different kinds of message depending on how they view the errors. |
1 similar comment
I'm not persuaded that it is necessary to separate guesses and suggestions. My work flow for 'automatic application' is that the user opts in to doing this in an IDE or rustfix tool, possibly with some further input. I don't think there is a need or expectation that after such an application the resulting code is guaranteed to be logically correct or even to compile. So, I think a suggestion with placeholders would be fine as would a suggestion with multiple choices. In other words, I'd rather make suggestions more flexible than add another category of error. I strongly dislike the idea that JSON and plain text error messages might be different (JSON might have more info, e.g., show all choices rather than the first 8, or contain full text where the human text elides some source code with elipses, etc.). I think it would be confusing for users to get (semantically) different kinds of message depending on how they view the errors. |
Clippy tries pretty hard to make suggestions that will just compile. There's always the small chance it won't, but there's a big difference between "probably will compile" (and if it doesn't it's a clippy bug) and "probably won't compile" (because we knew it wouldn't beforehand). The former is something you can tie up to an automated tool, the latter needs a more interactive UI. I would love to be able to auto-rustfix the vast majority of clippy errors, compile, inspect, and commit, and then go ahead to more manually rustfix the remaining suggestions by applying them one by one. I would represent guesses and suggestions as the same thing in JSON, with an extra "guess" param. |
I guess I just don't think this is realistic, or importantly something we should encourage. Even more so with compiler errors. Let me also expound on the other side of the trade-off: although the taxonomy in #39458 (comment) is sensible, I think it is not reliably adhered to currently and together with errors and warnings all these categories are confusing and poorly used by compiler devs (especially since improving error messages is a prime area for new contributors who often don't have a strong notion of the distinctions). It is also detrimental for users who get a mutli-coloured, chaotic mix of different terms without clear distinctions. I think adding another category will make things worse in both the code and the user experience. I'm not saying we must never add anything, but I do think there should be a really strong case. |
I think from the user's POV it would just be displayed as a suggestion; this is mostly for tools to consume. (This is why I originally proposed it as an additional boolean param that gets reflected in the json) |
I haven't made up my mind on the overall distinction, but some of what @nrc is saying is resonating with me. There is definitely a balance to be struck regarding the number of distinctions, colors, and so forth in our output. I also think that "guaranteed to be correct" (from the wording in the code) is an impossibly high standard for a suggestion to meet: e.g., if you see an I also agree that moving the "Did you mean foo?" suggestions into their own |
@nikomatsakis note that I'm not suggesting this display differently in the regular Rust UI I think part of the issue comes from the fact that I'm mostly thinking about clippy lints, whereas you're thinking about compiler lints. Clippy do tend to have "one correct solution" much more often because they're often dealing with tidying up code. This is just like how we don't worry about the transformations rustfmt applies to our code. With clippy I envision a workflow where you just pipe it through rustfix. Maybe check the diff. Maybe not. Meh. With rustc I envision that you'd pipe it through rustfix, and then definitely check the diff. I'd absolutely love to have a tool like |
Yeah, I hear you, although I chose my example very deliberately. Note that "unused |
That's not what I meant. I mean that guesses are always displayed the way "they" are now. So a single guess is just a note that directly includes the text, e.g.:
Multiple guesses are rendered as
But json displays them uniformly as an array of guesses. So there's no semantic difference, since both suggest the same thing, but are displayed in a readable form or show with enough metadata (json) to be automatically applicable.
This can be tested by running rustfix over the test suite and checking whether run-pass still passes. This could be something done when nightly moves to beta, so it doesn't slow down the regular travis.
I believe that adding guesses actually improves this. Right now we have many notes and helps which contain code snippets. Having an actual place to put them would probably help.
That's why I suggest no not show guesses to users as anything new. Just to introduce a structured way to write guesses. |
OK, sorry I msunderstood, this sounds good.
The other distinctions can't be tested like this though, and I worry about making a muddy picture worse as much as creating mud in the first place. |
@@ -2,7 +2,7 @@ error: no field `baz` on type `Foo` | |||
--> $DIR/issue-36798.rs:17:7 | |||
| | |||
17 | f.baz; | |||
| ^^^ did you mean `bar`? | |||
| ^^^ did you mean `bar` |
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.
Questions have disappeared in many places.
| | | ||
| did you mean `self.whiskers`? | ||
| `self` value is only available in methods with `self` parameter | ||
| ^^^^^^^^ did you intend to access a struct field? `self.whiskers` |
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.
All the diagnostics with 2 labels lose one of the labels
| ^ did you mean `a::I`? | ||
| ^^^ | ||
| | | ||
| did you mean `a::I` |
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.
extraneous
| ^^^
| |
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.
This might be caused by the same span being used as primary and secondary. The primary span didn't have any text, but the secondary did. In terminal output the ^^^
would be red and the did you (...)
would be blue. (This is an educated guess.)
I look at the diagnostics changes and I can't say I like what I see (even after a5965ab). Can this PR be redone in some way to not affect user-visible behavior at all, just to emit some semantic markup into json for tools to use? |
@oli-obk any updates? |
Waiting for the rfc |
Closing in favor of the associated RFC (while we wait on that) |
Change some notes into suggestions r? @petrochenkov since you commented on the same edits in rust-lang#39458
Change some notes into suggestions r? @petrochenkov since you commented on the same edits in rust-lang#39458
Change some notes into suggestions r? @petrochenkov since you commented on the same edits in rust-lang#39458
Change some notes into suggestions r? @petrochenkov since you commented on the same edits in #39458
fixes #33691
cc #37085
fixes #39254