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

Unfelpful error when trying to call member function as free function #66782

Closed
ChrisJefferson opened this issue Nov 26, 2019 · 1 comment · Fixed by #66913
Closed

Unfelpful error when trying to call member function as free function #66782

ChrisJefferson opened this issue Nov 26, 2019 · 1 comment · Fixed by #66913
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ChrisJefferson
Copy link
Contributor

ChrisJefferson commented Nov 26, 2019

I just spent far too long trying to figure out the problem with the following (reduced) code

struct X { i: isize }

impl X {
    fn a(&self, i: usize)
    { }

    fn b(&self)
    { a(self, 2) }
}

Which produces the error:

    Checking playground v0.0.1 (/playground)
error[E0425]: cannot find function `a` in this scope
 --> src/lib.rs:8:7
  |
8 |     { a(self, 2) }
  |       ^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

While I don't expect the code to compile, perhaps mention when trying to call a(self,...) that I should be calling self.a(...)?

@Centril Centril added D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Nov 26, 2019
Centril added a commit to Centril/rust that referenced this issue Dec 22, 2019
Suggest calling method when first argument is `self`

Closes: rust-lang#66782

I've explored different approaches for this MR but I think the most straightforward is the best one.

I've tried to find out if the methods for given type exist (to maybe have a better suggestion), but we don't collect them anywhere and collecting them is quite problematic. Moreover, collecting all the methods would require rewriting big part of the code and also could potentially include performance degradation, which I don't think is necessary for this simple case.
Centril added a commit to Centril/rust that referenced this issue Dec 23, 2019
Suggest calling method when first argument is `self`

Closes: rust-lang#66782

I've explored different approaches for this MR but I think the most straightforward is the best one.

I've tried to find out if the methods for given type exist (to maybe have a better suggestion), but we don't collect them anywhere and collecting them is quite problematic. Moreover, collecting all the methods would require rewriting big part of the code and also could potentially include performance degradation, which I don't think is necessary for this simple case.
Centril added a commit to Centril/rust that referenced this issue Jan 3, 2020
Suggest calling method when first argument is `self`

Closes: rust-lang#66782

I've explored different approaches for this MR but I think the most straightforward is the best one.

I've tried to find out if the methods for given type exist (to maybe have a better suggestion), but we don't collect them anywhere and collecting them is quite problematic. Moreover, collecting all the methods would require rewriting big part of the code and also could potentially include performance degradation, which I don't think is necessary for this simple case.
@bors bors closed this as completed in a436293 Jan 4, 2020
@ChrisJefferson
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants