Infering default generic arguments through traits #50107
Labels
A-inference
Area: Type inference
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
I've recently come across an issue of type inference that can be summed up like this:
returns
(playground)
I would have thought rustc could be able to infer the type for
T3
asFoo<u8, u16>
, through this procedure:Many<'a, 'b, 't1, 't2, 't3>
with't1 = Foo<u8, 'b1>
and't2 = Foo<'a2, u16>
where
clause says't1: Trait<'a, 'b>
, and we only have't1: Trait<u8, 'b1>
, so we can unify and get'a = u8
and'b = 'b1
where
clause also says't2: Trait<'a, 'b>
, and we only have't2: Trait<'a2, u16>
, so we can unify and get'a = 'a2
and'b = u16
Many<u8, u16, Foo<u8, u16>, Foo<u8, u16>, 't3>
't3
gives't3 = Foo<u8, u16>
, which is what I'm hoping forIn the meantime, would you happen to know of a way to do what I'm trying to do? Ideally it'd be a variadic enum, but not being able to figure out a way to do it I just decided to have a cap on the number of variants, and hit this bug. If this could not be a solution based on auto-generating a rust file for all possible numbers of variants it'd be even better, but…
The text was updated successfully, but these errors were encountered: