-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 error: the type of this value must be known in this context #23012
Comments
What's causing this is that we currently inspect the obligations in scope for |
I imagine that atm this could be worked around by changing: fn receive<F: Receive<T, E>>(self, f: F) to fn receive<F: Receive<T, E>+FnOnce(Result<T,E>)>(self, f: F) |
Today, this gives a completely different error about |
Updated code to not give the unrelated pub trait Receive<T, E>: FnOnce(Result<T, E>) {
fn receive(self, res: Result<T, E>);
}
impl<T, E, F: FnOnce(Result<T, E>)> Receive<T, E> for F {
fn receive(self, res: Result<T, E>) {
self(res)
}
}
pub trait Async<T, E> {
fn receive<F: Receive<T, E>>(self, f: F);
}
impl<T, E> Async<T, E> for Result<T, E> {
fn receive<F: Receive<T, E>>(self, f: F) {
f(self)
}
}
pub fn main() {
Ok::<u32, ()>(123).receive(|res| res.unwrap())
} |
This comes up for me fairly regularly. It would be really nice to fix it. (e.g., it came up recently in rayon-rs/rayon#318) |
We discussed this in the types team 'backlog bonanza' meeting today. Our conclusion was that this is a "nice to have" and that directly fixing this issue felt like a types team FCP, because it's a tweak to the inference rules. TL;DR right now we say
...but it seems reasonable to say
...and that would fix this example (types team FCP would be required). However, I believe that beyond this specific example, most people who wind up here are trying to do something a bit more sophisticated, such as having an argument that might be a closure but might not, or have extended varieties of closures (as described in this rayon change). It is possible that just making the above change would fix those problems, but it's likely that further changes would be required. Those scope feels like a lang-team initiative. Still may be worth making this change just to screen out the easy cases, mind you! |
Repro:
Output:
The text was updated successfully, but these errors were encountered: