mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +00:00
Add tests for once functions (#2549).
This commit is contained in:
parent
1496216db6
commit
c1f037e6ac
29
src/test/compile-fail/once-cant-call-twice-on-heap.rs
Normal file
29
src/test/compile-fail/once-cant-call-twice-on-heap.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
// This program would segfault if it were legal.
|
||||||
|
|
||||||
|
extern mod extra;
|
||||||
|
use extra::arc;
|
||||||
|
use std::util;
|
||||||
|
|
||||||
|
fn foo(blk: ~once fn()) {
|
||||||
|
blk();
|
||||||
|
blk(); //~ ERROR use of moved value
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = arc::ARC(true);
|
||||||
|
do foo {
|
||||||
|
assert!(*x.get());
|
||||||
|
util::ignore(x);
|
||||||
|
}
|
||||||
|
}
|
29
src/test/compile-fail/once-cant-call-twice-on-stack.rs
Normal file
29
src/test/compile-fail/once-cant-call-twice-on-stack.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
// This program would segfault if it were legal.
|
||||||
|
|
||||||
|
extern mod extra;
|
||||||
|
use extra::arc;
|
||||||
|
use std::util;
|
||||||
|
|
||||||
|
fn foo(blk: &once fn()) {
|
||||||
|
blk();
|
||||||
|
blk(); //~ ERROR use of moved value
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = arc::ARC(true);
|
||||||
|
do foo {
|
||||||
|
assert!(*x.get());
|
||||||
|
util::ignore(x);
|
||||||
|
}
|
||||||
|
}
|
20
src/test/compile-fail/once-cant-copy-stack-once-fn-copy.rs
Normal file
20
src/test/compile-fail/once-cant-copy-stack-once-fn-copy.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Though it should be legal to copy a heap-allocated "once fn:Copy",
|
||||||
|
// stack closures are not deep-copied, so (counterintuitively) it should be
|
||||||
|
// illegal to copy them.
|
||||||
|
|
||||||
|
fn foo<'r>(blk: &'r once fn:Copy()) -> (&'r once fn:Copy(), &'r once fn:Copy()) {
|
||||||
|
(copy blk, blk) //~ ERROR copying a value of non-copyable type
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
// This program would segfault if it were legal.
|
||||||
|
|
||||||
|
extern mod extra;
|
||||||
|
use extra::arc;
|
||||||
|
use std::util;
|
||||||
|
|
||||||
|
fn foo(blk: ~fn()) {
|
||||||
|
blk();
|
||||||
|
blk();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = arc::ARC(true);
|
||||||
|
do foo {
|
||||||
|
assert!(*x.get());
|
||||||
|
util::ignore(x); //~ ERROR cannot move out of captured outer variable
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
// This program would segfault if it were legal.
|
||||||
|
|
||||||
|
extern mod extra;
|
||||||
|
use extra::arc;
|
||||||
|
use std::util;
|
||||||
|
|
||||||
|
fn foo(blk: &fn()) {
|
||||||
|
blk();
|
||||||
|
blk();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = arc::ARC(true);
|
||||||
|
do foo {
|
||||||
|
assert!(*x.get());
|
||||||
|
util::ignore(x); //~ ERROR cannot move out of captured outer variable
|
||||||
|
}
|
||||||
|
}
|
27
src/test/run-pass/once-move-out-on-heap.rs
Normal file
27
src/test/run-pass/once-move-out-on-heap.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
|
||||||
|
extern mod extra;
|
||||||
|
use extra::arc;
|
||||||
|
use std::util;
|
||||||
|
|
||||||
|
fn foo(blk: ~once fn()) {
|
||||||
|
blk();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = arc::ARC(true);
|
||||||
|
do foo {
|
||||||
|
assert!(*x.get());
|
||||||
|
util::ignore(x);
|
||||||
|
}
|
||||||
|
}
|
27
src/test/run-pass/once-move-out-on-stack.rs
Normal file
27
src/test/run-pass/once-move-out-on-stack.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Testing guarantees provided by once functions.
|
||||||
|
|
||||||
|
extern mod extra;
|
||||||
|
use extra::arc;
|
||||||
|
use std::util;
|
||||||
|
|
||||||
|
fn foo(blk: &once fn()) {
|
||||||
|
blk();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = arc::ARC(true);
|
||||||
|
do foo {
|
||||||
|
assert!(*x.get());
|
||||||
|
util::ignore(x);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user