Problem with type inference and impl Trait #73239
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-impl-trait
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
A-lazy-normalization
Area: Lazy normalization (tracking issue: #60471)
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
Hi!
I recently experienced a bug in that probably comes from problems of the interference of type inference, impl Trait in return type position, and associated types.
This is a very strongly simplified version of what was going on in my codebase. In fact my codebase included
Arc
instead ofSmartPointer
andAsRef
instead ofMyAsRef
, but I wanted to simplify to reproduce the problem withoutstd
.I expected to see this happen:
The compiler should be able to infer that
<TypeSetImpl as TypeSet>::Type0
=Type0Impl
and compile the program.Instead, this happened:
The compiler failed with this error message:
As noted in the comments in the code snipped changing the one line using impl Trait in return type position enables the compiler to build the program.
I'm not entirely sure if this is a bug or if I expecting type inference to be stronger as it is or if the code I wrote is indeed not correct, so sorry if that is the case.
Meta
rustc --version --verbose
:None
The text was updated successfully, but these errors were encountered: