I know the depiction of differences between generics and impl Trait
in return position, but still don't get it here.
fn main() {
a(0..10).map(|d| dbg!(d)).last();
}
// pass
fn a<T: Iterator<Item = u8>>(t: T) -> impl Iterator<Item = u8> {
t.map(|x| x + 1)
}
// failed: mismatched types
fn b<T: Iterator<Item = u8>, U: Iterator<Item = u8>>(t: T) -> U {
t.map(|x| x + 1)
}
// failed: mismatched types
fn c<T, U>(t: T) -> U
where
T: Iterator<Item = u8>,
U: Iterator<Item = u8>,
{
t.map(|x| x + 1)
}
error[E0308]: mismatched types
--> src/main.rs:12:5
|
11 | fn b<T: Iterator<Item = u8>, U: Iterator<Item = u8>>(t: T) -> U {
| - this type parameter - expected `U` because of return type
12 | t.map(|x| x + 1)
| ^^^^^^^^^^^^^^^^ expected type parameter `U`, found struct `Map`
|
= note: expected type parameter `U`
found struct `Map<T, [closure@src/main.rs:12:11: 12:20]>`
error[E0308]: mismatched types
--> src/main.rs:21:5
|
16 | fn c<T, U>(t: T) -> U
| - - expected `U` because of return type
| |
| this type parameter
...
21 | t.map(|x| x + 1)
| ^^^^^^^^^^^^^^^^ expected type parameter `U`, found struct `Map`
|
= note: expected type parameter `U`
found struct `Map<T, [closure@src/main.rs:21:11: 21:20]>`
For more information about this error, try `rustc --explain E0308`.