Incorrect trait bound resolution in the presence of associated types #78220
Labels
A-associated-items
Area: Associated items such as associated types and consts.
A-traits
Area: Trait system
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The following code:
produces the following error:
In theory, this should compile fine.
ConcreteBar::BarType
is()
, so the trait boundA: Foo<<ConcreteBar as Bar>::BarType>
should be equivalent toA: Foo<()>
.Changing the first bound to
A: Foo<()>
eliminates the error. Additionally, adding a third type parameterB
and changing the bounds to the following:eliminates the error. However, see the additional context below.
Meta
This has been tested on the current stable and nightly compilers:
Additional context
I encountered this issue while working with generic traits from typenum, generic-array, and nalgebra, and in this context the above-mentioned workarounds do not work. Unfortunately I have yet to find an example of this more persistent version of the issue that does not use types and traits from these crates.
Several code and error examples
(Plus a couple of duplicate errors pointing to different spans.)
Bounding on
Mul<typenum::U1>
directly:Using the compiler-suggested bound actually leads to it suggesting the exact same bound again:
The text was updated successfully, but these errors were encountered: