-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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) -> TThis 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) -> TSince 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
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.