-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant 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`.Fixed by the next-generation trait solver, `-Znext-solver`.
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)
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant 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`.Fixed by the next-generation trait solver, `-Znext-solver`.