rust/src/test/ui/once-cant-call-twice-on-hea...

19 lines
331 B
Rust
Raw Normal View History

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