Skip to content

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

Closed

Description

@ChrisJefferson

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

Activity

  1. added
    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.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Nov 26, 2019
  2. added 2 commits that reference this issue on Dec 22, 2019
    3849ccd
    bc2213e
  3. added 2 commits that reference this issue on Jan 3, 2020
    d0fe179
    a436293
  4. ChrisJefferson commented on Jan 4, 2020

    @ChrisJefferson
    ContributorAuthor

    Thanks!

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

Metadata

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