-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Inference should be able to determine closure argument types from usage #35714
Comments
The closure is type-checked first and no type has seen by then. Closures outside of call argument position are poorly supported and should be avoided where possible. |
Similar: #[derive(Debug)]
struct Foo<T>(T);
fn main() {
let f = Foo(42);
let cls = |foo| {
// println!("{:?}", foo); // Works
foo.0; // Does not work
};
cls(f);
} What's strange about this to me is that the type of |
@eddyb do you know if this is an inherent limitation, or is it just a "we haven't gotten around to fixing this yet" situation? |
It's not something you "fix", it's something you rewrite your whole type-checker for, from scratch, sadly. The explanation for your example is that |
Ah, so just a few hours of low-impact work, gotcha! 😸 Thank you for the detailed explanation of my case. |
I'm going to close this issue -- this is a known limitation of the current type-checker, but not one that we plan to imminently change, and I don't think having this issue open will help us track it in particular. Feel free to let me know if you disagree. |
@nikomatsakis sounds good. Is there another place where these "bigger picture" issues are tracked? Maybe some kind of document of known limitations? I'd like to have a place to point people who stumble across the same problem. Keeping it in our heads is useful to us, but not others 😉 |
I'm not aware of any such place. I'm not really sure what would be the best such place either... :/ |
(playpen)
gives:
The typechecker should be able to figure out that the type is
Bar
, since that's what the closure is used with.@nagisa mentioned that it might be that the closure is polymorphic over the argument, but that's not the case -- trying to feed it two types doesn't work (example) and it's clear that the closure type gets decided when it is fed a
Bar
.The text was updated successfully, but these errors were encountered: