Closed
Description
I tried this code:
#![feature(return_position_impl_trait_in_trait)]
trait Foo<T> {
fn foo<F2: Foo<T>>(self) -> impl Foo<T>;
}
struct Bar;
impl Foo<u8> for Bar {
fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
self
}
}
fn main() {}
I expected this to compile without error, since it is implementing the trait correctly.
Instead, the following error was shown:
error[E0053]: method `foo` has an incompatible type for trait
--> src/main.rs:10:42
|
10 | fn foo<F2: Foo<u8>>(self, f2: F2) -> impl Foo<u8> {
| -- ^^^^^^^^^^^^
| | |
| | expected `u8`, found type parameter `F2`
| this type parameter help: change the output type to match the trait: `impl Foo<u8>`
|
note: type in trait
--> src/main.rs:4:41
|
4 | fn foo<F2: Foo<T>>(self, f2: F2) -> impl Foo<T>;
| ^^^^^^^^^^^
= note: expected fn pointer `fn(Bar, _) -> impl Foo<u8>`
found fn pointer `fn(Bar, _) -> impl Foo<u8>`
It suggests replacing the code with the code I already have, which doesn't make much sense, as well as complaining that two things which appear identical are not.
Meta
rustc --version --verbose
:
rustc 1.66.0-nightly (3f83906b3 2022-09-24)
binary: rustc
commit-hash: 3f83906b30798bf61513fa340524cebf6676f9db
commit-date: 2022-09-24
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0