Equivalent types have different behavior with old trait solver
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimized example in the issue on the specified Rust nightly or Playground, comparing the works and fails functions. Start by tracing the trait-system handling of the Refl<T> alias and associated-type bounds; done means the equivalent forms behave consistently without the reported erroneous T: Trait requirement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100