Skip to content

TAIT: concrete types may differ by normalization #112691

Open
@aliemjay

Description

@aliemjay

The following should compile:

#![feature(type_alias_impl_trait)]

trait Trait {
    type Gat<'lt>;
}

impl Trait for u8 {
    type Gat<'lt> = ();
}

fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) {
    loop {}
}

type Opaque = impl Sized;

fn define() -> Opaque {
    dyn_hoops::<_>(0)
    //~^ ERROR concrete type differs from previous defining opaque type use
    // expected `*const (dyn FnOnce(()) + 'static)`,
    // got      `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
}

There are multiple places where we compare concrete types for equality. A regression test for this issue should cover them all:

#![feature(type_alias_impl_trait)]

trait Trait {
    type Gat<'lt>;
}

impl Trait for u8 {
    type Gat<'lt> = ();
}

fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) {
    loop {}
}

mod typeof_1 {
    use super::*;
    type Opaque = impl Sized;
    fn define() -> Opaque {
        dyn_hoops::<_>(0)
    }
}

mod typeof_2 {
    use super::*;
    type Opaque = impl Sized;
    fn define_1() -> Opaque { dyn_hoops::<_>(0) }
    fn define_2() -> Opaque { dyn_hoops::<u8>(0) }
}

mod typeck {
    use super::*;
    type Opaque = impl Sized;
    fn define() -> Option<Opaque> {
        let _: Opaque = dyn_hoops::<_>(0);
        let _: Opaque = dyn_hoops::<u8>(0);
        None
    }
}

mod borrowck {
    use super::*;
    type Opaque = impl Sized;
    fn define() -> Option<Opaque> {
        let _: Opaque = dyn_hoops::<_>(0);
        None
    }
}

fn main() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions