Description
I tried this code:
trait Add<Rhs> {
type Sum;
}
impl Add<()> for () {
type Sum = ();
}
type Unit = <() as Add<()>>::Sum;
trait Trait<C> {
type Output;
}
fn f<T>()
where
T: Trait<()>,
<T as Trait<()>>::Output: Sized,
{}
fn g<T>()
where
T: Trait<Unit>,
<T as Trait<()>>::Output: Sized,
{}
fn h<T>()
where
T: Trait<()>,
<T as Trait<Unit>>::Output: Sized,
{}
Function g
is f
with ()
replaced with Unit
in first where clause, while function h
is f
with ()
replaced with Unit
in second where clause. Since Unit
is effectively a type alias for ()
, I expected all three functions to compile.
Instead, the compiler complains about g
:
error[E0277]: the trait bound `T: Trait<()>` is not satisfied
--> src/lib.rs:25:1
|
25 | / fn g<T>()
26 | | where
27 | | T: Trait<Unit>,
28 | | <T as Trait<()>>::Output: Sized,
| |____________________________________^ the trait `Trait<()>` is not implemented for `T`
|
help: consider further restricting this bound
|
27 | T: Trait<Unit> + Trait<()>,
| +++++++++++
error[E0277]: the trait bound `T: Trait<()>` is not satisfied
--> src/lib.rs:25:4
|
25 | fn g<T>()
| ^ the trait `Trait<()>` is not implemented for `T`
|
help: consider further restricting this bound
|
27 | T: Trait<Unit> + Trait<()>,
| +++++++++++
The compiler suggests adding Trait<()>
on T
, which should not be necessary since Trait<Unit>
has exactly the same meaning as Trait<()>
(and it actually works that way for h
). Having Unit
type alias is not essential, inlining it yields the same error.
(Also it complains about the same unsatisfied bound twice, but it is less of an issue, I guess)
Meta
I used the latest stable at the moment, 1.67.1, but it can also be reproduced on the latest beta (2023-03-06 b955c8271da80a1af8a1
) and latest nigthly (2023-03-06 b955c8271da80a1af8a1
) at the moment.
Probably related to #43049.
@rustbot label: +A-associated-items