-
Notifications
You must be signed in to change notification settings - Fork 13.4k
bind allows data to be moved multiple times #1261
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
Comments
I think disallowing binding of by-move or by-copy arguments is the sanest solution to this. |
@nikomatsakis Feel free to reopen if you feel this solution is unsatisfactory. |
Yes, that's fine, as long as lambdas also prevent moving out of upvars (and I just tested and found that they do). That is what I meant, not sure why I phrased it in such a complicated way. I guess I wanted to know if there were other corner cases I was not thinking of. |
This code crashes today
The error is that bind needs to "re-copy" the ~3 each time
b()
is invoked, but it doesn't. In other words, that bind code is equivalent tolet x = ~3 in fn () -> foo(x)
(in some weird O'Caml/Rust hybrid) but it would need to befn() -> let x = ~3 in foo(x)
to be safe.Not sure the best fix here. One thought is to ensure that bind
let b = bind f(E1, ..., En)
is syntactic sugar for something like:Similarly, upvars in lambdas should have reference mode (referencing the environment, not creator stack frame) which would prevent moves.
The text was updated successfully, but these errors were encountered: