-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Emit a better diagnostic when function actually has a 'self' parameter #72308
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Fixes rust-lang#66898 When we are unable to resolve a reference to `self`, we current assume that the containing function doesn't have a `self` parameter, and emit an error message accordingly. However, if the reference to `self` was created by a macro invocation, then resolution will correctly fail, due to hygiene. In this case, we don't want to tell the user that the containing fuction doesn't have a 'self' paramter if it actually has one. This PR checks for the precense of a 'self' parameter, and adjusts the error message we emit accordingly. TODO: The exact error message we emit could probably be improved. Should we explicitly mention hygiene?
5647896
to
b684448
Compare
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.
Code looks good to me.
cc @rust-lang/wg-diagnostics if anyone has a suggestion for the error message.
I haven't been able to think of a better error message. @matthewjasper: Are there any other changes that you'd like me to make? |
I think that it's fine as is. |
📌 Commit b684448 has been approved by |
Rollup of 4 pull requests Successful merges: - rust-lang#72153 (exhaustively check `ty::Kind` during structural match checking) - rust-lang#72308 (Emit a better diagnostic when function actually has a 'self' parameter) - rust-lang#72560 (Enable `glacier` command via triagebot) - rust-lang#72567 (Clean up E0608 explanation) Failed merges: r? @ghost
Fixes #66898
When we are unable to resolve a reference to
self
, we current assumethat the containing function doesn't have a
self
parameter, andemit an error message accordingly.
However, if the reference to
self
was created by a macro invocation,then resolution will correctly fail, due to hygiene. In this case, we
don't want to tell the user that the containing fuction doesn't have a
'self' paramter if it actually has one.
This PR checks for the precense of a 'self' parameter, and adjusts the
error message we emit accordingly.
TODO: The exact error message we emit could probably be improved. Should
we explicitly mention hygiene?