rust/tests/ui/once-cant-call-twice-on-heap.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
309 B
Rust
Raw Normal View History

2013-06-17 23:25:06 +00:00
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
use std::sync::Arc;
2013-06-17 23:25:06 +00:00
fn foo<F:FnOnce()>(blk: F) {
2013-06-17 23:25:06 +00:00
blk();
blk(); //~ ERROR use of moved value
}
fn main() {
let x = Arc::new(true);
foo(move|| {
assert!(*x);
drop(x);
2014-01-27 23:29:50 +00:00
});
2013-06-17 23:25:06 +00:00
}