Skip to content

Calling a trait method as a free function yields odd diagnostics #98938

Description

@yoshuawuyts

Given the following code: playground

trait Foo {
    fn bar() {}
}

fn main() {
    Foo::bar();
}

The current output is:

error[E0283]: type annotations needed
 --> src/main.rs:4:5
  |
4 |     Foo::bar();
  |     ^^^^^^^^ cannot infer type
  |
  = note: cannot satisfy `_: Foo`

Ideally the output should look like:

Cannot call trait method as a free function. It needs an actual type to be implemented on for it to be called.

For bonus points: The trait is currently not callable since it's not implemented for anything. It needs to actually be implemented. "It looks like you're trying to call this trait method, but nothing implements it."

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.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