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

Suggest that a method exist with a different self type #79352

Closed
ogoffart opened this issue Nov 23, 2020 · 1 comment
Closed

Suggest that a method exist with a different self type #79352

ogoffart opened this issue Nov 23, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@ogoffart
Copy link
Contributor

ogoffart commented Nov 23, 2020

Consider this code:

use std::pin::Pin;
struct Hello;
impl Hello {
    pub fn foo(self: Pin<&Self>) { }
}

fn main() {
    let h = Box::pin(Hello);
    h.foo();
}

As of Rust 1.48 we get the following (expected) error (and the same error is in nightly)

error[E0599]: no method named `foo` found for struct `Pin<Box<Hello>>` in the current scope
 --> src/main.rs:9:7
  |
9 |     h.foo();
  |       ^^^ method not found in `Pin<Box<Hello>>`

Ideally, it would be great if the method exist with a different self type, the compiler would tell us that this method exist

Suggestion:

  help: there is an associated function of the same name with a different self type: `Pin<&Hello>`

Even better would be if the compiler would know how to hint to use Pin::as_ref() in this case to fix the error. (A bit similar to #65409)

@ogoffart ogoffart added the C-bug Category: This is a bug. label Nov 23, 2020
@SNCPlay42
Copy link
Contributor

Duplicate of #57994

@camelid camelid closed this as completed Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants