Skip to content

RPITIT seems to assume return type is the type parameter when it looks the same #102301

Closed
@Artemis21

Description

@Artemis21

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.

Playground.

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

Metadata

Metadata

Labels

C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.F-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions