Inference worse in method signature using associated type than with new generic type parameter eq-constrained to the associated type #45462
Open
Description
With this signature
fn try_fold<F, T: Try>(self, init: T::Ok, mut f: F) -> T where
Self: Sized, F: FnMut(T::Ok, Self::Item) -> T
This code
let a = [1, 2, 3];
let sum = a.iter().try_fold(0i8, |acc, &x| acc.checked_add(x));
Gets error[E0619]: the type of this value must be known in this context
.
But it works fine with the seemingly-equivalent signature
fn try_fold<F, U, T: Try<Ok=U>>(self, init: U, mut f: F) -> T where
Self: Sized, F: FnMut(U, Self::Item) -> T
Since acc
and init
must have the same type in both cases, shouldn't both signatures work?
Full repro: https://play.rust-lang.org/?gist=f8d2baeae64b17344e1cf27673a2e905&version=nightly