Skip to content

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

Closed

Description

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(...)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions