Skip to content

Confusing error message related to Sized when actually trait import needed #35550

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

Closed
alexcrichton opened this issue Aug 9, 2016 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@alexcrichton
Copy link
Member

This gist contains all the code, the relevant file being this one.

When compiling, I get:

$ rustup run nightly cargo run
   Compiling wut v0.1.0 (file:///home/alex/code/wut)
error[E0277]: the trait bound `futures::stream::Stream<Item=(futures_mio::TcpStream, std::net::SocketAddr), Error=std::io::Error>: std::marker::Sized` is not satisfied
  --> src/main.rs:24:32
   |
24 |         let welcomes = clients.and_then(|(socket, _peer_addr)| {
   |                                ^^^^^^^^
   |
   = note: `futures::stream::Stream<Item=(futures_mio::TcpStream, std::net::SocketAddr), Error=std::io::Error>` does not have a constant size known at compile-time

error: no method named `fold` found for type `futures::stream::AndThen<futures::stream::Stream<Item=(futures_mio::TcpStream, std::net::SocketAddr), Error=std::io::Error>, [closure@src/main.rs:24:41: 26:10], futures_io::WriteAll<futures_mio::TcpStream, &[u8; 29]>>` in the current scope
  --> src/main.rs:27:18
   |
27 |         welcomes.fold((), |(), (socket, _welcome)| {
   |                  ^^^^
   |
   = note: the method `fold` exists but the following trait bounds were not satisfied: `futures::stream::AndThen<futures::stream::Stream<Item=(futures_mio::TcpStream, std::net::SocketAddr), Error=std::io::Error>, [closure@src/main.rs:24:41: 26:10], futures_io::WriteAll<futures_mio::TcpStream, &[u8; 29]>> : std::iter::Iterator`

error: aborting due to 2 previous errors

error: Could not compile `wut`.

To learn more, run the command again with --verbose.

The real error here is that I forgot to import the Stream trait, but instead I'm seeing a few points which confused me:

  • Talking about Sized is mega-confusing as it's not really related.
  • Printing the full type here ends up being somewhat harmful
  • At the end it's talking about Iterator, but that's unrelated in this case

cc @jonathandturner
cc @nikomatsakis

@alexcrichton alexcrichton added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 9, 2016
@sophiajt sophiajt self-assigned this Aug 9, 2016
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of #35976 duplicate issue.

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
Projects
None yet
Development

No branches or pull requests

4 participants