-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference fails to determine closure argument type #12679
Comments
What happens of you write the definition of |
If writing inline at the point of use, it works: xs.find_or_insert_with((3,3), |_| 30); |
This API is gone now, and I am bad with the new Entry API. @gankro ? |
Seems to basically do the same thing. |
Another related testcase: #![feature(std_misc)]
use std::collections::HashMap;
use std::collections::hash_map::VacantEntry;
pub fn main() {
let mut xs = HashMap::<(u32, u32), u32>::new();
let new_el = |v:VacantEntry<(u32, u32),u32>| v.insert(30);
xs.insert((1,1), 10);
xs.insert((2,2), 20);
xs.entry((3,3)).get().unwrap_or_else(new_el);
println!("{:?}", xs);
} gives |
Have another related/simplified test case:
fails to resolve, while the following works:
|
Triage: this issue is kind of a general one, with lots of cases. I'm not sure how much of this is intended to get resolved, and how much of this is scatted across other issues on the tracker. |
#27828 has another instance of this. |
Edit: current output:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It's the last day of 2021, and I still met a similar problem. The following code snippet works: fn set_callback<F>(_: F)
where
F: FnOnce(&mut [u8])
{ }
fn foo() {
set_callback(|_| ());
} But the following does not: fn set_callback<F>(_: Option<F>)
where
F: FnOnce(&mut [u8])
{ }
fn foo() {
set_callback(Some(|_| ()));
} |
fix: typos in hir-ty
Current output for the last example:
|
The following fails to compile:
The argument type must be explicitly spelled out:
Should the type inference work here?
The text was updated successfully, but these errors were encountered: