Skip to content

Unification fails when type alias impl trait is used in non-return position #64445

Description

@jonhoo

The following code fails to compile, but I believe this should be a supported use-case under rust-lang/rfcs#2515 (and #63063):

#![feature(type_alias_impl_trait)]
type X = impl Iterator<Item = u64> + Unpin;

struct Foo(X);
impl Foo {
    fn new(z: Vec<u64>) -> Self {
        Foo(z.into_iter())
    }
}

with

error[E0308]: mismatched types
  --> src/lib.rs:12:13
   |
12 |         Foo(z.into_iter())
   |             ^^^^^^^^^^^^^ expected opaque type, found struct `std::vec::IntoIter`
   |
   = note: expected type `X`
              found type `std::vec::IntoIter<u64>`

This code on the other hand works just fine with the above X:

fn foo(z: Vec<u64>) -> X {
    z.into_iter()
}

Including both Foo and foo in the same file still produces the same error, so foo does not "help" identify X.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceA-type-systemArea: Type systemC-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions