-
Notifications
You must be signed in to change notification settings - Fork 13.4k
use structured suggestion for method calls #57291
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
error[E0616]: field `len` of struct `sub::S` is private | ||
--> $DIR/issue-26472.rs:11:13 | ||
| | ||
LL | let v = s.len; | ||
| ^^^^^ | ||
LL | let v = s.len; //~ ERROR field `len` of struct `sub::S` is private | ||
| ^^--- | ||
| | | ||
| help: a method `len` also exists, call it with parentheses: `len()` | ||
|
||
error[E0616]: field `len` of struct `sub::S` is private | ||
--> $DIR/issue-26472.rs:12:5 | ||
| | ||
= note: a method `len` also exists, perhaps you wish to call it | ||
LL | s.len = v; //~ ERROR field `len` of struct `sub::S` is private | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0616`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,13 @@ error[E0615]: attempted to take value of method `get_x` on type `Point` | |
--> $DIR/method-missing-call.rs:22:26 | ||
| | ||
LL | .get_x;//~ ERROR attempted to take value of method `get_x` on type `Point` | ||
| ^^^^^ | ||
| | ||
= help: maybe a `()` to call it is missing? | ||
| ^^^^^ help: use parentheses to call the method: `get_x()` | ||
|
||
error[E0615]: attempted to take value of method `filter_map` on type `std::iter::Filter<std::iter::Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/method-missing-call.rs:27:20: 27:25]>, [closure@$DIR/method-missing-call.rs:28:23: 28:35]>` | ||
--> $DIR/method-missing-call.rs:29:16 | ||
| | ||
LL | .filter_map; //~ ERROR attempted to take value of method `filter_map` on type | ||
| ^^^^^^^^^^ | ||
| | ||
= help: maybe a `()` to call it is missing? | ||
| ^^^^^^^^^^ help: use parentheses to call the method: `filter_map(...)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be amazing if we inspected the arguments of |
||
|
||
error: aborting due to 2 previous errors | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Though this is a case that will need to be accounted for specifically, as the ideal case would be for the parser to actually be able to parse type setting without the turbofish and emit a customized relevant suggestion to use the turbofish. If we do that, then this error will not trigger.
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.
How would I distinguish this case from something like
where we should still apply the suggestion?
Uh oh!
There was an error while loading. Please reload this page.
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.
What would be the "perfect" suggestion in that case? IMO, that's borderline "unrecoverable": the code is attempting (assumption 1) to set a type argument without using turbofish and (assumption 2) calling that method. Because this requires not one but two assumptions, the likelihood of a suggestion being incorrect increases. In this case we would emit the following, which I think is "good enough" (at least for now):
In an ideal compiler, we could keep around enough information about parse recoveries like the above and figure out if the call and boolean comparison looked like a missing turbofish, and effectively elide errors:
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 suppose a better example is this:
The user is attempting to compare the result of a method call, but forgot the parens. If we don't emit the suggestion because it's parsed as part of a
BinOp
<
, it would be incorrect. How can I distinguish this from a missing turbofish?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.
We'd need to keep track of either
NodeId
s orSpan
s where the turbofish note due to chained comparison operators in a set owned by the parser. We then need to keep that arround in theSess
. When finding this case in the type checker, we look back at thesess
to see if the place where we're about to suggest adding a()
is covered by the turbofish suggestion or not. All of this should be done in a separate PR, as it might quickly become very involved.