Skip to content

Unhelpful error message when using bad receiver type #57994

@RalfJung

Description

@RalfJung

Consider the following piece of code:

use std::pin::Pin; trait Test { fn test(self: Pin<&mut Self>); } fn foo(t: impl Test) { t.test() }

The error here is that test can only be called on Pin<&mut Self>, so t.test does not work. But the error message is less than helpful:

error[E0599]: no method named `test` found for type `impl Test` in the current scope --> src/lib.rs:8:7 | 8 | t.test() | ^^^^ | = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `test`, perhaps you need to implement it: candidate #1: `Test` 

It suggests I import a trait that is already in scope. This leads down the totally wrong path -- not showing the "help" and "note" at all would be better than this. Ideally it could point out the receiver type mismatch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-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