Rust can't figure out that two types are the same with supertraits and associated types. #135979
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
F-associated_type_bounds
`#![feature(associated_type_bounds)]`
T-types
Relevant to the types team, which will review and decide on the PR/issue.
I tried this code:
I expected the code to compile. However, the
works
function compiles, while thefails
function fails to compile, producing the error:For every SubFoo type, the ToBar and SubToBar associated types will always be the same (
Self::ToBar == Self::SubToBar
). This can be proven from by the following chain of reasoning for any typeF: SubFoo
:It seems like the trait solver can't figure this out by itself. But prodding it with the
helper()
function makes it able to figure this out. This workaround is rather inconvenient though, and it would be nice if the trait solver can figure this out itself, or if there were some way to give hints to the trait solver to reach this conclusion.Note: my attempts to simplify things have repeatedly ran into the problem described at #65913. Also, the original use case had GATs, which made associated type bounds not usable on the Foo/SubFoo traits.
Meta
Reproducible on the playground with stable rust version 1.84.0, and nightly rust version
1.86.0-nightly (2025-01-23 99768c80a1c094a5cfc3)
Using
-Z next-solver=globally
doesn't fix the problem.@rustbot labels +A-trait-system +A-associated-items
The text was updated successfully, but these errors were encountered: