Skip to content
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

Merged
merged 1 commit into from
May 25, 2020

Conversation

Aaron1011
Copy link
Member

Fixes #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?

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2020
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?
Copy link
Contributor

@matthewjasper matthewjasper left a 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.

@Aaron1011
Copy link
Member Author

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?

@matthewjasper
Copy link
Contributor

I think that it's fine as is.
@bors r+

@bors
Copy link
Contributor

bors commented May 25, 2020

📌 Commit b684448 has been approved by matthewjasper

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 25, 2020
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
@bors bors merged commit 65607fb into rust-lang:master May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing "this function doesn't have a self parameter" hint when using macro
4 participants