Closed jocutajar closed 1 year ago
Happens for collect, try_collect etc etc as well of course.
Happened for me in case of map.
I encountered a similar problem when I forgot to import std::io::Read
:
// use std::io::Read;
fn make_reader() -> Box<dyn std::io::Read + 'static> {
let s = "hello world";
Box::new(s.as_bytes())
}
fn main() {
let mut buf = Vec::new();
make_reader().take(100).read_to_end(&mut buf).unwrap();
println!("{:?}", buf);
}
which returns error: the `take` method cannot be invoked on a trait object
and a confusing message about Sized requirement
Current output for Read
:
error: the `take` method cannot be invoked on a trait object
--> src/main.rs:11:19
|
11 | make_reader().take(100).read_to_end(&mut buf).unwrap();
| ^^^^
--> /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/io/mod.rs:1032:15
|
= note: this has a `Sized` requirement
|
help: another candidate was found in the following trait, perhaps add a `use` for it:
|
3 + use std::io::Read;
|
Current output for the original report (not sure if it is still equivalent due to the dependencies maybe drifting since):
error[E0277]: the size for values of type `dyn Stream<Item = Result<(), ()>>` cannot be known at compilation time
--> src/lib.rs:13:11
|
13 | input.forward(output)
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Stream<Item = Result<(), ()>>`
note: required by a bound in `futures::StreamExt::forward`
--> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/mod.rs:1555:27
|
1552 | fn forward<S>(self, sink: S) -> Forward<Self, S>
| ------- required by a bound in this associated function
...
1555 | Self: TryStream + Sized,
| ^^^^^ required by this bound in `StreamExt::forward`
error[E0277]: `dyn futures::Sink<(), Error = ()>` cannot be unpinned
--> src/lib.rs:13:19
|
13 | input.forward(output)
| ------- ^^^^^^ the trait `Unpin` is not implemented for `dyn futures::Sink<(), Error = ()>`
| |
| required by a bound introduced by this call
|
= note: consider using the `pin!` macro
consider using `Box::pin` if you need to access the pinned value outside of the current scope
= help: the trait `futures::Sink<Item>` is implemented for `Box<S>`
= note: required for `Box<dyn futures::Sink<(), Error = ()>>` to implement `futures::Sink<()>`
note: required by a bound in `futures::StreamExt::forward`
--> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/mod.rs:1554:12
|
1552 | fn forward<S>(self, sink: S) -> Forward<Self, S>
| ------- required by a bound in this associated function
1553 | where
1554 | S: Sink<Self::Ok, Error = Self::Error>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StreamExt::forward`
error[E0308]: mismatched types
--> src/lib.rs:13:5
|
12 | ) -> Box<dyn Future<Output = Result<(), ()>>> {
| ---------------------------------------- expected `Box<(dyn futures::Future<Output = Result<(), ()>> + 'static)>` because of return type
13 | input.forward(output)
| ^^^^^^^^^^^^^^^^^^^^^ expected `Box<dyn Future<Output = ...>>`, found `Forward<dyn Stream<Item = ...>, ...>`
|
= note: expected struct `Box<(dyn futures::Future<Output = Result<(), ()>> + 'static)>`
found struct `Forward<dyn Stream<Item = Result<(), ()>>, Box<dyn futures::Sink<(), Error = ()>>>`
Why is it a problem: I'm so used to helpful compiler advice that I'm almost upset with this misleading statement :)
Actual: Calling StreamExt::forward fails unless I add Unpin trait, but the error suggests that it is not possible to call the method on the trait object because it has to be Sized, no mention of Unpin and on top of it it suggests adding a
use
clause that is already present.Expected: An advice about missing Unpin trait.
Reproduce: see example:
Error: