-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Description
This code crashes today
// 'x' can have any mode but & or &&
fn foo(-x: ~int) { }
fn main() {
let b = bind foo(~3);
b();
b();
}
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 to let x = ~3 in fn () -> foo(x)
(in some weird O'Caml/Rust hybrid) but it would need to be fn() -> 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:
let b = {
let v1 = E1;
...
let vN = En;
lambda() { f(v1, ..., vN) }
}
Similarly, upvars in lambdas should have reference mode (referencing the environment, not creator stack frame) which would prevent moves.
Activity
marijnh commentedon Dec 7, 2011
I think disallowing binding of by-move or by-copy arguments is the sanest solution to this.
marijnh commentedon Dec 7, 2011
@nikomatsakis Feel free to reopen if you feel this solution is unsatisfactory.
nikomatsakis commentedon Dec 7, 2011
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.
Fix _mm_extract_ps example. (rust-lang#1261)
Bump CBMC viewer version to 3.5 (rust-lang#1261)
Fix an invalid link on Diagnostic Items (rust-lang#1261)
Fix an invalid link on Diagnostic Items (rust-lang#1261)