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

trait bound is reported not satisfied although it is #61021

Closed
sidgilles opened this issue May 21, 2019 · 1 comment
Closed

trait bound is reported not satisfied although it is #61021

sidgilles opened this issue May 21, 2019 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sidgilles
Copy link

sidgilles commented May 21, 2019

Hello!

Rustc report an unsatisfied trait bound. However, following the compiler suggestion does not help much. Working with tokio.
Is #43580 also relevant for this one ?
Thanks.

Sample code.

use tokio::codec::{Encoder, Decoder, LinesCodec, Framed};
use tokio::io::{AsyncRead, AsyncWrite, Error};
// other uses here...

struct DummyServer<T, U>{
    pub stream_instant : Box<Stream<Item=Instant, Error=tokio::timer::Error> + Send>,
    pub stream_line : Box<Framed<T, U>>,
    pub closure_timer : Box<FnMut(bool, &mut Box<Framed<T, U>>, Option<<U as Decoder>::Item>) -> () + Send>,
}

impl <T, U> Future for DummyServer<T, U>
    where U : Encoder + Decoder, T : AsyncRead + AsyncWrite
 {
    type Item = ();
    type Error = ();

    fn poll(&mut self) ->  Result<Async<Self::Item>, Self::Error> {
       // some code here...
    }
}

Compiler output.

error[E0277]: the trait bound `U: tokio::codec::Decoder` is not satisfied
  --> driver_com/common/src/main.rs:54:5
   |
54 |     pub closure_timer : Box<FnMut(bool, &mut Box<Framed<T, U>>, Option<<U as Decoder>::Item>) -> () + Send>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `tokio::codec::Decoder` is not implemented for `U`
   |
   = help: consider adding a `where U: tokio::codec::Decoder` bound

This is happening both on stable and nightly, freshly updated.

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.34.2 (6c2484dc3 2019-05-13)
   nightly-x86_64-unknown-linux-gnu updated - rustc 1.36.0-nightly (d35181ad8 2019-05-20)

Dependencies.

[dependencies]
futures = { package = "futures", version = "0.1" }
tokio = { version = "0.1" }

Edit:
This sample code get compiled.
I would say that:

  1. the message help: consider adding a 'where U: tokio::codec::Decoder' bound is misleading as the where clause does not apply on struct definition
  2. it would be nice to see this unusual case in the docs, really nice.
struct DummyServer<T, U : Encoder + Decoder>{
    pub stream_instant : Box<Stream<Item=Instant, Error=tokio::timer::Error> + Send>,
    pub stream_line : Box<Framed<T, U>>,
    pub closure_timer : Box<FnMut(bool, &mut Box<Framed<T, U>>, Option<<U as Decoder>::Item>) -> () + Send>,
}

impl <T,U> Future for DummyServer<T,U>
    where T : AsyncRead + AsyncWrite, U : Encoder + Decoder
 {
    type Item = ();
    type Error = ();

    fn poll(&mut self) ->  Result<Async<Self::Item>, Self::Error> {
       // some code here...
    }
}
@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 May 22, 2019
@estebank estebank added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Oct 8, 2019
@estebank estebank added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Dec 28, 2022
@apiraino
Copy link
Contributor

Closing as an MCVE could not be provided. The provided sample code does not emit the same error anymore, I've tried to compile with rustc 1.34.2 but failed (I guess it makes it even trickier to reproduce today) due to external dependencies not supporting it anymore?

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. D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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