Skip to content

Error message for incorrectly calling method using arbitrary self types is bad #60086

Closed
@Nemo157

Description

@Nemo157
use std::pin::Pin;

trait Foo {
    fn foo(self: Pin<&Self>) {}
}

struct Bar;
impl Foo for Bar {
}

fn main() {
    Bar.foo();
}

(playground) gives an error:

error[E0599]: no method named `foo` found for type `Bar` in the current scope
  --> src/main.rs:12:9
   |
7  | struct Bar;
   | ----------- method `foo` not found for this
...
12 |     Bar.foo();
   |         ^^^
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `foo`, perhaps you need to implement it:
           candidate #1: `Foo`

The error isn't that the trait is unimplemented for Bar, it's that the method requires self: Pin<&Self> and we're trying to pass just Self. The error message should mention the mismatched self-type (and for the builtin types that are supported by arbitrary self types it might even be able to generate proposed fixes).

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.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