Skip to content

confusing diagnostic when calling a method that doesn't exist on a trait but exists on another trait #111312

Closed
@fee1-dead

Description

@fee1-dead

Code

trait Has {
    fn has() {}
}

trait HasNot {}

fn main() {
    HasNot::has();
}

Current output

error[E0782]: trait objects must include the `dyn` keyword
 --> src/main.rs:8:5
  |
8 |     HasNot::has();
  |     ^^^^^^
  |
help: add `dyn` keyword before this trait
  |
8 |     <dyn HasNot>::has();
  |     ++++       +

error[E0599]: no function or associated item named `has` found for trait object `dyn HasNot` in the current scope
 --> src/main.rs:8:13
  |
8 |     HasNot::has();
  |             ^^^ function or associated item not found in `dyn HasNot`
  |
  = help: items from traits can only be used if the trait is implemented and in scope
note: `Has` defines an item `has`, perhaps you need to implement it
 --> src/main.rs:1:1
  |
1 | trait Has {
  | ^^^^^^^^^

Some errors have detailed explanations: E0599, E0782.
For more information about an error, try `rustc --explain E0599`.
error: could not compile `playground` due to 2 previous errors

code snippet by @WaffleLapkin. (this is from December 2022)

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