Skip to content

Enhance Error Message For Misusing Methods As Functions #72005

@xfoxfu

Description

@xfoxfu

Consider the following example (playground):

struct S;

trait T {
    fn some(&self) {}
}

impl T for S {}

fn main() {
    let s = S;

    s.some();
    s::some();
}

If there is fn some(&self);, and I called s::some() instead of s.some() (the correct one), the compiler wil emit error[E0433]: failed to resolve: use of undeclared type or module 's'. I think this is hard for developers to understand, and a hint of using method would be better in this case.

To be more precise, when the code misuses methods as functions, in addition to the current E0433, a hint would be provided, for example possible misusing methods as functions, try change to method call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions