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

Confusing error when using future wrapper #67338

Closed
Disasm opened this issue Dec 15, 2019 · 2 comments
Closed

Confusing error when using future wrapper #67338

Disasm opened this issue Dec 15, 2019 · 2 comments
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Disasm
Copy link
Contributor

Disasm commented Dec 15, 2019

(Playground)

use std::future::Future;
use std::task::{Context, Poll};
use std::pin::Pin;

pub struct AnyFuture<F> {
    inner: F,
}

impl<F: Future> Future for AnyFuture<F> {
    type Output = F::Output;

    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        self.inner.poll(cx)
    }
}

Error:

error[E0599]: no method named `poll` found for type `F` in the current scope
  --> src/main.rs:13:20
   |
13 |         self.inner.poll(cx)
   |                    ^^^^ method not found in `F`
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `poll`, perhaps you need to restrict type parameter `F` with it:
   |
9  | impl<F: std::future::Future + Future> Future for AnyFuture<F> {
   |      ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Of course, adding the suggested trait bound does not help.

@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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 Dec 15, 2019
@estebank estebank added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Dec 16, 2019
@memoryruins
Copy link
Contributor

Appears to be the same case as #57994

@Disasm
Copy link
Contributor Author

Disasm commented Dec 16, 2019

@memoryruins, indeed. Also works with Rc<Self>, Box<Self> and so on.

pub trait TestTrait {
    fn test(self: Box<Self>);
}

pub struct Wrapper<T> {
    inner: T,
}

impl<T: TestTrait> TestTrait for Wrapper<T> {
    fn test(self: Box<Self>) {
        self.inner.test()
    }
}

@Disasm Disasm closed this as completed Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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

4 participants