-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)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-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.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
The following fails to compile:
pub fn main() {
let mut xs = HashMap::<(u32, u32), u32>::new();
let new_el = |&_| 30; // error: the type of this value must be known in this context
xs.insert((1,1), 10);
xs.insert((2,2), 20);
xs.find_or_insert_with((3,3), new_el);
println!("{}", xs);
}
The argument type must be explicitly spelled out:
let new_el = |_: &(u32, u32)| 30;
Should the type inference work here?
schneiderfelipe
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)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-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.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.