Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Artemis21 opened this issue Sep 26, 2022 · 2 comments · Fixed by #102334
Closed

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

Artemis21 opened this issue Sep 26, 2022 · 2 comments · Fixed by #102334
Assignees
Labels
C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Artemis21
Copy link

Artemis21 commented Sep 26, 2022

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
@Artemis21 Artemis21 added the C-bug Category: This is a bug. label Sep 26, 2022
@Rageking8
Copy link
Contributor

@rustbot label +T-compiler +requires-nightly +F-return_position_impl_trait_in_trait +D-invalid-suggestion

@rustbot rustbot added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 26, 2022
@compiler-errors
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants