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

Trait aliases considers same type as not equal to itself if used in impl Trait return type #57612

Closed
matprec opened this issue Jan 14, 2019 · 2 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system A-type-system Area: Type system F-trait_alias `#![feature(trait_alias)]`

Comments

@matprec
Copy link
Contributor

matprec commented Jan 14, 2019

Example:

#![feature(trait_alias)]
#![feature(existential_type)]

trait Foo {
    type Bar: Baz<Self, Self>;

    fn bar(&self) -> Self::Bar;
}

struct X;

impl Foo for X {
    existential type Bar: Baz<Self, Self>;

    fn bar(&self) -> Self::Bar {
        |x: &X| x
    }
}

trait Baz<A, B> = Fn(&A) -> &B;

Workaround: Replace existential type Bar: Baz<Self, Self>; with existential type Bar: Fn(&X) -> &X;
Possibly related to #57611
Playground

@Centril Centril added A-type-system Area: Type system A-trait-system Area: Trait system labels Jan 15, 2019
@oli-obk oli-obk self-assigned this Jan 25, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Mar 18, 2019

Reduced example

#![feature(trait_alias)]

struct X;

fn bar() -> impl Baz<X, X> {
    |x: &X| x
}

trait Baz<A, B> = Fn(&A) -> &B;

@oli-obk oli-obk removed their assignment Mar 18, 2019
@oli-obk oli-obk added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` F-trait_alias `#![feature(trait_alias)]` and removed F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Feb 18, 2021
@oli-obk oli-obk changed the title Trait aliases in existential types considers same type as more general Trait aliases considers same type as not equal to itself if used in impl Trait return type Feb 18, 2021
@oli-obk oli-obk added the A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. label Feb 18, 2021
@plazmoid
Copy link

Not a bug anymore, Oli's example compiles now (with fixing some lifetime issues):

#![feature(trait_alias)]
#![feature(closure_lifetime_binder)]

struct X;

fn bar() -> impl Baz<X, X> {
    for<'a> |x: &'a X| -> &'a X { x }
}

trait Baz<A, B> = Fn(&A) -> &B;

Interestingly that moving HRTB into trait alias doesn't solve the lifetimes issue

@oli-obk oli-obk closed this as completed Aug 31, 2022
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system A-type-system Area: Type system F-trait_alias `#![feature(trait_alias)]`
Projects
None yet
Development

No branches or pull requests

5 participants