rust/src/test/run-pass/capture_nil.rs
Niko Matsakis 14303bad89 Do not copy values of type () or _|_
This can trigger a crash because we assume we
can supply null ptrs and undefined values for
values of those types, as we should be treated
them as zero-size.

Interestingly, this crash only shows up (atm)
in non-optimized builds.  Therefore, I added
a -Z no-opt flag so that the new test
(capture_nil) can specify that it should not
run with optimizations enabled.
2012-09-07 13:00:03 -07:00

30 lines
720 B
Rust

// compile-flags:-Z no-opt
use comm::*;
// This test has to be setup just so to trigger
// the condition which was causing us a crash.
// The situation is that we are capturing a
// () value by ref. We generally feel free,
// however, to substitute NULL pointers and
// undefined values for values of () type, and
// so this caused a segfault when we copied into
// the closure.
//
// The fix is just to not emit any actual loads
// or stores for copies of () type (which is of
// course preferable, as the value itself is
// irrelevant).
fn foo(&&x: ()) -> Port<()> {
let p = Port();
let c = Chan(p);
do task::spawn() |copy c, copy x| {
c.send(x);
}
p
}
fn main() {
foo(()).recv()
}