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

Improve compiler errors #71032

Closed
manuels opened this issue Apr 11, 2020 · 1 comment
Closed

Improve compiler errors #71032

manuels opened this issue Apr 11, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@manuels
Copy link

manuels commented Apr 11, 2020

If you use traits error messages can become very long and complicated to read.

Consider this error message:

error[E0599]: no method named `into_stream` found for type `futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>>` in the current scope
   --> src/main.rs:220:19
    |
220 |     let foo = foo.into_stream();
    |                   ^^^^^^^^^^^ method not found in `futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>>`
    |
    = note: the method `into_stream` exists but the following trait bounds were not satisfied:
            `&futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> : futures_util::future::future::FutureExt`
            `&futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> : futures_util::stream::try_stream::TryStreamExt`
            `&mut futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> : futures_util::future::future::FutureExt`
            `&mut futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> : futures_util::stream::try_stream::TryStreamExt`
            `futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> : futures_util::future::future::FutureExt`
            `futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> : futures_util::stream::try_stream::TryStreamExt`

Especially people new to rust can be overwhelmed by all the information and a lot of information here is redundant because the type of foo is repeated over and over again. pas_mtts on reddit came up with the idea to replace the actual type of foo (futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>> ) with typeof(foo), so the error message would look like this:

error[E0599]: typeof(foo) = futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>>

no method named `into_stream` found for type `typeof(foo)` in the current scope
   --> src/main.rs:220:19
    |
220 |     let foo = foo.into_stream();
    |                   ^^^^^^^^^^^ method not found in `typeof(foo)`
    |
    = note: the method `into_stream` exists but the following trait bounds were not satisfied:
            `&typeof(foo) : futures_util::future::future::FutureExt`
            `&typeof(foo) : futures_util::stream::try_stream::TryStreamExt`
            `&mut typeof(foo) : futures_util::future::future::FutureExt`
            `&mut typeof(foo) : futures_util::stream::try_stream::TryStreamExt`
            `typeof(foo) : futures_util::future::future::FutureExt`
            `typeof(foo) : futures_util::stream::try_stream::TryStreamExt`

which is much nicer to read.
It would be great if rust would report errors like this and would make it much easier to read error messages in the console.

Meta

rustc --version --verbose:

rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-unknown-linux-gnu
release: 1.42.0
LLVM version: 9.0
@manuels manuels added the C-bug Category: This is a bug. label Apr 11, 2020
@jonas-schievink
Copy link
Contributor

Duplicate of #50310

@jonas-schievink jonas-schievink marked this as a duplicate of #50310 Apr 11, 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

2 participants