Closed
Description
Code
fn i_can_has_iterator() -> impl Iterator<Item = u32> {
Box::new(1..=10) as Box<dyn Iterator>
}
Current output
Compiling iterconfusion v0.1.0 (/irrelevant/iterconfusion)
error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
--> src/lib.rs:2:33
|
2 | Box::new(1..=10) as Box<dyn Iterator>
| ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
error[E0271]: expected `Box<dyn Iterator>` to be an iterator that yields `u32`, but it yields `<dyn Iterator as Iterator>::Item`
--> src/lib.rs:1:28
|
1 | fn i_can_has_iterator() -> impl Iterator<Item = u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `u32`
2 | Box::new(1..=10) as Box<dyn Iterator>
| ------------------------------------- return type was inferred to be `Box<dyn Iterator>` here
|
= note: expected associated type `<dyn Iterator as Iterator>::Item`
found type `u32`
help: a method is available that returns `<dyn Iterator as Iterator>::Item`
--> /home/multisn8/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:3852:5
|
3852 | / unsafe fn __iterator_get_unchecked(&mut self, _idx: usize) -> Self::Item
3853 | | where
3854 | | Self: TrustedRandomAccessNoCoerce,
| |__________________________________________^ consider calling `__iterator_get_unchecked`
Some errors have detailed explanations: E0191, E0271.
For more information about an error, try `rustc --explain E0191`.
error: could not compile `iterconfusion` due to 2 previous errors
Desired output
error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
--> src/lib.rs:2:33
|
2 | Box::new(1..=10) as Box<dyn Iterator>
| ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
help: likely you want this to match the output type, `Iterator<Item = u32>`
--> src/lib.rs:2:40
|
2 | Box::new(1..=10) as Box<dyn Iterator<Item = u32>>
| ++++++++++++
Rationale and extra context
I don't think I as an outside user of stdlib should be confronted with using internal unsafe APIs such as __iterator_get_unchecked
.
Other cases
No response
Anything else?
rustc -V
: rustc 1.69.0-nightly (5b8f28453 2023-02-12)