Skip to content

Equivalent types have different behavior with old trait solver #145286

@theemathas

Description

@theemathas

I tried this code:

pub trait Mirror {
    type Output;
}
impl<T> Mirror for T {
    type Output = T;
}

// Refl<X> = X
pub type Refl<X> = <X as Mirror>::Output;

pub trait Trait {
    type Assoc;
}

fn works<T>()
where
    T: Trait,
    <Refl<T> as Trait>::Assoc: Sized,
{
}

fn fails<T>()
where
    Refl<T>: Trait,
    <Refl<T> as Trait>::Assoc: Sized,
{
}

I expected both works and fails to compile. Instead, fails doesn't compile, producing the following error:

error[E0277]: the trait bound `T: Trait` is not satisfied
  --> src/lib.rs:22:1
   |
22 | / fn fails<T>()
23 | | where
24 | |     Refl<T>: Trait,
25 | |     <Refl<T> as Trait>::Assoc: Sized,
   | |_____________________________________^ the trait `Trait` is not implemented for `T`
   |
help: consider further restricting type parameter `T` with trait `Trait`
   |
25 |     <Refl<T> as Trait>::Assoc: Sized, T: Trait
   |                                       ++++++++

error[E0277]: the trait bound `T: Trait` is not satisfied
  --> src/lib.rs:25:32
   |
25 |     <Refl<T> as Trait>::Assoc: Sized,
   |                                ^^^^^ the trait `Trait` is not implemented for `T`
   |
help: consider further restricting type parameter `T` with trait `Trait`
   |
25 |     <Refl<T> as Trait>::Assoc: Sized, T: Trait
   |                                       ++++++++

For more information about this error, try `rustc --explain E0277`.

Minimized from code written by backslash_phi on the rust community discord

@rustbot labels +A-trait-system +T-types

Meta

Reproducible on the playground with version 1.91.0-nightly (2025-08-10 c8ca44c98eade864824a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.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