Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Nemo157 opened this issue Apr 18, 2019 · 1 comment
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Apr 18, 2019

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

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 18, 2019
@Nemo157
Copy link
Member Author

Nemo157 commented Apr 22, 2019

And just noticed that this is a dupe of #57994.

@Nemo157 Nemo157 closed this as completed Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants