Type inference for closure return types #1202
y1ca1
started this conversation in
Feature requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The problem
Consider the following simple closure:
The use of type hole
_
here is valid in both Rust and Verus. However, when we want to add spec to the closure, one has to explicitly annotate the return type likelet ok1 = |x: u8| -> (o: u8) ensures x == o { x }
. Otherwise, Verus complains.Verus outputs:
Why care
Type inference for closure return types is especially useful when it comes to nested closures. Consider the following valid Rust/Verus code:
The inferred closure type is
impl Fn(u8) -> impl Fn(u8) -> (u8, u8)
. Specifically, the type of the inner closure (or the return type of the outer closure) isimpl Fn(u8) -> (u8, u8)
, which is not allowed to be written explicitly in Rust for reasons I have yet to explore.So there is no way if we want to add some specs for a nested closure like:
Link to code
I am curious if it's inherently hard to support this feature/there's any workaround/pointers to code if I decide to make a PR? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions