Fn vs FnOnce in spec code
#270
Replies: 3 comments
-
|
Interesting. From discussions about executable closures with @tjhance , it's likely we'd want to use a new type, |
Beta Was this translation helpful? Give feedback.
-
|
I agree it ought to be sound to declare the parameter to This might be relevant: a few days ago, Chris and I were discussing exec-mode function arguments and discussed the possibility of adding To summarize that conversation:
As such, we came up with a possible solution:
I think this plan would also solve the problem you bring here due to the last bullet point. |
Beta Was this translation helpful? Give feedback.
-
|
A variation of this (where |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We currently only support
Fnfunction bounds (notFnOnceorFnMut).However in this situation:
while
foo_1typechecks,foo_2doesn't: "expected a closure that implements theFntrait, but this closure only implementsFnOnce". The error message explains thatkkandvvareFnOncebecausem1is moved into them. However,Map::newexpectsFnfunctions.foo_1wouldn't borrow-check in regular rust either, but we don't borrow-check spec functions. This behavior appears to be an asymmetry in how the function traits for closures are determined and how that influences the borrow-checking constraints.In fact, one can force the closures in the
lets to beFnby ascription:This again typechecks (but we currently fail because we don't support
dyn).This behavior is surprising and there may be different ways to address it.
We could change the trait bounds on
Map::newto beFnOnce, which I believe would be sound (asMap::newis spec).Initially found by @matthias-brun.
Beta Was this translation helpful? Give feedback.
All reactions