提交 58bea31c 编写于 作者: E Eduard Burtescu

tests: remove uses of Gc.

上级 aa596935
......@@ -541,14 +541,6 @@ fn test_dead() {
assert!(y.upgrade().is_none());
}
#[test]
fn gc_inside() {
// see issue #11532
use std::gc::GC;
let a = Rc::new(RefCell::new(box(GC) 1i));
assert!(a.try_borrow_mut().is_some());
}
#[test]
fn weak_self_cyclic() {
struct Cycle {
......
......@@ -532,7 +532,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
mod tests {
use std::fmt::Show;
use std::prelude::*;
use std::gc::{GC, Gc};
use std::hash;
use test::Bencher;
use test;
......@@ -587,43 +586,6 @@ fn test_simple() {
assert_eq!(*d.get(3), 4);
}
#[test]
#[allow(deprecated)]
fn test_boxes() {
let a: Gc<int> = box(GC) 5;
let b: Gc<int> = box(GC) 72;
let c: Gc<int> = box(GC) 64;
let d: Gc<int> = box(GC) 175;
let mut deq = RingBuf::new();
assert_eq!(deq.len(), 0);
deq.push_front(a);
deq.push_front(b);
deq.push(c);
assert_eq!(deq.len(), 3);
deq.push(d);
assert_eq!(deq.len(), 4);
assert_eq!(deq.front(), Some(&b));
assert_eq!(deq.back(), Some(&d));
assert_eq!(deq.pop_front(), Some(b));
assert_eq!(deq.pop(), Some(d));
assert_eq!(deq.pop(), Some(c));
assert_eq!(deq.pop(), Some(a));
assert_eq!(deq.len(), 0);
deq.push(c);
assert_eq!(deq.len(), 1);
deq.push_front(b);
assert_eq!(deq.len(), 2);
deq.push(d);
assert_eq!(deq.len(), 3);
deq.push_front(a);
assert_eq!(deq.len(), 4);
assert_eq!(*deq.get(0), a);
assert_eq!(*deq.get(1), b);
assert_eq!(*deq.get(2), c);
assert_eq!(*deq.get(3), d);
}
#[cfg(test)]
fn test_parameterized<T:Clone + PartialEq + Show>(a: T, b: T, c: T, d: T) {
let mut deq = RingBuf::new();
......@@ -755,12 +717,6 @@ fn test_param_int() {
test_parameterized::<int>(5, 72, 64, 175);
}
#[test]
fn test_param_at_int() {
test_parameterized::<Gc<int>>(box(GC) 5, box(GC) 72,
box(GC) 64, box(GC) 175);
}
#[test]
fn test_param_taggy() {
test_parameterized::<Taggy>(One(1), Two(1, 2), Three(1, 2, 3), Two(17, 42));
......
......@@ -529,9 +529,8 @@ fn test_rposition() {
#[test]
#[should_fail]
fn test_rposition_fail() {
use std::gc::GC;
let v = [(box 0i, box(GC) 0i), (box 0i, box(GC) 0i),
(box 0i, box(GC) 0i), (box 0i, box(GC) 0i)];
let v = [(box 0i, box 0i), (box 0i, box 0i),
(box 0i, box 0i), (box 0i, box 0i)];
let mut i = 0i;
v.iter().rposition(|_elt| {
if i == 2 {
......
......@@ -572,7 +572,6 @@ fn test_repr() {
use std::io::stdio::println;
use std::char::is_alphabetic;
use std::mem::swap;
use std::gc::GC;
fn exact_test<T>(t: &T, e:&str) {
let mut m = io::MemWriter::new();
......@@ -587,7 +586,6 @@ fn exact_test<T>(t: &T, e:&str) {
exact_test(&1.234f64, "1.234f64");
exact_test(&("hello"), "\"hello\"");
exact_test(&(box(GC) 10i), "box(GC) 10");
exact_test(&(box 10i), "box 10");
exact_test(&(&10i), "&10");
let mut x = 10i;
......@@ -601,8 +599,6 @@ fn exact_test<T>(t: &T, e:&str) {
"&[\"hi\", \"there\"]");
exact_test(&(P{a:10, b:1.234}),
"repr::P{a: 10, b: 1.234f64}");
exact_test(&(box(GC) P{a:10, b:1.234}),
"box(GC) repr::P{a: 10, b: 1.234f64}");
exact_test(&(box P{a:10, b:1.234}),
"box repr::P{a: 10, b: 1.234f64}");
......
......@@ -411,7 +411,6 @@ mod tests {
extern crate test;
use std::prelude::*;
use std::gc::{Gc, GC};
use super::*;
use std::task;
......@@ -467,11 +466,11 @@ fn test_tls_crust_automorestack_memorial_bug() {
#[test]
fn test_tls_multiple_types() {
static str_key: Key<String> = &KeyValueKey;
static box_key: Key<Gc<()>> = &KeyValueKey;
static box_key: Key<Box<int>> = &KeyValueKey;
static int_key: Key<int> = &KeyValueKey;
task::spawn(proc() {
str_key.replace(Some("string data".to_string()));
box_key.replace(Some(box(GC) ()));
box_key.replace(Some(box 0));
int_key.replace(Some(42));
});
}
......@@ -479,13 +478,13 @@ fn test_tls_multiple_types() {
#[test]
fn test_tls_overwrite_multiple_types() {
static str_key: Key<String> = &KeyValueKey;
static box_key: Key<Gc<()>> = &KeyValueKey;
static box_key: Key<Box<int>> = &KeyValueKey;
static int_key: Key<int> = &KeyValueKey;
task::spawn(proc() {
str_key.replace(Some("string data".to_string()));
str_key.replace(Some("string data 2".to_string()));
box_key.replace(Some(box(GC) ()));
box_key.replace(Some(box(GC) ()));
box_key.replace(Some(box 0));
box_key.replace(Some(box 1));
int_key.replace(Some(42));
// This could cause a segfault if overwriting-destruction is done
// with the crazy polymorphic transmute rather than the provided
......@@ -498,13 +497,13 @@ fn test_tls_overwrite_multiple_types() {
#[should_fail]
fn test_tls_cleanup_on_failure() {
static str_key: Key<String> = &KeyValueKey;
static box_key: Key<Gc<()>> = &KeyValueKey;
static box_key: Key<Box<int>> = &KeyValueKey;
static int_key: Key<int> = &KeyValueKey;
str_key.replace(Some("parent data".to_string()));
box_key.replace(Some(box(GC) ()));
box_key.replace(Some(box 0));
task::spawn(proc() {
str_key.replace(Some("string data".to_string()));
box_key.replace(Some(box(GC) ()));
box_key.replace(Some(box 2));
int_key.replace(Some(42));
fail!();
});
......
......@@ -554,23 +554,14 @@ mod test {
use super::*;
use std::prelude::*;
use std::task;
use std::gc::{Gc, GC};
#[test]
fn local_heap() {
let a = box(GC) 5i;
let b = a;
assert!(*a == 5);
assert!(*b == 5);
}
#[test]
fn tls() {
local_data_key!(key: Gc<String>)
key.replace(Some(box(GC) "data".to_string()));
local_data_key!(key: String)
key.replace(Some("data".to_string()));
assert_eq!(key.get().unwrap().as_slice(), "data");
local_data_key!(key2: Gc<String>)
key2.replace(Some(box(GC) "data".to_string()));
local_data_key!(key2: String)
key2.replace(Some("data".to_string()));
assert_eq!(key2.get().unwrap().as_slice(), "data");
}
......@@ -605,23 +596,6 @@ fn comm_shared_chan() {
assert!(rx.recv() == 10);
}
#[test]
fn heap_cycles() {
use std::cell::RefCell;
struct List {
next: Option<Gc<RefCell<List>>>,
}
let a = box(GC) RefCell::new(List { next: None });
let b = box(GC) RefCell::new(List { next: Some(a) });
{
let mut a = a.borrow_mut();
a.next = Some(b);
}
}
#[test]
#[should_fail]
fn test_begin_unwind() {
......
......@@ -10,7 +10,6 @@
use std::cell::RefCell;
use std::gc::{Gc, GC};
pub struct Entry<A,B> {
key: A,
......@@ -19,7 +18,7 @@ pub struct Entry<A,B> {
pub struct alist<A,B> {
eq_fn: extern "Rust" fn(A,A) -> bool,
data: Gc<RefCell<Vec<Entry<A,B>>>>,
data: Box<RefCell<Vec<Entry<A,B>>>>,
}
pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
......@@ -47,7 +46,7 @@ pub fn new_int_alist<B:'static>() -> alist<int, B> {
fn eq_int(a: int, b: int) -> bool { a == b }
return alist {
eq_fn: eq_int,
data: box(GC) RefCell::new(Vec::new()),
data: box RefCell::new(Vec::new()),
};
}
......@@ -57,6 +56,6 @@ pub fn new_int_alist_2<B:'static>() -> alist<int, B> {
fn eq_int(a: int, b: int) -> bool { a == b }
return alist {
eq_fn: eq_int,
data: box(GC) RefCell::new(Vec::new()),
data: box RefCell::new(Vec::new()),
};
}
......@@ -27,9 +27,8 @@ fn add(&self, _s: String) {
pub mod rust {
pub use name_pool::add;
use std::gc::Gc;
pub type rt = Gc<()>;
pub type rt = Box<()>;
pub trait cx {
fn cx(&self);
......
......@@ -13,9 +13,9 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::gc::Gc;
use std::rc::Rc;
pub type header_map = HashMap<String, Gc<RefCell<Vec<Gc<String>>>>>;
pub type header_map = HashMap<String, Rc<RefCell<Vec<Rc<String>>>>>;
// the unused ty param is necessary so this gets monomorphized
pub fn request<T>(req: &header_map) {
......
......@@ -10,7 +10,6 @@
use std::collections::HashMap;
use std::gc::Gc;
pub type map = Gc<HashMap<uint, uint>>;
pub type map = Box<HashMap<uint, uint>>;
......@@ -56,8 +56,6 @@ pub enum FooEnum {
VarB(uint, uint)
}
// Skipping ty_box
// Tests ty_uniq (of u8)
pub type FooUniq = Box<u8>;
......
......@@ -10,18 +10,15 @@
#![feature(unsafe_destructor)]
extern crate collections;
extern crate time;
use time::precise_time_s;
use std::os;
use std::task;
use std::vec;
use std::gc::{Gc, GC};
#[deriving(Clone)]
enum List<T> {
Nil, Cons(T, Gc<List<T>>)
Nil, Cons(T, Box<List<T>>)
}
enum UniqueList {
......@@ -53,15 +50,13 @@ fn run(repeat: int, depth: int) {
// Filled with things that have to be unwound
struct State {
managed: Gc<nillist>,
unique: Box<nillist>,
tuple: (Gc<nillist>, Box<nillist>),
vec: Vec<Gc<nillist>>,
vec: Vec<Box<nillist>>,
res: r
}
struct r {
_l: Gc<nillist>,
_l: Box<nillist>,
}
#[unsafe_destructor]
......@@ -69,7 +64,7 @@ impl Drop for r {
fn drop(&mut self) {}
}
fn r(l: Gc<nillist>) -> r {
fn r(l: Box<nillist>) -> r {
r {
_l: l
}
......@@ -85,22 +80,17 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
let st = match st {
None => {
State {
managed: box(GC) Nil,
unique: box Nil,
tuple: (box(GC) Nil, box Nil),
vec: vec!(box(GC) Nil),
res: r(box(GC) Nil)
vec: vec!(box Nil),
res: r(box Nil)
}
}
Some(st) => {
State {
managed: box(GC) Cons((), st.managed),
unique: box Cons((), box(GC) *st.unique),
tuple: (box(GC) Cons((), st.tuple.ref0().clone()),
box Cons((), box(GC) *st.tuple.ref1().clone())),
unique: box Cons((), box *st.unique),
vec: st.vec.clone().append(
&[box(GC) Cons((), *st.vec.last().unwrap())]),
res: r(box(GC) Cons((), st.res._l))
&[box Cons((), *st.vec.last().unwrap())]),
res: r(box Cons((), st.res._l))
}
}
};
......
......@@ -8,30 +8,25 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
use std::gc::{Gc, GC};
struct clam {
x: Gc<int>,
y: Gc<int>,
x: Box<int>,
y: Box<int>,
}
struct fish {
a: Gc<int>,
a: Box<int>,
}
fn main() {
let a: clam = clam{x: box(GC) 1, y: box(GC) 2};
let b: clam = clam{x: box(GC) 10, y: box(GC) 20};
let z: int = a.x + b.y; //~ ERROR binary operation `+` cannot be applied to type `Gc<int>`
println!("{:?}", z);
let a: clam = clam{x: box 1, y: box 2};
let b: clam = clam{x: box 10, y: box 20};
let z: int = a.x + b.y; //~ ERROR binary operation `+` cannot be applied to type `Box<int>`
println!("{}", z);
assert_eq!(z, 21);
let forty: fish = fish{a: box(GC) 40};
let two: fish = fish{a: box(GC) 2};
let forty: fish = fish{a: box 40};
let two: fish = fish{a: box 2};
let answer: int = forty.a + two.a;
//~^ ERROR binary operation `+` cannot be applied to type `Gc<int>`
println!("{:?}", answer);
//~^ ERROR binary operation `+` cannot be applied to type `Box<int>`
println!("{}", answer);
assert_eq!(answer, 42);
}
// Copyright 2014 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.
use std::gc::GC;
struct A;
impl A {
fn foo(&mut self) {
}
}
pub fn main() {
let a = box(GC) A;
a.foo();
//~^ ERROR cannot borrow immutable dereference of `Gc` `*a` as mutable
}
// Copyright 2014 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.
// Verify that managed pointers scope is treated like owned pointers.
// regression test for #11586
use std::gc::{GC, Gc};
fn foo(x: &Gc<int>) -> &int {
match x {
&ref y => {
&**y // Do not expect an error here
}
}
}
fn bar() {
let a = 3i;
let mut y = &a;
if true {
let x = box(GC) 3i;
y = &*x; //~ ERROR `*x` does not live long enough
}
}
fn main() {}
// Copyright 2012-2014 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.
// exec-env:RUST_POISON_ON_FREE=1
use std::gc::GC;
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
assert_eq!(before, after);
}
struct F { f: Box<int> }
pub fn main() {
let mut x = box(GC) F {f: box 3};
borrow(&*x.f, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x.f) as *const int, &(*b_x) as *const int);
//~^ NOTE borrow occurs due to use of `x` in closure
x = box(GC) F {f: box 4};
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
assert!(&(*x.f) as *const int != &(*b_x) as *const int);
})
}
// Copyright 2012-2014 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.
// exec-env:RUST_POISON_ON_FREE=1
use std::gc::GC;
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
assert_eq!(before, after);
}
struct F { f: Box<int> }
pub fn main() {
let mut x = box box(GC) F{f: box 3};
borrow(&*x.f, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x.f) as *const int, &(*b_x) as *const int);
//~^ NOTE borrow occurs due to use of `x` in closure
*x = box(GC) F{f: box 4};
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
assert!(&(*x.f) as *const int != &(*b_x) as *const int);
})
}
// Copyright 2012-2014 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.
// exec-env:RUST_POISON_ON_FREE=1
use std::gc::GC;
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
assert_eq!(before, after);
}
pub fn main() {
let mut x = box(GC) 3;
borrow(&*x, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x) as *const int, &(*b_x) as *const int);
//~^ NOTE borrow occurs due to use of `x` in closure
x = box(GC) 22;
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
assert!(&(*x) as *const int != &(*b_x) as *const int);
})
}
// Copyright 2012 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.
// exec-env:RUST_POISON_ON_FREE=1
use std::gc::GC;
fn testfn(cond: bool) {
let mut x = box(GC) 3i;
let mut y = box(GC) 4i;
// borrow x and y
let r_x = &*x;
let r_y = &*y;
let mut r = r_x;
let mut exp = 3;
if cond {
r = r_y;
exp = 4;
}
println!("*r = {}, exp = {}", *r, exp);
assert_eq!(*r, exp);
x = box(GC) 5i; //~ERROR cannot assign to `x` because it is borrowed
y = box(GC) 6i; //~ERROR cannot assign to `y` because it is borrowed
println!("*r = {}, exp = {}", *r, exp);
assert_eq!(*r, exp);
assert_eq!(x, box(GC) 5i);
assert_eq!(y, box(GC) 6i);
}
pub fn main() {
testfn(true);
testfn(false);
}
// Copyright 2012-2014 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.
// exec-env:RUST_POISON_ON_FREE=1
use std::gc::GC;
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
assert_eq!(before, after);
}
struct F { f: Box<int> }
pub fn main() {
let mut x = box(GC) F {f: box 3};
borrow(&*(*x).f, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x.f) as *const int, &(*b_x) as *const int);
//~^ NOTE borrow occurs due to use of `x` in closure
x = box(GC) F {f: box 4};
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);
assert!(&(*x.f) as *const int != &(*b_x) as *const int);
})
}
// Copyright 2014 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.
use std::gc::{Gc, GC};
fn f<T>(x: T) -> Gc<T> {
box(GC) x //~ ERROR the parameter type `T` may not live long enough
}
fn g<T:'static>(x: T) -> Gc<T> {
box(GC) x // ok
}
fn main() {}
......@@ -11,7 +11,6 @@
// Verifies all possible restrictions for static items values.
use std::kinds::marker;
use std::gc::{Gc, GC};
struct WithDtor;
......@@ -124,9 +123,6 @@ fn drop(&mut self) {}
static mut STATIC17: SafeEnum = Variant1;
//~^ ERROR mutable static items are not allowed to have destructors
static STATIC18: Gc<SafeStruct> = box(GC) SafeStruct{field1: Variant1, field2: Variant2(0)};
//~^ ERROR static items are not allowed to have custom pointers
static STATIC19: Box<int> = box 3;
//~^ ERROR static items are not allowed to have custom pointers
......
......@@ -8,11 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing that we can't store a reference it task-local storage
// Testing that we can't store a reference in task-local storage
use std::gc::{GC, Gc};
local_data_key!(key: Gc<&int>)
local_data_key!(key: Box<&int>)
//~^ ERROR missing lifetime specifier
fn main() {}
......@@ -8,12 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::gc::{GC,Gc};
fn main() {
let x: Box<int> = box 0;
let y: Gc<int> = box (GC) 0;
println!("{}", x + 1); //~ ERROR binary operation `+` cannot be applied to type `Box<int>`
println!("{}", y + 1); //~ ERROR binary operation `+` cannot be applied to type `Gc<int>`
}
......@@ -9,17 +9,14 @@
// except according to those terms.
use std::gc::Gc;
// test that autoderef of a type like this does not
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
struct t { //~ ERROR this type cannot be instantiated
x: x,
struct S { //~ ERROR this type cannot be instantiated
x: X,
to_str: (),
}
struct x(Gc<t>); //~ ERROR this type cannot be instantiated
struct X(Box<S>); //~ ERROR this type cannot be instantiated
fn main() {
}
fn main() {}
......@@ -8,17 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::gc::Gc;
struct P { child: Option<Gc<P>> }
struct P { child: Option<Box<P>> }
trait PTrait {
fn getChildOption(&self) -> Option<Gc<P>>;
fn getChildOption(&self) -> Option<Box<P>>;
}
impl PTrait for P {
fn getChildOption(&self) -> Option<Gc<P>> {
static childVal: Gc<P> = self.child.get();
fn getChildOption(&self) -> Option<Box<P>> {
static childVal: Box<P> = self.child.get();
//~^ ERROR attempt to use a non-constant value in a constant
fail!();
}
......
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
mod my_mod {
pub struct MyStruct {
priv_field: int
......@@ -29,11 +27,8 @@ fn main() {
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
let _woohoo = (box my_struct).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
let _woohoo = (box(GC) my_struct).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
(&my_struct).happyfun(); //~ ERROR method `happyfun` is private
(box my_struct).happyfun(); //~ ERROR method `happyfun` is private
(box(GC) my_struct).happyfun(); //~ ERROR method `happyfun` is private
let nope = my_struct.priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
}
......@@ -8,14 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::gc::Gc;
struct BarStruct;
impl<'a> BarStruct {
fn foo(&'a mut self) -> Gc<BarStruct> { self }
//~^ ERROR: error: mismatched types: expected `Gc<BarStruct>`, found `&'a mut BarStruct
fn foo(&'a mut self) -> Box<BarStruct> { self }
//~^ ERROR: error: mismatched types: expected `Box<BarStruct>`, found `&'a mut BarStruct
}
fn main() {}
......@@ -10,10 +10,9 @@
use std::cell::RefCell;
use std::gc::{Gc, GC};
// Regresion test for issue 7364
static managed: Gc<RefCell<int>> = box(GC) RefCell::new(0);
static boxed: Box<RefCell<int>> = box RefCell::new(0);
//~^ ERROR static items are not allowed to have custom pointers
fn main() { }
......@@ -12,7 +12,6 @@
use std::rc::Rc;
use std::gc::Gc;
fn assert_copy<T:Copy>() { }
trait Dummy { }
......@@ -76,8 +75,7 @@ fn test<'a,T,U:Copy>(_: &'a int) {
// structs containing non-POD are not ok
assert_copy::<MyNoncopyStruct>(); //~ ERROR `core::kinds::Copy` is not implemented
// managed or ref counted types are not ok
assert_copy::<Gc<int>>(); //~ ERROR `core::kinds::Copy` is not implemented
// ref counted types are not ok
assert_copy::<Rc<int>>(); //~ ERROR `core::kinds::Copy` is not implemented
}
......
......@@ -9,10 +9,10 @@
// except according to those terms.
use std::gc::Gc;
use std::rc::Rc;
struct Foo {
f: Gc<int>,
f: Rc<int>,
}
impl Drop for Foo {
......
......@@ -9,12 +9,12 @@
// except according to those terms.
use std::gc::{Gc, GC};
use std::rc::Rc;
fn foo(_x: Gc<uint>) {}
fn foo(_x: Rc<uint>) {}
fn main() {
let x = box(GC) 3u;
let x = Rc::new(3u);
let _: proc():Send = proc() foo(x); //~ ERROR `core::kinds::Send` is not implemented
let _: proc():Send = proc() foo(x); //~ ERROR `core::kinds::Send` is not implemented
let _: proc():Send = proc() foo(x); //~ ERROR `core::kinds::Send` is not implemented
......
// Copyright 2012 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.
#![forbid(heap_memory)]
#![allow(dead_code)]
use std::gc::{Gc, GC};
struct Foo {
x: Gc<int>, //~ ERROR type uses managed
}
struct Bar { x: Box<int> } //~ ERROR type uses owned
fn main() {
let _x : Bar = Bar {x : box 10i}; //~ ERROR type uses owned
box(GC) 2i; //~ ERROR type uses managed
box 2i; //~ ERROR type uses owned
fn g(_: Box<Clone>) {} //~ ERROR type uses owned
proc() {}; //~ ERROR type uses owned
}
// Copyright 2012 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.
#![allow(dead_code)]
#![forbid(managed_heap_memory)]
use std::gc::{Gc, GC};
struct Foo {
x: Gc<int> //~ ERROR type uses managed
}
fn main() {
let _x : Foo = Foo {x : box(GC) 10};
//~^ ERROR type uses managed
}
// Copyright 2014 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.
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the new `box` syntax works with unique pointers and GC pointers.
use std::gc::{Gc, GC};
use std::boxed::{Box, HEAP};
pub fn main() {
let x: Gc<int> = box(HEAP) 2; //~ ERROR mismatched types
let y: Gc<int> = box(HEAP)(1 + 2); //~ ERROR mismatched types
let z: Box<int> = box(GC)(4 + 5); //~ ERROR mismatched types
}
......@@ -10,14 +10,14 @@
#![feature(unsafe_destructor)]
extern crate debug;
use std::task;
use std::gc::{Gc, GC};
use std::rc::Rc;
struct Port<T>(Gc<T>);
#[deriving(Show)]
struct Port<T>(Rc<T>);
fn main() {
#[deriving(Show)]
struct foo {
_x: Port<()>,
}
......@@ -33,11 +33,11 @@ fn foo(x: Port<()>) -> foo {
}
}
let x = foo(Port(box(GC) ()));
let x = foo(Port(Rc::new(())));
task::spawn(proc() {
let y = x;
//~^ ERROR `core::kinds::Send` is not implemented
println!("{:?}", y);
println!("{}", y);
});
}
......@@ -8,11 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::gc::GC;
fn main() {
let f;
let g;
g = f;
f = box(GC) g; //~ ERROR cyclic type of infinite size
f = box g; //~ ERROR cyclic type of infinite size
}
......@@ -9,9 +9,7 @@
// except according to those terms.
use std::gc::GC;
fn main() {
let f;
f = box(GC) f; //~ ERROR cyclic type of infinite size
f = box f; //~ ERROR cyclic type of infinite size
}
// Copyright 2012 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.
#![feature(unsafe_destructor)]
extern crate debug;
use std::cell::Cell;
use std::gc::{Gc, GC};
struct r {
i: Gc<Cell<int>>,
}
#[unsafe_destructor]
impl Drop for r {
fn drop(&mut self) {
unsafe {
self.i.set(self.i.get() + 1);
}
}
}
fn r(i: Gc<Cell<int>>) -> r {
r {
i: i
}
}
struct A {
y: r,
}
fn main() {
let i = box(GC) Cell::new(0);
{
// Can't do this copy
let x = box box box A {y: r(i)};
let _z = x.clone(); //~ ERROR not implemented
println!("{:?}", x);
}
println!("{:?}", *i);
}
// Copyright 2012 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.
// Test no-special rooting is used for managed boxes
use std::gc::GC;
fn testfn(cond: bool) {
let mut x = box(GC) 3i;
let mut y = box(GC) 4i;
let mut a = &*x;
let mut exp = 3i;
if cond {
a = &*y;
exp = 4;
}
x = box(GC) 5i; //~ERROR cannot assign to `x` because it is borrowed
y = box(GC) 6i; //~ERROR cannot assign to `y` because it is borrowed
assert_eq!(*a, exp);
assert_eq!(x, box(GC) 5i);
assert_eq!(y, box(GC) 6i);
}
pub fn main() {}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::Gc;
struct point {
x: int,
y: int,
......@@ -20,7 +18,7 @@ fn x_coord<'r>(p: &'r point) -> &'r int {
return &p.x;
}
fn foo<'a>(p: Gc<point>) -> &'a int {
fn foo<'a>(p: Box<point>) -> &'a int {
let xc = x_coord(&*p); //~ ERROR `*p` does not live long enough
assert_eq!(*xc, 3);
return xc;
......
......@@ -9,11 +9,9 @@
// except according to those terms.
use std::gc::Gc;
fn borrow<T>(x: &T) -> &T {x}
fn foo(cond: || -> bool, make_box: || -> Gc<int>) {
fn foo(cond: || -> bool, make_box: || -> Box<int>) {
let mut y: &int;
loop {
let x = make_box();
......
......@@ -12,27 +12,25 @@
// Check that we correctly infer that b and c must be region
// parameterized because they reference a which requires a region.
use std::gc::Gc;
type a<'a> = &'a int;
type b<'a> = Gc<a<'a>>;
type b<'a> = Box<a<'a>>;
struct c<'a> {
f: Gc<b<'a>>
f: Box<b<'a>>
}
trait set_f<'a> {
fn set_f_ok(&mut self, b: Gc<b<'a>>);
fn set_f_bad(&mut self, b: Gc<b>);
fn set_f_ok(&mut self, b: Box<b<'a>>);
fn set_f_bad(&mut self, b: Box<b>);
}
impl<'a> set_f<'a> for c<'a> {
fn set_f_ok(&mut self, b: Gc<b<'a>>) {
fn set_f_ok(&mut self, b: Box<b<'a>>) {
self.f = b;
}
fn set_f_bad(&mut self, b: Gc<b>) {
self.f = b; //~ ERROR mismatched types: expected `Gc<Gc<&'a int>>`, found `Gc<Gc<&int>>`
fn set_f_bad(&mut self, b: Box<b>) {
self.f = b; //~ ERROR mismatched types: expected `Box<Box<&'a int>>`, found `Box<Box<&int>>`
}
}
......
......@@ -9,12 +9,10 @@
// except according to those terms.
use std::gc::GC;
fn f<T:'static>(_: T) {}
fn main() {
let x = box(GC) 3i;
let x = box 3i;
f(x);
let x = &3i; //~ ERROR borrowed value does not live long enough
f(x);
......
......@@ -11,13 +11,11 @@
// except according to those terms.
use std::gc::{Gc, GC};
struct Foo<'a> {
x: &'a int
}
pub fn main() {
let f = Foo { x: &*(box(GC) 3) }; //~ ERROR borrowed value does not live long enough
let f = Foo { x: &*(box 3) }; //~ ERROR borrowed value does not live long enough
assert_eq!(*f.x, 3);
}
......@@ -9,18 +9,16 @@
// except according to those terms.
use std::gc::Gc;
struct foo {
a: int,
b: int,
}
type bar = Gc<foo>;
type bar = Box<foo>;
fn want_foo(f: foo) {}
fn have_bar(b: bar) {
want_foo(b); //~ ERROR (expected struct foo, found Gc-ptr)
want_foo(b); //~ ERROR (expected struct foo, found box)
}
fn main() {}
......@@ -9,15 +9,13 @@
// except according to those terms.
use std::gc::Gc;
trait Mumbo {
fn jumbo(&self, x: Gc<uint>) -> uint;
fn jumbo(&self, x: &uint) -> uint;
}
impl Mumbo for uint {
// Cannot have a larger effect than the trait:
unsafe fn jumbo(&self, x: Gc<uint>) { *self + *x; }
unsafe fn jumbo(&self, x: &uint) { *self + *x; }
//~^ ERROR expected normal fn, found unsafe fn
}
......
......@@ -9,12 +9,12 @@
// except according to those terms.
use std::gc::GC;
use std::rc::Rc;
fn f<T:Send>(_i: T) {
}
fn main() {
let i = box box(GC) 100i;
let i = box Rc::new(100i);
f(i); //~ ERROR `core::kinds::Send` is not implemented
}
......@@ -10,16 +10,15 @@
#![feature(unsafe_destructor)]
extern crate debug;
use std::cell::Cell;
use std::gc::{Gc, GC};
struct r {
i: Gc<Cell<int>>,
#[deriving(Show)]
struct r<'a> {
i: &'a Cell<int>,
}
#[unsafe_destructor]
impl Drop for r {
impl<'a> Drop for r<'a> {
fn drop(&mut self) {
unsafe {
self.i.set(self.i.get() + 1);
......@@ -31,13 +30,13 @@ fn f<T>(_i: Vec<T> , _j: Vec<T> ) {
}
fn main() {
let i1 = box(GC) Cell::new(0);
let i2 = box(GC) Cell::new(1);
let i1 = &Cell::new(0);
let i2 = &Cell::new(1);
let r1 = vec!(box r { i: i1 });
let r2 = vec!(box r { i: i2 });
f(r1.clone(), r2.clone());
//~^ ERROR the trait `core::clone::Clone` is not implemented
//~^^ ERROR the trait `core::clone::Clone` is not implemented
println!("{:?}", (r2, i1.get()));
println!("{:?}", (r1, i2.get()));
println!("{}", (r2, i1.get()));
println!("{}", (r1, i2.get()));
}
......@@ -12,14 +12,14 @@
// Test that a class with an unsendable field can't be
// sent
use std::gc::{Gc, GC};
use std::rc::Rc;
struct foo {
i: int,
j: Gc<String>,
j: Rc<String>,
}
fn foo(i:int, j: Gc<String>) -> foo {
fn foo(i:int, j: Rc<String>) -> foo {
foo {
i: i,
j: j
......@@ -29,5 +29,5 @@ fn foo(i:int, j: Gc<String>) -> foo {
fn main() {
let cat = "kitty".to_string();
let (tx, _) = channel(); //~ ERROR `core::kinds::Send` is not implemented
tx.send(foo(42, box(GC) (cat))); //~ ERROR `core::kinds::Send` is not implemented
tx.send(foo(42, Rc::new(cat))); //~ ERROR `core::kinds::Send` is not implemented
}
// Copyright 2013-2014 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.
// ignore-android: FIXME(#10381)
// Gdb doesn't know about UTF-32 character encoding and will print a rust char as only
// its numerical value.
// compile-flags:-g
// === GDB TESTS ===================================================================================
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *bool_ref
// gdb-check:$1 = true
// gdb-command:print *int_ref
// gdb-check:$2 = -1
// gdb-command:print *char_ref
// gdb-check:$3 = 97
// gdb-command:print/d *i8_ref
// gdb-check:$4 = 68
// gdb-command:print *i16_ref
// gdb-check:$5 = -16
// gdb-command:print *i32_ref
// gdb-check:$6 = -32
// gdb-command:print *i64_ref
// gdb-check:$7 = -64
// gdb-command:print *uint_ref
// gdb-check:$8 = 1
// gdb-command:print/d *u8_ref
// gdb-check:$9 = 100
// gdb-command:print *u16_ref
// gdb-check:$10 = 16
// gdb-command:print *u32_ref
// gdb-check:$11 = 32
// gdb-command:print *u64_ref
// gdb-check:$12 = 64
// gdb-command:print *f32_ref
// gdb-check:$13 = 2.5
// gdb-command:print *f64_ref
// gdb-check:$14 = 3.5
// === LLDB TESTS ==================================================================================
// lldb-command:type format add -f decimal char
// lldb-command:type format add -f decimal 'unsigned char'
// lldb-command:run
// lldb-command:print *bool_ref
// lldb-check:[...]$0 = true
// lldb-command:print *int_ref
// lldb-check:[...]$1 = -1
// LLDB can't handle 32bit chars yet
// d ebugger:print *char_ref
// c heck:[...]$x = 97
// lldb-command:print *i8_ref
// lldb-check:[...]$2 = 68
// lldb-command:print *i16_ref
// lldb-check:[...]$3 = -16
// lldb-command:print *i32_ref
// lldb-check:[...]$4 = -32
// lldb-command:print *i64_ref
// lldb-check:[...]$5 = -64
// lldb-command:print *uint_ref
// lldb-check:[...]$6 = 1
// lldb-command:print *u8_ref
// lldb-check:[...]$7 = 100
// lldb-command:print *u16_ref
// lldb-check:[...]$8 = 16
// lldb-command:print *u32_ref
// lldb-check:[...]$9 = 32
// lldb-command:print *u64_ref
// lldb-check:[...]$10 = 64
// lldb-command:print *f32_ref
// lldb-check:[...]$11 = 2.5
// lldb-command:print *f64_ref
// lldb-check:[...]$12 = 3.5
#![allow(unused_variable)]
use std::gc::{Gc, GC};
fn main() {
let bool_box: Gc<bool> = box(GC) true;
let bool_ref: &bool = &*bool_box;
let int_box: Gc<int> = box(GC) -1;
let int_ref: &int = &*int_box;
let char_box: Gc<char> = box(GC) 'a';
let char_ref: &char = &*char_box;
let i8_box: Gc<i8> = box(GC) 68;
let i8_ref: &i8 = &*i8_box;
let i16_box: Gc<i16> = box(GC) -16;
let i16_ref: &i16 = &*i16_box;
let i32_box: Gc<i32> = box(GC) -32;
let i32_ref: &i32 = &*i32_box;
let i64_box: Gc<i64> = box(GC) -64;
let i64_ref: &i64 = &*i64_box;
let uint_box: Gc<uint> = box(GC) 1;
let uint_ref: &uint = &*uint_box;
let u8_box: Gc<u8> = box(GC) 100;
let u8_ref: &u8 = &*u8_box;
let u16_box: Gc<u16> = box(GC) 16;
let u16_ref: &u16 = &*u16_box;
let u32_box: Gc<u32> = box(GC) 32;
let u32_ref: &u32 = &*u32_box;
let u64_box: Gc<u64> = box(GC) 64;
let u64_ref: &u64 = &*u64_box;
let f32_box: Gc<f32> = box(GC) 2.5;
let f32_ref: &f32 = &*f32_box;
let f64_box: Gc<f64> = box(GC) 3.5;
let f64_ref: &f64 = &*f64_box;
zzz(); // #break
}
fn zzz() {()}
......@@ -29,15 +29,6 @@
// gdb-command:print *ref_to_unnamed
// gdb-check:$4 = {x = 11, y = 24.5}
// gdb-command:print *managed_val_ref
// gdb-check:$5 = {x = 12, y = 25.5}
// gdb-command:print *managed_val_interior_ref_1
// gdb-check:$6 = 12
// gdb-command:print *managed_val_interior_ref_2
// gdb-check:$7 = 25.5
// gdb-command:print *unique_val_ref
// gdb-check:$8 = {x = 13, y = 26.5}
......@@ -64,15 +55,6 @@
// lldb-command:print *ref_to_unnamed
// lldb-check:[...]$3 = SomeStruct { x: 11, y: 24.5 }
// lldb-command:print *managed_val_ref
// lldb-check:[...]$4 = SomeStruct { x: 12, y: 25.5 }
// lldb-command:print *managed_val_interior_ref_1
// lldb-check:[...]$5 = 12
// lldb-command:print *managed_val_interior_ref_2
// lldb-check:[...]$6 = 25.5
// lldb-command:print *unique_val_ref
// lldb-check:[...]$7 = SomeStruct { x: 13, y: 26.5 }
......@@ -84,8 +66,6 @@
#![allow(unused_variable)]
use std::gc::GC;
struct SomeStruct {
x: int,
y: f64
......@@ -98,11 +78,6 @@ fn main() {
let stack_val_interior_ref_2: &f64 = &stack_val.y;
let ref_to_unnamed: &SomeStruct = &SomeStruct { x: 11, y: 24.5 };
let managed_val = box(GC) SomeStruct { x: 12, y: 25.5 };
let managed_val_ref: &SomeStruct = &*managed_val;
let managed_val_interior_ref_1: &int = &managed_val.x;
let managed_val_interior_ref_2: &f64 = &managed_val.y;
let unique_val = box SomeStruct { x: 13, y: 26.5 };
let unique_val_ref: &SomeStruct = &*unique_val;
let unique_val_interior_ref_1: &int = &unique_val.x;
......
......@@ -25,9 +25,6 @@
// gdb-command:print *ref_to_unnamed
// gdb-check:$2 = {-15, -20}
// gdb-command:print *managed_val_ref
// gdb-check:$3 = {-16, -21}
// gdb-command:print *unique_val_ref
// gdb-check:$4 = {-17, -22}
......@@ -42,25 +39,17 @@
// lldb-command:print *ref_to_unnamed
// lldb-check:[...]$1 = (-15, -20)
// lldb-command:print *managed_val_ref
// lldb-check:[...]$2 = (-16, -21)
// lldb-command:print *unique_val_ref
// lldb-check:[...]$3 = (-17, -22)
#![allow(unused_variable)]
use std::gc::{Gc, GC};
fn main() {
let stack_val: (i16, f32) = (-14, -19f32);
let stack_val_ref: &(i16, f32) = &stack_val;
let ref_to_unnamed: &(i16, f32) = &(-15, -20f32);
let managed_val: Gc<(i16, f32)> = box(GC) (-16, -21f32);
let managed_val_ref: &(i16, f32) = &*managed_val;
let unique_val: Box<(i16, f32)> = box() (-17, -22f32);
let unique_val_ref: &(i16, f32) = &*unique_val;
......
......@@ -22,10 +22,6 @@
// gdb-check:$1 = 1
// gdb-command:print *b
// gdb-check:$2 = {2, 3.5}
// gdb-command:print c->val
// gdb-check:$3 = 4
// gdb-command:print d->val
// gdb-check:$4 = false
// === LLDB TESTS ==================================================================================
......@@ -35,20 +31,12 @@
// lldb-check:[...]$0 = 1
// lldb-command:print *b
// lldb-check:[...]$1 = (2, 3.5)
// lldb-command:print c->val
// lldb-check:[...]$2 = 4
// lldb-command:print d->val
// lldb-check:[...]$3 = false
#![allow(unused_variable)]
use std::gc::GC;
fn main() {
let a = box 1i;
let b = box() (2i, 3.5f64);
let c = box(GC) 4i;
let d = box(GC) false;
zzz(); // #break
}
......
......@@ -21,15 +21,9 @@
// gdb-command:print *unique
// gdb-check:$1 = {x = 99, y = 999, z = 9999, w = 99999}
// gdb-command:print managed->val
// gdb-check:$2 = {x = 88, y = 888, z = 8888, w = 88888}
// gdb-command:print *unique_dtor
// gdb-check:$3 = {x = 77, y = 777, z = 7777, w = 77777}
// gdb-command:print managed_dtor->val
// gdb-check:$4 = {x = 33, y = 333, z = 3333, w = 33333}
// === LLDB TESTS ==================================================================================
......@@ -38,19 +32,11 @@
// lldb-command:print *unique
// lldb-check:[...]$0 = StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 }
// lldb-command:print managed->val
// lldb-check:[...]$1 = StructWithSomePadding { x: 88, y: 888, z: 8888, w: 88888 }
// lldb-command:print *unique_dtor
// lldb-check:[...]$2 = StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 }
// lldb-command:print managed_dtor->val
// lldb-check:[...]$3 = StructWithDestructor { x: 33, y: 333, z: 3333, w: 33333 }
#![allow(unused_variable)]
use std::gc::GC;
struct StructWithSomePadding {
x: i16,
y: i32,
......@@ -72,11 +58,8 @@ fn drop(&mut self) {}
fn main() {
let unique = box StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 };
let managed = box(GC) StructWithSomePadding { x: 88, y: 888, z: 8888, w: 88888 };
let unique_dtor = box StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 };
let managed_dtor = box(GC) StructWithDestructor { x: 33, y: 333, z: 3333, w: 33333 };
zzz(); // #break
}
......
......@@ -33,11 +33,6 @@
// gdb-check:$3 = {4444.5, 5555, 6666, 7777.5}
// gdb-command:continue
// gdb-command:finish
// gdb-command:print self->val
// gdb-check:$4 = 8888
// gdb-command:continue
// === LLDB TESTS ==================================================================================
......@@ -55,12 +50,6 @@
// lldb-check:[...]$2 = (4444.5, 5555, 6666, 7777.5)
// lldb-command:continue
// lldb-command:print self->val
// lldb-check:[...]$3 = 8888
// lldb-command:continue
use std::gc::{Gc, GC};
trait Trait {
fn method(self) -> Self;
}
......@@ -91,18 +80,10 @@ fn method(self) -> (f64, int, int, f64) {
}
}
impl Trait for Gc<int> {
fn method(self) -> Gc<int> {
zzz(); // #break
self
}
}
fn main() {
let _ = (1111 as int).method();
let _ = Struct { x: 2222, y: 3333 }.method();
let _ = (4444.5, 5555, 6666, 7777.5).method();
let _ = (box(GC) 8888).method();
}
fn zzz() { () }
// Copyright 2013-2014 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.
// ignore-android: FIXME(#10381)
// compile-flags:-g
// === GDB TESTS ===================================================================================
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print the_a->val
// gdb-check:$1 = {{TheA, x = 0, y = 8970181431921507452}, {TheA, 0, 2088533116, 2088533116}}
// gdb-command:print the_b->val
// gdb-check:$2 = {{TheB, x = 0, y = 1229782938247303441}, {TheB, 0, 286331153, 286331153}}
// gdb-command:print univariant->val
// gdb-check:$3 = {{-9747455}}
// === LLDB TESTS ==================================================================================
// lldb-command:run
// lldb-command:print the_a->val
// lldb-check:[...]$0 = TheA { x: 0, y: 8970181431921507452 }
// lldb-command:print the_b->val
// lldb-check:[...]$1 = TheB(0, 286331153, 286331153)
// lldb-command:print univariant->val
// lldb-check:[...]$2 = TheOnlyCase(-9747455)
#![allow(unused_variable)]
#![feature(struct_variant)]
use std::gc::GC;
// The first element is to ensure proper alignment, irrespective of the machines word size. Since
// the size of the discriminant value is machine dependent, this has be taken into account when
// datatype layout should be predictable as in this case.
enum ABC {
TheA { x: i64, y: i64 },
TheB (i64, i32, i32),
}
// This is a special case since it does not have the implicit discriminant field.
enum Univariant {
TheOnlyCase(i64)
}
fn main() {
// In order to avoid endianess trouble all of the following test values consist of a single
// repeated byte. This way each interpretation of the union should look the same, no matter if
// this is a big or little endian machine.
// 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
// 0b01111100011111000111110001111100 = 2088533116
// 0b0111110001111100 = 31868
// 0b01111100 = 124
let the_a = box(GC) TheA { x: 0, y: 8970181431921507452 };
// 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
// 0b00010001000100010001000100010001 = 286331153
// 0b0001000100010001 = 4369
// 0b00010001 = 17
let the_b = box(GC) TheB (0, 286331153, 286331153);
let univariant = box(GC) TheOnlyCase(-9747455);
zzz(); // #break
}
fn zzz() {()}
// Copyright 2013-2014 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.
// ignore-android: FIXME(#10381)
// compile-flags:-g
// === GDB TESTS ===================================================================================
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print unique.ptr[0]->val
// gdb-check:$1 = 10
// gdb-command:print unique.ptr[1]->val
// gdb-check:$2 = 11
// gdb-command:print unique.ptr[2]->val
// gdb-check:$3 = 12
// gdb-command:print unique.ptr[3]->val
// gdb-check:$4 = 13
// === LLDB TESTS ==================================================================================
// lldb-command:run
// lldb-command:print unique.ptr[0]->val
// lldb-check:[...]$0 = 10
// lldb-command:print unique.ptr[1]->val
// lldb-check:[...]$1 = 11
// lldb-command:print unique.ptr[2]->val
// lldb-check:[...]$2 = 12
// lldb-command:print unique.ptr[3]->val
// lldb-check:[...]$3 = 13
#![allow(unused_variable)]
use std::gc::{Gc, GC};
fn main() {
let unique: Vec<Gc<i64>> = vec!(box(GC) 10, box(GC) 11, box(GC) 12, box(GC) 13);
zzz(); // #break
}
fn zzz() {()}
// Copyright 2013-2014 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.
// ignore-android: FIXME(#10381)
// compile-flags:-g
// === GDB TESTS ===================================================================================
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *ordinary_unique
// gdb-check:$1 = {-1, -2}
// gdb-command:print managed_within_unique->x
// gdb-check:$2 = -3
// gdb-command:print managed_within_unique->y->val
// gdb-check:$3 = -4
// === LLDB TESTS ==================================================================================
// lldb-command:run
// lldb-command:print *ordinary_unique
// lldb-check:[...]$0 = (-1, -2)
// lldb-command:print managed_within_unique->x
// lldb-check:[...]$1 = -3
// lldb-command:print managed_within_unique->y->val
// lldb-check:[...]$2 = -4
#![allow(unused_variable)]
use std::gc::{GC, Gc};
struct ContainsManaged {
x: int,
y: Gc<int>,
}
fn main() {
let ordinary_unique = box() (-1i, -2i);
let managed_within_unique = box ContainsManaged { x: -3, y: box(GC) -4i };
zzz(); // #break
}
fn zzz() {()}
......@@ -29,11 +29,6 @@
// gdb-command:print unique_unique->next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdb-check:$4 = 3
// gdb-command:print box_unique->val.value
// gdb-check:$5 = 4
// gdb-command:print box_unique->val.next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdb-check:$6 = 5
// gdb-command:print vec_unique[0].value
// gdb-check:$7 = 6.5
// gdb-command:print vec_unique[0].next.RUST$ENCODED$ENUM$0$Empty.val->value
......@@ -44,32 +39,6 @@
// gdb-command:print borrowed_unique->next.RUST$ENCODED$ENUM$0$Empty.val->value
// gdb-check:$10 = 9.5
// MANAGED
// gdb-command:print stack_managed.value
// gdb-check:$11 = 10
// gdb-command:print stack_managed.next.RUST$ENCODED$ENUM$0$Empty.val->val.value
// gdb-check:$12 = 11
// gdb-command:print unique_managed->value
// gdb-check:$13 = 12
// gdb-command:print unique_managed->next.RUST$ENCODED$ENUM$0$Empty.val->val.value
// gdb-check:$14 = 13
// gdb-command:print box_managed.val->value
// gdb-check:$15 = 14
// gdb-command:print box_managed->val->next.RUST$ENCODED$ENUM$0$Empty.val->val.value
// gdb-check:$16 = 15
// gdb-command:print vec_managed[0].value
// gdb-check:$17 = 16.5
// gdb-command:print vec_managed[0].next.RUST$ENCODED$ENUM$0$Empty.val->val.value
// gdb-check:$18 = 17.5
// gdb-command:print borrowed_managed->value
// gdb-check:$19 = 18.5
// gdb-command:print borrowed_managed->next.RUST$ENCODED$ENUM$0$Empty.val->val.value
// gdb-check:$20 = 19.5
// LONG CYCLE
// gdb-command:print long_cycle1.value
// gdb-check:$21 = 20
......@@ -106,8 +75,6 @@
#![allow(unused_variable)]
#![feature(struct_variant)]
use std::gc::{Gc, GC};
enum Opt<T> {
Empty,
Val { val: T }
......@@ -118,11 +85,6 @@ struct UniqueNode<T> {
value: T
}
struct ManagedNode<T> {
next: Opt<Gc<ManagedNode<T>>>,
value: T
}
struct LongCycle1<T> {
next: Box<LongCycle2<T>>,
value: T,
......@@ -184,16 +146,6 @@ fn main() {
value: 2,
};
let box_unique: Gc<UniqueNode<u64>> = box(GC) UniqueNode {
next: Val {
val: box UniqueNode {
next: Empty,
value: 5,
}
},
value: 4,
};
let vec_unique: [UniqueNode<f32>, ..1] = [UniqueNode {
next: Val {
val: box UniqueNode {
......@@ -214,56 +166,6 @@ fn main() {
value: 8.5,
};
let stack_managed: ManagedNode<u16> = ManagedNode {
next: Val {
val: box(GC) ManagedNode {
next: Empty,
value: 11,
}
},
value: 10,
};
let unique_managed: Box<ManagedNode<u32>> = box ManagedNode {
next: Val {
val: box(GC) ManagedNode {
next: Empty,
value: 13,
}
},
value: 12,
};
let box_managed: Gc<ManagedNode<u64>> = box(GC) ManagedNode {
next: Val {
val: box(GC) ManagedNode {
next: Empty,
value: 15,
}
},
value: 14,
};
let vec_managed: [ManagedNode<f32>, ..1] = [ManagedNode {
next: Val {
val: box(GC) ManagedNode {
next: Empty,
value: 17.5,
}
},
value: 16.5,
}];
let borrowed_managed: &ManagedNode<f64> = &ManagedNode {
next: Val {
val: box(GC) ManagedNode {
next: Empty,
value: 19.5,
}
},
value: 18.5,
};
// LONG CYCLE
let long_cycle1: LongCycle1<u16> = LongCycle1 {
next: box LongCycle2 {
......
......@@ -28,8 +28,6 @@
// gdb-check:$4 = {a = -3, b = 4.5, c = 5}
// gdb-command:print *owned
// gdb-check:$5 = 6
// gdb-command:print managed->val
// gdb-check:$6 = 7
// gdb-command:print closure_local
// gdb-check:$7 = 8
// gdb-command:continue
......@@ -45,8 +43,6 @@
// gdb-check:$11 = {a = -3, b = 4.5, c = 5}
// gdb-command:print *owned
// gdb-check:$12 = 6
// gdb-command:print managed->val
// gdb-check:$13 = 7
// gdb-command:print closure_local
// gdb-check:$14 = 8
// gdb-command:continue
......@@ -66,8 +62,6 @@
// lldb-check:[...]$3 = Struct { a: -3, b: 4.5, c: 5 }
// lldb-command:print *owned
// lldb-check:[...]$4 = 6
// lldb-command:print managed->val
// lldb-check:[...]$5 = 7
// lldb-command:print closure_local
// lldb-check:[...]$6 = 8
// lldb-command:continue
......@@ -82,16 +76,12 @@
// lldb-check:[...]$10 = Struct { a: -3, b: 4.5, c: 5 }
// lldb-command:print *owned
// lldb-check:[...]$11 = 6
// lldb-command:print managed->val
// lldb-check:[...]$12 = 7
// lldb-command:print closure_local
// lldb-check:[...]$13 = 8
// lldb-command:continue
#![allow(unused_variable)]
use std::gc::GC;
struct Struct {
a: int,
b: f64,
......@@ -110,14 +100,13 @@ fn main() {
let struct_ref = &a_struct;
let owned = box 6;
let managed = box(GC) 7;
let closure = || {
let closure_local = 8;
let nested_closure = || {
zzz(); // #break
variable = constant + a_struct.a + struct_ref.a + *owned + *managed + closure_local;
variable = constant + a_struct.a + struct_ref.a + *owned + closure_local;
};
zzz(); // #break
......
......@@ -28,8 +28,6 @@
// gdb-check:$4 = {a = -3, b = 4.5, c = 5}
// gdb-command:print *owned
// gdb-check:$5 = 6
// gdb-command:print managed->val
// gdb-check:$6 = 7
// === LLDB TESTS ==================================================================================
......@@ -46,13 +44,9 @@
// lldb-check:[...]$3 = Struct { a: -3, b: 4.5, c: 5 }
// lldb-command:print *owned
// lldb-check:[...]$4 = 6
// lldb-command:print managed->val
// lldb-check:[...]$5 = 7
#![allow(unused_variable)]
use std::gc::GC;
struct Struct {
a: int,
b: f64,
......@@ -71,11 +65,10 @@ fn main() {
let struct_ref = &a_struct;
let owned = box 6;
let managed = box(GC) 7;
let closure = || {
zzz(); // #break
variable = constant + a_struct.a + struct_ref.a + *owned + *managed;
variable = constant + a_struct.a + struct_ref.a + *owned;
};
closure();
......
......@@ -14,34 +14,33 @@
use std::cell::Cell;
use std::gc::GC;
fn test1() { let val = box(GC) 0i; { } *val; }
fn test1() { let val = &0i; { } *val; }
fn test2() -> int { let val = box(GC) 0i; { } *val }
fn test2() -> int { let val = &0i; { } *val }
struct S { eax: int }
fn test3() {
let regs = box(GC) Cell::new(S {eax: 0});
let regs = &Cell::new(S {eax: 0});
match true { true => { } _ => { } }
regs.set(S {eax: 1});
}
fn test4() -> bool { let regs = box(GC) true; if true { } *regs || false }
fn test4() -> bool { let regs = &true; if true { } *regs || false }
fn test5() -> (int, int) { { } (0, 1) }
fn test6() -> bool { { } (true || false) && true }
fn test7() -> uint {
let regs = box(GC) 0i;
let regs = &0i;
match true { true => { } _ => { } }
(*regs < 2) as uint
}
fn test8() -> int {
let val = box(GC) 0i;
let val = &0i;
match true {
true => { }
_ => { }
......@@ -54,12 +53,12 @@ fn test8() -> int {
}
fn test9() {
let regs = box(GC) Cell::new(0i);
let regs = &Cell::new(0i);
match true { true => { } _ => { } } regs.set(regs.get() + 1);
}
fn test10() -> int {
let regs = box(GC) vec!(0i);
let regs = vec!(0i);
match true { true => { } _ => { } }
*(*regs).get(0)
}
......
......@@ -11,8 +11,6 @@
// error-pattern:meep
use std::gc::{Gc, GC};
fn f(_a: int, _b: int, _c: Box<int>) { fail!("moop"); }
fn f(_a: int, _b: int, _c: Gc<int>) { fail!("moop"); }
fn main() { f(1, fail!("meep"), box(GC) 42); }
fn main() { f(1, fail!("meep"), box 42); }
// Copyright 2012 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.
// error-pattern:explicit failure
// Issue #2272 - unwind this without leaking the unique pointer
use std::gc::{Gc, GC};
struct X { y: Y, a: Box<int> }
struct Y { z: Gc<int> }
fn main() {
let _x = X {
y: Y {
z: box(GC) 0
},
a: box 0
};
fail!();
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn main() {
let _a = box(GC) 0i;
assert!(false);
}
// Copyright 2012 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.
// error-pattern:fail
extern crate debug;
use std::gc::{GC, Gc};
fn failfn() {
fail!();
}
fn main() {
let y = box 0i;
let x: Gc<proc():Send> = box(GC) (proc() {
println!("{:?}", y.clone());
});
failfn();
println!("{:?}", x);
}
// Copyright 2012 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.
// error-pattern:fail
extern crate debug;
use std::mem;
use std::gc::GC;
fn failfn() {
fail!();
}
struct r {
v: *const int,
}
impl Drop for r {
fn drop(&mut self) {
unsafe {
let _v2: Box<int> = mem::transmute(self.v);
}
}
}
fn r(v: *const int) -> r {
r {
v: v
}
}
fn main() {
unsafe {
let i1 = box 0i;
let i1p = mem::transmute_copy(&i1);
mem::forget(i1);
let x = box(GC) r(i1p);
failfn();
println!("{:?}", x);
}
}
// Copyright 2012 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.
// error-pattern:fail
extern crate debug;
use std::gc::GC;
fn failfn() {
fail!();
}
fn main() {
let x = box(GC) "hi".to_string();
failfn();
println!("{:?}", x);
}
// Copyright 2012 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.
// error-pattern:fail
extern crate debug;
use std::gc::GC;
fn failfn() {
fail!();
}
fn main() {
let x = box(GC) box box 0i;
failfn();
println!("{:?}", x);
}
// Copyright 2012 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.
// error-pattern:fail
extern crate debug;
use std::gc::GC;
fn failfn() {
fail!();
}
fn main() {
let x = box(GC) box 0i;
failfn();
println!("{:?}", x);
}
// Copyright 2012 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.
// error-pattern:fail
extern crate debug;
use std::gc::GC;
fn failfn() {
fail!();
}
fn main() {
let x = box(GC) vec!(0i, 1, 2, 3, 4, 5);
failfn();
println!("{:?}", x);
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn failfn() {
fail!();
}
fn main() {
box(GC) 0i;
failfn();
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn main() {
box(GC) 0i;
fail!();
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::Gc;
fn f() -> Gc<int> { fail!(); }
fn main() {
let _a: Gc<int> = f();
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::Gc;
fn main() {
let _a: Gc<int> = {
fail!();
};
}
// Copyright 2012 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.
// error-pattern:fail
#![allow(unreachable_code)]
#![allow(unused_variable)]
use std::gc::GC;
fn x(it: |int|) {
fail!();
it(0);
}
fn main() {
let a = box(GC) 0i;
x(|_i| { } );
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::{GC};
fn x(it: |int|) {
let _a = box(GC) 0i;
it(1);
}
fn main() {
x(|_x| fail!() );
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::{Gc, GC};
fn main() {
let cheese = "roquefort".to_string();
let carrots = box(GC) "crunchy".to_string();
let result: |Gc<String>, |String||: 'static = (|tasties, macerate| {
macerate((*tasties).clone());
});
result(carrots, |food| {
let mush = format!("{}{}", food, cheese);
let cheese = cheese.clone();
let f: || = || {
let _chew = format!("{}{}", mush, cheese);
fail!("so yummy")
};
f();
});
}
// Copyright 2012 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.
// Issue #945
// error-pattern:non-exhaustive match failure
use std::gc::GC;
fn test_box() {
box(GC) 0i;
}
fn test_str() {
let res = match false { true => { "happy".to_string() },
_ => fail!("non-exhaustive match failure") };
assert_eq!(res, "happy".to_string());
}
fn main() {
test_box();
test_str();
}
// Copyright 2012 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.
// exec-env:RUST_NEWRT=1
// error-pattern:fail
use std::vec;
use std::collections;
use std::gc::GC;
fn main() {
let _count = box(GC) 0u;
let mut map = collections::HashMap::new();
let mut arr = Vec::new();
for _i in range(0u, 10u) {
arr.push(box(GC) "key stuff".to_string());
map.insert(arr.clone(),
arr.clone().append([box(GC) "value stuff".to_string()]));
if arr.len() == 5 {
fail!();
}
}
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::{Gc, GC};
fn f(_a: Gc<int>) {
fail!();
}
fn main() {
let a = box(GC) 0;
f(a);
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn main() {
let _a = box(GC) 0i;
{
let _b = box(GC) 0i;
{
fail!();
}
}
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn f() -> Vec<int> { fail!(); }
// Voodoo. In unwind-alt we had to do this to trigger the bug. Might
// have been to do with memory allocation patterns.
fn prime() {
box(GC) 0i;
}
fn partial() {
let _x = box(GC) f();
}
fn main() {
prime();
partial();
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn f() -> Vec<int> { fail!(); }
// Voodoo. In unwind-alt we had to do this to trigger the bug. Might
// have been to do with memory allocation patterns.
fn prime() {
box(GC) 0i;
}
fn partial() {
let _x = box f();
}
fn main() {
prime();
partial();
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn f() -> Vec<int> { fail!(); }
// Voodoo. In unwind-alt we had to do this to trigger the bug. Might
// have been to do with memory allocation patterns.
fn prime() {
box(GC) 0i;
}
fn partial() {
let _x = vec!(vec!(0i), f(), vec!(0i));
}
fn main() {
prime();
partial();
}
// Copyright 2012 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.
// error-pattern:squirrel
use std::gc::GC;
struct r {
i: int,
}
impl Drop for r {
fn drop(&mut self) { fail!("squirrel") }
}
fn r(i: int) -> r { r { i: i } }
fn main() {
box(GC) 0i;
let _r = r(0);
}
// Copyright 2012-2014 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.
// ignore-test leaks
// error-pattern:wombat
use std::gc::GC;
struct r {
i: int,
}
impl Drop for r {
fn drop(&mut self) { fail!("wombat") }
}
fn r(i: int) -> r { r { i: i } }
fn main() {
box(GC) 0;
let r = r(0);
fail!();
}
// Copyright 2012 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.
#![feature(unsafe_destructor)]
// error-pattern:quux
use std::gc::{Gc, GC};
struct faily_box {
i: Gc<int>
}
// What happens to the box pointer owned by this class?
fn faily_box(i: Gc<int>) -> faily_box { faily_box { i: i } }
#[unsafe_destructor]
impl Drop for faily_box {
fn drop(&mut self) {
fail!("quux");
}
}
fn main() {
faily_box(box(GC) 10);
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn f() {
let _a = box(GC) 0i;
fail!();
}
fn g() {
let _b = box(GC) 0i;
f();
}
fn main() {
let _a = box(GC) 0i;
g();
}
// Copyright 2012 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.
use std::gc::Gc;
// error-pattern:fail
fn fold_local() -> Gc<Vec<int>> {
fail!();
}
fn main() {
let _lss = (fold_local(), 0i);
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
// error-pattern:fail
fn fold_local() -> Gc<Vec<int>> {
box(GC) vec!(0,0,0,0,0,0)
}
fn fold_remote() -> Gc<Vec<int>> {
fail!();
}
fn main() {
let _lss = (fold_local(), fold_remote());
}
// Copyright 2012 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.
// error-pattern:fail
use std::gc::GC;
fn f() {
fail!();
}
fn main() {
f();
let _a = box(GC) 0i;
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
#[deriving(PartialEq, Show)]
struct Point { x : int }
......@@ -19,5 +17,4 @@ pub fn main() {
assert_eq!("abc".to_string(),"abc".to_string());
assert_eq!(box Point{x:34},box Point{x:34});
assert_eq!(&Point{x:34},&Point{x:34});
assert_eq!(box(GC) Point{x:34},box(GC) Point{x:34});
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::{GC, Gc};
trait double {
fn double(self) -> uint;
}
......@@ -19,11 +17,11 @@ impl double for uint {
fn double(self) -> uint { self }
}
impl double for Gc<uint> {
impl double for Box<uint> {
fn double(self) -> uint { *self * 2u }
}
pub fn main() {
let x = box(GC) 3u;
let x = box 3u;
assert_eq!(x.double(), 6u);
}
......@@ -9,15 +9,13 @@
// except according to those terms.
use std::gc::{Gc, GC};
trait Foo {
fn foo(&self) -> String;
}
impl<T:Foo> Foo for Gc<T> {
impl<T:Foo> Foo for Box<T> {
fn foo(&self) -> String {
format!("box(GC) {}", (**self).foo())
format!("box {}", (**self).foo())
}
}
......@@ -28,6 +26,6 @@ fn foo(&self) -> String {
}
pub fn main() {
let x = box(GC) 3u;
assert_eq!(x.foo(), "box(GC) 3".to_string());
let x = box 3u;
assert_eq!(x.foo(), "box 3".to_string());
}
......@@ -10,9 +10,6 @@
// Binop corner cases
use std::gc::GC;
fn test_nil() {
assert_eq!((), ());
assert!((!(() != ())));
......@@ -45,10 +42,6 @@ fn test_bool() {
assert_eq!(true ^ true, false);
}
fn test_box() {
assert_eq!(box(GC) 10i, box(GC) 10i);
}
fn test_ptr() {
unsafe {
let p1: *const u8 = ::std::mem::transmute(0u);
......@@ -98,7 +91,6 @@ fn test_class() {
pub fn main() {
test_nil();
test_bool();
test_box();
test_ptr();
test_class();
}
......@@ -9,13 +9,11 @@
// except according to those terms.
use std::gc::{Gc, GC};
fn borrow(x: &int, f: |x: &int|) {
f(x)
}
fn test1(x: Gc<Box<int>>) {
fn test1(x: &Box<int>) {
borrow(&*(*x).clone(), |p| {
let x_a = &**x as *const int;
assert!((x_a as uint) != (p as *const int as uint));
......@@ -24,5 +22,5 @@ fn test1(x: Gc<Box<int>>) {
}
pub fn main() {
test1(box(GC) box 22);
test1(&box 22);
}
// Copyright 2014 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.
// exec-env:RUST_POISON_ON_FREE=1
// Test that we root `x` even though it is found in immutable memory,
// because it is moved.
use std::gc::{Gc, GC};
fn free<T>(x: Gc<T>) {}
struct Foo {
f: Gc<Bar>
}
struct Bar {
g: int
}
fn lend(x: Gc<Foo>) -> int {
let y = &x.f.g;
free(x); // specifically here, if x is not rooted, it will be freed
*y
}
pub fn main() {
assert_eq!(lend(box(GC) Foo {f: box(GC) Bar {g: 22}}), 22);
}
// Copyright 2012 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.
use std::gc::{GC, Gc};
struct F { f: Gc<G> }
struct G { g: Vec<int> }
pub fn main() {
let rec = box(GC) F {f: box(GC) G {g: vec!(1, 2, 3)}};
while rec.f.g.len() == 23 {}
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
fn borrow<'r,T>(x: &'r T) -> &'r T {x}
struct Rec { f: Gc<int> }
pub fn main() {
let rec = box(GC) Rec {f: box(GC) 22};
while *borrow(&*rec.f) == 23 {}
}
......@@ -10,7 +10,6 @@
use std::cell::Cell;
use std::gc::GC;
enum newtype {
newvar(int)
......@@ -21,8 +20,8 @@ pub fn main() {
// Test that borrowck treats enums with a single variant
// specially.
let x = box(GC) Cell::new(5);
let y = box(GC) Cell::new(newvar(3));
let x = &Cell::new(5);
let y = &Cell::new(newvar(3));
let z = match y.get() {
newvar(b) => {
x.set(x.get() + 1);
......
// Copyright 2012 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.
use std::gc::GC;
pub fn main() {
assert!((box(GC) 1i < box(GC) 3i));
assert!((box(GC) box(GC) "hello ".to_string() >
box(GC) box(GC) "hello".to_string()));
assert!((box(GC) box(GC) box(GC) "hello".to_string() !=
box(GC) box(GC) box(GC) "there".to_string()));
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
pub fn main() {
let i: (Gc<int>, int) = (box(GC) 10, 10);
let (_a, _) = i;
}
// Copyright 2012 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.
use std::gc::{GC, Gc};
fn some_box(x: int) -> Gc<int> { return box(GC) x; }
fn is_odd(_n: int) -> bool { return true; }
fn length_is_even(_vs: Gc<int>) -> bool { return true; }
fn foo(_acc: int, n: int) {
if is_odd(n) && length_is_even(some_box(1)) { println!("bloop"); }
}
pub fn main() { foo(67, 5); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
fn some_box(x: int) -> Gc<int> { return box(GC) x; }
fn is_odd(_n: int) -> bool { return true; }
fn length_is_even(_vs: Gc<int>) -> bool { return true; }
fn foo(_acc: int, n: int) {
if is_odd(n) || length_is_even(some_box(1)) { println!("bloop"); }
}
pub fn main() { foo(67, 5); }
// Copyright 2012 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.
fn main() {
let box x = box 3i;
match box 3i {
box y => {
assert!(x == y);
println!("{} {}", x, y);
}
}
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
struct Box<T> {c: Gc<T>}
fn unbox<T:Clone>(b: Box<T>) -> T { return (*b.c).clone(); }
pub fn main() {
let foo: int = 17;
let bfoo: Box<int> = Box {c: box(GC) foo};
println!("see what's in our box");
assert_eq!(unbox::<int>(bfoo), foo);
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
pub fn main() { let x: Gc<int> = box(GC) 10; assert!((*x == 10)); }
// Copyright 2012 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.
// Regression test that rustc doesn't recurse infinitely substituting
// the boxed type parameter
use std::gc::Gc;
struct Tree<T> {
parent: Option<T>
}
fn empty<T>() -> Tree<T> { fail!() }
struct Box {
tree: Tree<Gc<Box>>
}
fn Box() -> Box {
Box {
tree: empty()
}
}
struct LayoutData {
a_box: Option<Gc<Box>>
}
pub fn main() { }
......@@ -13,10 +13,9 @@
extern crate cci_borrow_lib;
use cci_borrow_lib::foo;
use std::gc::GC;
pub fn main() {
let p = box(GC) 22u;
let p = box 22u;
let r = foo(&*p);
println!("r={}", r);
assert_eq!(r, 22u);
......
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::Gc;
struct kitten {
cat: Option<cat>,
}
......@@ -21,6 +19,6 @@ fn kitten(cat: Option<cat>) -> kitten {
}
}
type cat = Gc<kitten>;
type cat = Box<kitten>;
pub fn main() {}
// Copyright 2012 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.
use std::task;
use std::gc::{GC, Gc};
fn adder(x: Gc<int>, y: Gc<int>) -> int { return *x + *y; }
fn failer() -> Gc<int> { fail!(); }
pub fn main() {
assert!(task::try(proc() {
adder(box(GC) 2, failer()); ()
}).is_err());
}
......@@ -17,12 +17,10 @@
extern crate crate_method_reexport_grrrrrrr2;
use std::gc::GC;
pub fn main() {
use crate_method_reexport_grrrrrrr2::rust::add;
use crate_method_reexport_grrrrrrr2::rust::cx;
let x = box(GC) ();
let x = box() ();
x.cx();
let y = ();
y.add("hi".to_string());
......
// Copyright 2012 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.
use std::cell::RefCell;
use std::gc::{Gc, GC};
enum taggy {
cons(Gc<RefCell<taggy>>),
nil,
}
fn f() {
let a_box = box(GC) RefCell::new(nil);
*a_box.borrow_mut() = cons(a_box);
}
pub fn main() {
f();
}
......@@ -9,13 +9,10 @@
// except according to those terms.
extern crate debug;
use std::cell::Cell;
use std::gc::GC;
pub fn main() {
let x = box(GC) Cell::new(5i);
let x = box Cell::new(5i);
x.set(1000i);
println!("{:?}", x.get());
println!("{}", x.get());
}
......@@ -9,9 +9,7 @@
// except according to those terms.
use std::gc::{Gc, GC};
pub fn main() {
let x: Gc<int> = box(GC) 10;
let x: Box<int> = box 10;
let _y: int = *x;
}
// Copyright 2012 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.
use std::gc::Gc;
struct Quux {
bar: int
}
fn g(_i: int) { }
fn f(foo: Gc<Gc<Quux>>) { g(foo.bar); }
pub fn main() { }
......@@ -9,11 +9,9 @@
// except according to those terms.
use std::gc::{Gc, GC};
enum t { foo(Gc<int>), }
enum t { foo(Box<int>), }
pub fn main() {
let tt = foo(box(GC) 10);
let tt = foo(box 10);
match tt { foo(_z) => { } }
}
......@@ -9,7 +9,6 @@
// except according to those terms.
use std::gc::Gc;
use std::mem::size_of;
trait Trait {}
......@@ -33,9 +32,8 @@ fn main() {
assert_eq!(size_of::<&Trait>(), size_of::<Option<&Trait>>());
assert_eq!(size_of::<&mut Trait>(), size_of::<Option<&mut Trait>>());
// Pointers - Box<T> / Gc<T>
// Pointers - Box<T>
assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
assert_eq!(size_of::<Gc<int>>(), size_of::<Option<Gc<int>>>());
// The optimization can't apply to raw pointers
......
......@@ -15,11 +15,9 @@
* represented with nullable pointers could be misoptimized in some cases.
*/
use std::gc::{Gc, GC};
enum List<X> { Nil, Cons(X, Gc<List<X>>) }
enum List<X> { Nil, Cons(X, Box<List<X>>) }
pub fn main() {
match Cons(10i, box(GC) Nil) {
match Cons(10i, box Nil) {
Cons(10i, _) => {}
Nil => {}
_ => fail!()
......
// Copyright 2012 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.
#![allow(dead_assignment)]
use std::gc::{Gc, GC};
pub fn main() {
let x : [Gc<int>, ..5] = [box(GC) 1,box(GC) 2,box(GC) 3,box(GC) 4,box(GC) 5];
let _y : [Gc<int>, ..5] = [box(GC) 1,box(GC) 2,box(GC) 3,box(GC) 4,box(GC) 5];
let mut z = [box(GC) 1,box(GC) 2,box(GC) 3,box(GC) 4,box(GC) 5];
z = x;
assert_eq!(*z[0], 1);
assert_eq!(*z[4], 5);
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::Gc;
enum list_cell<T> { cons(Gc<list_cell<T>>), nil }
enum list_cell<T> { cons(Box<list_cell<T>>), nil }
pub fn main() { }
// Copyright 2012 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.
use std::gc::GC;
pub fn main() { let x = { box(GC) 100i }; assert!((*x == 100)); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
type compare<T> = |Gc<T>, Gc<T>|: 'static -> bool;
fn test_generic<T>(expected: Gc<T>, eq: compare<T>) {
let actual: Gc<T> = { expected };
assert!((eq(expected, actual)));
}
fn test_box() {
fn compare_box(b1: Gc<bool>, b2: Gc<bool>) -> bool {
println!("{}", *b1);
println!("{}", *b2);
return *b1 == *b2;
}
test_generic::<bool>(box(GC) true, compare_box);
}
pub fn main() { test_box(); }
// Copyright 2012-2014 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.
use std::gc::{GC, Gc};
type compare<'a, T> = |T, T|: 'a -> bool;
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
let actual: T = { expected.clone() };
assert!((eq(expected, actual)));
}
fn test_vec() {
fn compare_vec(v1: Gc<int>, v2: Gc<int>) -> bool { return v1 == v2; }
test_generic::<Gc<int>>(box(GC) 1, compare_vec);
}
pub fn main() { test_vec(); }
// Copyright 2012 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.
use std::gc::GC;
// Regression test for issue #388
pub fn main() { let _x = { { box(GC) 10i } }; }
// Copyright 2012 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.
use std::gc::{Gc, GC};
// Make sure we drop the refs of the temporaries needed to return the
// values from the else if branch
pub fn main() {
let y: Gc<uint> = box(GC) 10u;
let _x = if false { y } else if true { y } else { y };
assert_eq!(*y, 10u);
}
// Copyright 2012 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.
use std::gc::{GC};
// Regression test for issue #388
pub fn main() {
let _x = if false {
box(GC) 0u
} else if true {
box(GC) 10u
} else {
box(GC) 0u
};
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
// Tests for if as expressions returning boxed types
fn test_box() {
let rs = if true { box(GC) 100i } else { box(GC) 101i };
assert_eq!(*rs, 100);
}
fn test_str() {
let rs = if true { "happy".to_string() } else { "sad".to_string() };
assert_eq!(rs, "happy".to_string());
}
pub fn main() { test_box(); test_str(); }
// Copyright 2012 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.
use std::gc::{GC, Gc};
type compare<T> = |Gc<T>, Gc<T>|: 'static -> bool;
fn test_generic<T>(expected: Gc<T>, not_expected: Gc<T>, eq: compare<T>) {
let actual: Gc<T> = if true { expected } else { not_expected };
assert!((eq(expected, actual)));
}
fn test_box() {
fn compare_box(b1: Gc<bool>, b2: Gc<bool>) -> bool { return *b1 == *b2; }
test_generic::<bool>(box(GC) true, box(GC) false, compare_box);
}
pub fn main() { test_box(); }
// Copyright 2012-2014 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.
use std::gc::{Gc, GC};
type compare<T> = |T, T|: 'static -> bool;
fn test_generic<T:Clone>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected.clone() } else { not_expected };
assert!((eq(expected, actual)));
}
fn test_vec() {
fn compare_box(v1: Gc<int>, v2: Gc<int>) -> bool { return v1 == v2; }
test_generic::<Gc<int>>(box(GC) 1, box(GC) 2, compare_box);
}
pub fn main() { test_vec(); }
// Copyright 2012 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.
use std::gc::GC;
// Tests for match as expressions resulting in boxed types
fn test_box() {
let res = match true { true => { box(GC) 100i } _ => fail!("wat") };
assert_eq!(*res, 100i);
}
fn test_str() {
let res = match true { true => { "happy".to_string() },
_ => fail!("not happy at all") };
assert_eq!(res, "happy".to_string());
}
pub fn main() { test_box(); test_str(); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
type compare<T> = |Gc<T>, Gc<T>|: 'static -> bool;
fn test_generic<T>(expected: Gc<T>, eq: compare<T>) {
let actual: Gc<T> = match true { true => { expected }, _ => fail!() };
assert!((eq(expected, actual)));
}
fn test_box() {
fn compare_box(b1: Gc<bool>, b2: Gc<bool>) -> bool { return *b1 == *b2; }
test_generic::<bool>(box(GC) true, compare_box);
}
pub fn main() { test_box(); }
// Copyright 2012-2014 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.
use std::gc::{Gc, GC};
type compare<T> = |T, T|: 'static -> bool;
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") };
assert!((eq(expected, actual)));
}
fn test_vec() {
fn compare_box(v1: Gc<int>, v2: Gc<int>) -> bool { return v1 == v2; }
test_generic::<Gc<int>>(box(GC) 1, compare_box);
}
pub fn main() { test_vec(); }
......@@ -10,11 +10,10 @@
use std::cell::Cell;
use std::gc::{Gc, GC};
struct Point {x: int, y: int, z: int}
fn f(p: Gc<Cell<Point>>) {
fn f(p: &Cell<Point>) {
assert!((p.get().z == 12));
p.set(Point {x: 10, y: 11, z: 13});
assert!((p.get().z == 13));
......@@ -22,7 +21,7 @@ fn f(p: Gc<Cell<Point>>) {
pub fn main() {
let a: Point = Point {x: 10, y: 11, z: 12};
let b: Gc<Cell<Point>> = box(GC) Cell::new(a);
let b: &Cell<Point> = &Cell::new(a);
assert_eq!(b.get().z, 12);
f(b);
assert_eq!(a.z, 12);
......
......@@ -9,45 +9,25 @@
// except according to those terms.
use std::task;
use std::gc::{GC, Gc};
use std::cell::RefCell;
static mut DROPS: uint = 0;
struct Foo(bool);
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
let Foo(fail) = *self;
unsafe { DROPS += 1; }
if fail { fail!() }
fail!()
}
}
fn tld_fail(fail: bool) {
local_data_key!(foo: Foo);
foo.replace(Some(Foo(fail)));
}
fn gc_fail(fail: bool) {
struct A {
inner: RefCell<Option<Gc<A>>>,
other: Foo,
}
let a = box(GC) A {
inner: RefCell::new(None),
other: Foo(fail),
};
*a.inner.borrow_mut() = Some(a.clone());
}
fn main() {
let _ = task::try(proc() {
tld_fail(true);
gc_fail(false);
local_data_key!(foo: Foo);
foo.replace(Some(Foo));
});
unsafe {
assert_eq!(DROPS, 2);
assert_eq!(DROPS, 1);
}
}
// Copyright 2014 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.
use std::gc::{GC};
fn main() {
// A fixed-size array allocated in a garbage-collected box
let x = box(GC) [1i, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(x[0], 1);
assert_eq!(x[6], 7);
assert_eq!(x[9], 10);
let y = x;
assert!(*y == [1i, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
}
// Copyright 2012 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.
extern crate debug;
use std::gc::{Gc, GC};
fn id<T>(t: T) -> T { return t; }
pub fn main() {
let expected = box(GC) 100;
let actual = id::<Gc<int>>(expected);
println!("{:?}", *actual);
assert_eq!(*expected, *actual);
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
fn box_it<T:'static>(x: Box<T>) -> Gc<Box<T>> { return box(GC) x; }
struct Box<T> {x: T, y: T, z: T}
pub fn main() {
let x: Gc<Box<int>> = box_it::<int>(Box{x: 1, y: 2, z: 3});
assert_eq!(x.y, 2);
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
struct Pair { x: Gc<int>, y: Gc<int> }
fn f<T>(t: T) { let _t1: T = t; }
pub fn main() { let x = Pair {x: box(GC) 10, y: box(GC) 12}; f(x); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
struct Recbox<T> {x: Gc<T>}
fn reclift<T:'static>(t: T) -> Recbox<T> { return Recbox {x: box(GC) t}; }
pub fn main() {
let foo: int = 17;
let rbfoo: Recbox<int> = reclift::<int>(foo);
assert_eq!(*rbfoo.x, foo);
}
// Copyright 2012 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.
extern crate debug;
use std::gc::{Gc, GC};
fn f<T>(x: Gc<T>) -> Gc<T> { return x; }
pub fn main() { let x = f(box(GC) 3i); println!("{:?}", *x); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
fn f<T>(_v: Gc<T>) { }
pub fn main() { f(box(GC) vec!(1i, 2, 3, 4, 5)); }
......@@ -11,14 +11,12 @@
// ignore-pretty FIXME(#14193)
use std::gc::{Gc, GC};
enum list<T> { cons(Gc<T>, Gc<list<T>>), nil, }
enum list<T> { cons(Box<T>, Box<list<T>>), nil, }
pub fn main() {
let _a: list<int> =
cons::<int>(box(GC) 10,
box(GC) cons::<int>(box(GC) 12,
box(GC) cons::<int>(box(GC) 13,
box(GC) nil::<int>)));
cons::<int>(box 10,
box cons::<int>(box 12,
box cons::<int>(box 13,
box nil::<int>)));
}
......@@ -11,11 +11,9 @@
#![allow(dead_assignment)]
#![allow(unused_variable)]
use std::gc::{Gc, GC};
enum option<T> { some(Gc<T>), none, }
enum option<T> { some(Box<T>), none, }
pub fn main() {
let mut a: option<int> = some::<int>(box(GC) 10);
let mut a: option<int> = some::<int>(box 10);
a = none::<int>;
}
......@@ -18,7 +18,6 @@
extern crate debug;
use std::fmt;
use std::gc::GC;
use std::io::MemWriter;
use std::io;
use std::str;
......@@ -50,7 +49,6 @@ pub fn main() {
t!(format!("{:?}", 1i), "1");
t!(format!("{:?}", A), "A");
t!(format!("{:?}", ()), "()");
t!(format!("{:?}", box(GC) (box 1i, "foo")), "box(GC) (box 1, \"foo\")");
// Various edge cases without formats
t!(format!(""), "");
......
......@@ -11,52 +11,43 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{Gc, GC};
// Resources can't be copied, but storing into data structures counts
// as a move unless the stored thing is used afterwards.
struct r {
i: Gc<Cell<int>>,
struct r<'a> {
i: &'a Cell<int>,
}
struct Box { x: r }
struct BoxR<'a> { x: r<'a> }
#[unsafe_destructor]
impl Drop for r {
impl<'a> Drop for r<'a> {
fn drop(&mut self) {
self.i.set(self.i.get() + 1)
}
}
fn r(i: Gc<Cell<int>>) -> r {
fn r(i: &Cell<int>) -> r {
r {
i: i
}
}
fn test_box() {
let i = box(GC) Cell::new(0i);
{
let _a = box(GC) r(i);
}
assert_eq!(i.get(), 1);
}
fn test_rec() {
let i = box(GC) Cell::new(0i);
let i = &Cell::new(0i);
{
let _a = Box {x: r(i)};
let _a = BoxR {x: r(i)};
}
assert_eq!(i.get(), 1);
}
fn test_tag() {
enum t {
t0(r),
enum t<'a> {
t0(r<'a>),
}
let i = box(GC) Cell::new(0i);
let i = &Cell::new(0i);
{
let _a = t0(r(i));
}
......@@ -64,7 +55,7 @@ enum t {
}
fn test_tup() {
let i = box(GC) Cell::new(0i);
let i = &Cell::new(0i);
{
let _a = (r(i), 0i);
}
......@@ -72,17 +63,17 @@ fn test_tup() {
}
fn test_unique() {
let i = box(GC) Cell::new(0i);
let i = &Cell::new(0i);
{
let _a = box r(i);
}
assert_eq!(i.get(), 1);
}
fn test_box_rec() {
let i = box(GC) Cell::new(0i);
fn test_unique_rec() {
let i = &Cell::new(0i);
{
let _a = box(GC) Box {
let _a = box BoxR {
x: r(i)
};
}
......@@ -90,10 +81,9 @@ fn test_box_rec() {
}
pub fn main() {
test_box();
test_rec();
test_tag();
test_tup();
test_unique();
test_box_rec();
test_unique_rec();
}
......@@ -8,21 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(globs)]
#![allow(unused_imports, dead_code)]
use foo::GC;
use foo::Foo;
mod foo {
pub use m::GC; // this should shadow d::GC
pub use m::Foo; // this should shadow d::Foo
}
mod m {
pub struct GC;
pub struct Foo;
}
mod d {
pub struct GC;
pub struct Foo;
}
fn main() {}
......@@ -11,17 +11,16 @@
// aux-build:issue-2631-a.rs
extern crate collections;
extern crate req;
use req::request;
use std::cell::RefCell;
use std::collections::HashMap;
use std::gc::GC;
use std::rc::Rc;
pub fn main() {
let v = vec!(box(GC) "hi".to_string());
let v = vec!(Rc::new("hi".to_string()));
let mut m: req::header_map = HashMap::new();
m.insert("METHOD".to_string(), box(GC) RefCell::new(v));
m.insert("METHOD".to_string(), Rc::new(RefCell::new(v)));
request::<int>(&m);
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
struct Font {
fontbuf: uint,
cairo_font: uint,
......@@ -31,5 +29,5 @@ fn Font() -> Font {
}
pub fn main() {
let _f = box(GC) Font();
let _f = box Font();
}
......@@ -11,28 +11,27 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{Gc, GC};
// This test should behave exactly like issue-2735-3
struct defer {
b: Gc<Cell<bool>>,
struct defer<'a> {
b: &'a Cell<bool>,
}
#[unsafe_destructor]
impl Drop for defer {
impl<'a> Drop for defer<'a> {
fn drop(&mut self) {
self.b.set(true);
}
}
fn defer(b: Gc<Cell<bool>>) -> defer {
fn defer(b: &Cell<bool>) -> defer {
defer {
b: b
}
}
pub fn main() {
let dtor_ran = box(GC) Cell::new(false);
let dtor_ran = &Cell::new(false);
let _ = defer(dtor_ran);
assert!(dtor_ran.get());
}
......@@ -11,28 +11,27 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{Gc, GC};
// This test should behave exactly like issue-2735-2
struct defer {
b: Gc<Cell<bool>>,
struct defer<'a> {
b: &'a Cell<bool>,
}
#[unsafe_destructor]
impl Drop for defer {
impl<'a> Drop for defer<'a> {
fn drop(&mut self) {
self.b.set(true);
}
}
fn defer(b: Gc<Cell<bool>>) -> defer {
fn defer(b: &Cell<bool>) -> defer {
defer {
b: b
}
}
pub fn main() {
let dtor_ran = box(GC) Cell::new(false);
let dtor_ran = &Cell::new(false);
defer(dtor_ran);
assert!(dtor_ran.get());
}
......@@ -14,10 +14,9 @@
extern crate socketlib;
extern crate libc;
use std::gc::GC;
use socketlib::socket;
pub fn main() {
let fd: libc::c_int = 1 as libc::c_int;
let _sock = box(GC) socket::socket_handle(fd);
let _sock = box socket::socket_handle(fd);
}
......@@ -9,13 +9,11 @@
// except according to those terms.
use std::gc::{Gc, GC};
enum side { mayo, catsup, vinegar }
enum order { hamburger, fries(side), shake }
enum meal { to_go(order), for_here(order) }
fn foo(m: Gc<meal>, cond: bool) {
fn foo(m: Box<meal>, cond: bool) {
match *m {
to_go(_) => { }
for_here(_) if cond => {}
......@@ -26,5 +24,5 @@ fn foo(m: Gc<meal>, cond: bool) {
}
pub fn main() {
foo(box(GC) for_here(hamburger), true)
foo(box for_here(hamburger), true)
}
......@@ -10,13 +10,12 @@
use std::cell::RefCell;
use std::gc::{Gc, GC};
static S: &'static str = "str";
struct list<T> {
element: T,
next: Option<Gc<RefCell<list<T>>>>
next: Option<Box<RefCell<list<T>>>>
}
impl<T:'static> list<T> {
......@@ -26,7 +25,7 @@ pub fn addEnd(&mut self, element: T) {
next: None
};
self.next = Some(box(GC) RefCell::new(newList));
self.next = Some(box RefCell::new(newList));
}
}
......
......@@ -9,18 +9,15 @@
// except according to those terms.
extern crate debug;
use std::gc::{Gc, GC};
#[deriving(Show)]
enum Token {
Text(Gc<String>),
ETag(Gc<Vec<String>> , Gc<String>),
UTag(Gc<Vec<String>> , Gc<String>),
Section(Gc<Vec<String>> , bool, Gc<Vec<Token>>, Gc<String>,
Gc<String>, Gc<String>, Gc<String>, Gc<String>),
IncompleteSection(Gc<Vec<String>> , bool, Gc<String>, bool),
Partial(Gc<String>, Gc<String>, Gc<String>),
Text(String),
ETag(Vec<String>, String),
UTag(Vec<String>, String),
Section(Vec<String>, bool, Vec<Token>, String,
String, String, String, String),
IncompleteSection(Vec<String>, bool, String, bool),
Partial(String, String, String),
}
fn check_strs(actual: &str, expected: &str) -> bool
......@@ -39,13 +36,13 @@ pub fn main()
// assert!(check_strs(fmt!("%?", ETag(@~["foo".to_string()], @"bar".to_string())),
// "ETag(@~[ ~\"foo\" ], @~\"bar\")"));
let t = Text(box(GC) "foo".to_string());
let u = Section(box(GC) vec!("alpha".to_string()),
true,
box(GC) vec!(t),
box(GC) "foo".to_string(),
box(GC) "foo".to_string(), box(GC) "foo".to_string(), box(GC) "foo".to_string(),
box(GC) "foo".to_string());
let v = format!("{:?}", u); // this is the line that causes the seg fault
let t = Text("foo".to_string());
let u = Section(vec!["alpha".to_string()],
true,
vec![t],
"foo".to_string(),
"foo".to_string(), "foo".to_string(), "foo".to_string(),
"foo".to_string());
let v = format!("{}", u); // this is the line that causes the seg fault
assert!(v.len() > 0);
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::Gc;
pub struct Foo {
a: int,
}
......@@ -20,7 +18,7 @@ struct Bar<'a> {
b: &'a Foo,
}
fn check(a: Gc<Foo>) {
fn check(a: Box<Foo>) {
let _ic = Bar{ b: &*a, a: box None };
}
......
......@@ -9,12 +9,10 @@
// except according to those terms.
use std::gc::GC;
enum Either<T, U> { Left(T), Right(U) }
pub fn main() {
match Left(box(GC) 17i) {
match Left(box 17i) {
Right(()) => {}
_ => {}
}
......
......@@ -12,8 +12,6 @@
extern crate debug;
use std::gc::GC;
fn assert_repr_eq<T>(obj : T, expected : String) {
assert_eq!(expected, format!("{:?}", obj));
}
......@@ -23,12 +21,10 @@ pub fn main() {
let tf = [true, false];
let x = [(), ()];
let slice = x[0..1];
let z = box(GC) x;
assert_repr_eq(abc, "[1, 2, 3]".to_string());
assert_repr_eq(tf, "[true, false]".to_string());
assert_repr_eq(x, "[(), ()]".to_string());
assert_repr_eq(slice, "&[()]".to_string());
assert_repr_eq(&x, "&[(), ()]".to_string());
assert_repr_eq(z, "box(GC) [(), ()]".to_string());
}
// Copyright 2014 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.
use std::gc::GC;
fn main() {
fn f(_: proc()) {}
fn eat<T>(_: T) {}
let x = box(GC) 1i;
f(proc() { eat(x) });
}
......@@ -11,27 +11,26 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{GC, Gc};
struct r {
b: Gc<Cell<int>>,
struct r<'a> {
b: &'a Cell<int>,
}
#[unsafe_destructor]
impl Drop for r {
impl<'a> Drop for r<'a> {
fn drop(&mut self) {
self.b.set(self.b.get() + 1);
}
}
fn r(b: Gc<Cell<int>>) -> r {
fn r(b: &Cell<int>) -> r {
r {
b: b
}
}
pub fn main() {
let b = box(GC) Cell::new(0);
let b = &Cell::new(0);
{
let _p = Some(r(b));
}
......
// Copyright 2012 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.
use std::cell::RefCell;
use std::gc::{Gc, GC};
enum maybe_pointy {
no_pointy,
yes_pointy(Gc<RefCell<Pointy>>),
}
struct Pointy {
x: maybe_pointy
}
pub fn main() {
let m = box(GC) RefCell::new(Pointy { x : no_pointy });
*m.borrow_mut() = Pointy {
x: yes_pointy(m)
};
}
// Copyright 2012 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.
use std::gc::{Gc, GC};
fn leaky<T>(_t: T) { }
pub fn main() { let x = box(GC) 10; leaky::<Gc<int>>(x); }
// Copyright 2012 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.
#![allow(dead_assignment)]
#![allow(unused_variable)]
use std::gc::{Gc, GC};
enum t { a, b(Gc<int>), }
pub fn main() { let mut x = b(box(GC) 10); x = a; }
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::{Gc, GC};
enum list { cons(int, Box<list>), nil, }
enum list { cons(int, Gc<list>), nil, }
pub fn main() { cons(10, box(GC) cons(11, box(GC) cons(12, box(GC) nil))); }
pub fn main() { cons(10, box cons(11, box cons(12, box nil))); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
enum mlist { cons(int, Gc<mlist>), nil, }
pub fn main() { cons(10, box(GC) cons(11, box(GC) cons(12, box(GC) nil))); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
struct Triple { x: int, y: int, z: int }
fn test(x: bool, foo: Gc<Triple>) -> int {
let bar = foo;
let mut y: Gc<Triple>;
y = bar;
if x { y = bar; } else { y = box(GC) Triple{x: 4, y: 5, z: 6}; }
return y.y;
}
pub fn main() {
let x = box(GC) Triple {x: 1, y: 2, z: 3};
assert_eq!(test(true, x), 2);
assert_eq!(test(true, x), 2);
assert_eq!(test(true, x), 2);
assert_eq!(test(false, x), 5);
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
struct X { x: int, y: int, z: int }
pub fn main() { let x = box(GC) X {x: 1, y: 2, z: 3}; let y = x; assert!((y.y == 2)); }
pub fn main() { let x = box X {x: 1, y: 2, z: 3}; let y = x; assert!((y.y == 2)); }
// Copyright 2012 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.
use std::gc::{Gc, GC};
struct Triple { x: int, y: int, z: int }
fn test(x: bool, foo: Gc<Triple>) -> int {
let bar = foo;
let mut y: Gc<Triple>;
if x { y = bar; } else { y = box(GC) Triple{x: 4, y: 5, z: 6}; }
return y.y;
}
pub fn main() {
let x = box(GC) Triple{x: 1, y: 2, z: 3};
for _i in range(0u, 10000u) {
assert_eq!(test(true, x), 2);
}
assert_eq!(test(false, x), 5);
}
......@@ -9,11 +9,9 @@
// except according to those terms.
use std::gc::{GC, Gc};
struct Triple { a: int, b: int, c: int }
fn test(foo: Gc<Triple>) -> Gc<Triple> {
fn test(foo: Box<Triple>) -> Box<Triple> {
let foo = foo;
let bar = foo;
let baz = bar;
......@@ -22,7 +20,7 @@ fn test(foo: Gc<Triple>) -> Gc<Triple> {
}
pub fn main() {
let x = box(GC) Triple{a: 1, b: 2, c: 3};
let x = box Triple{a: 1, b: 2, c: 3};
let y = test(x);
assert_eq!(y.c, 3);
}
......@@ -9,15 +9,13 @@
// except according to those terms.
use std::gc::{Gc, GC};
fn test(foo: Gc<Vec<int>>) { assert!((*foo.get(0) == 10)); }
fn test(foo: Box<Vec<int>>) { assert!((*foo.get(0) == 10)); }
pub fn main() {
let x = box(GC) vec!(10);
let x = box vec!(10);
// Test forgetting a local by move-in
test(x);
// Test forgetting a temporary by move-in.
test(box(GC) vec!(10));
test(box vec!(10));
}
// Copyright 2012 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.
#![allow(unused_mut)]
use std::gc::{Gc, GC};
struct Pair { a: int, b: int}
pub fn main() {
// This just tests whether the vec leaks its members.
let mut _pvec: Vec<Gc<Pair>> =
vec!(box(GC) Pair{a: 1, b: 2},
box(GC) Pair{a: 3, b: 4},
box(GC) Pair{a: 5, b: 6});
}
......@@ -9,14 +9,12 @@
// except according to those terms.
use std::gc::Gc;
enum colour { red, green, blue, }
enum tree { children(Gc<list>), leaf(colour), }
enum tree { children(Box<list>), leaf(colour), }
enum list { cons(Gc<tree>, Gc<list>), nil, }
enum list { cons(Box<tree>, Box<list>), nil, }
enum small_list { kons(int, Gc<small_list>), neel, }
enum small_list { kons(int, Box<small_list>), neel, }
pub fn main() { }
......@@ -11,9 +11,8 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the new `box` syntax works with unique pointers and GC pointers.
// Tests that the new `box` syntax works with unique pointers.
use std::gc::{Gc, GC};
use std::boxed::{Box, HEAP};
struct Structure {
......@@ -24,12 +23,6 @@ struct Structure {
pub fn main() {
let x: Box<int> = box(HEAP) 2i;
let y: Box<int> = box 2i;
let z: Gc<int> = box(GC) 2i;
let a: Gc<Structure> = box(GC) Structure {
x: 10,
y: 20,
};
let b: Box<int> = box()(1i + 2);
let c = box()(3i + 4);
let d = box(GC)(5i + 6);
}
......@@ -13,12 +13,11 @@
// Make sure the destructor is run for newtype structs.
use std::cell::Cell;
use std::gc::{Gc, GC};
struct Foo(Gc<Cell<int>>);
struct Foo<'a>(&'a Cell<int>);
#[unsafe_destructor]
impl Drop for Foo {
impl<'a> Drop for Foo<'a> {
fn drop(&mut self) {
let Foo(i) = *self;
i.set(23);
......@@ -26,7 +25,7 @@ fn drop(&mut self) {
}
pub fn main() {
let y = box(GC) Cell::new(32);
let y = &Cell::new(32);
{
let _x = Foo(y);
}
......
......@@ -11,7 +11,6 @@
#![feature(macro_rules)]
use std::{option, mem};
use std::gc::{Gc, GC};
// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
// which "says that a destructor applied to an object built from a constructor
......@@ -76,7 +75,6 @@ fn get_ref(&self) -> (int, &T) {
pub fn main() {
check_type!(&17: &int);
check_type!(box 18: Box<int>);
check_type!(box(GC) 19: Gc<int>);
check_type!("foo".to_string(): String);
check_type!(vec!(20, 22): Vec<int> );
let mint: uint = unsafe { mem::transmute(main) };
......
......@@ -11,7 +11,6 @@
#![feature(macro_rules)]
use std::mem;
use std::gc::Gc;
enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
struct S<T>(int, T);
......@@ -40,6 +39,5 @@ enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
pub fn main() {
check_type!(&'static int);
check_type!(Box<int>);
check_type!(Gc<int>);
check_type!(extern fn());
}
// Copyright 2013-2014 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.
use std::gc::{Gc, GC};
// Test invoked `&self` methods on owned objects where the values
// closed over contain managed values. This implies that the boxes
// will have headers that must be skipped over.
trait FooTrait {
fn foo(&self) -> uint;
}
struct BarStruct {
x: Gc<uint>
}
impl FooTrait for BarStruct {
fn foo(&self) -> uint {
*self.x
}
}
pub fn main() {
let foos: Vec<Box<FooTrait>> = vec!(
box BarStruct{ x: box(GC) 0 } as Box<FooTrait>,
box BarStruct{ x: box(GC) 1 } as Box<FooTrait>,
box BarStruct{ x: box(GC) 2 } as Box<FooTrait>
);
for i in range(0u, foos.len()) {
assert_eq!(i, foos.get(i).foo());
}
}
......@@ -11,16 +11,14 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{GC, Gc};
struct dtor {
x: Gc<Cell<int>>,
struct dtor<'a> {
x: &'a Cell<int>,
}
#[unsafe_destructor]
impl Drop for dtor {
impl<'a> Drop for dtor<'a> {
fn drop(&mut self) {
// abuse access to shared mutable state to write this code
self.x.set(self.x.get() - 1);
}
}
......@@ -33,7 +31,7 @@ fn unwrap<T>(o: Option<T>) -> T {
}
pub fn main() {
let x = box(GC) Cell::new(1);
let x = &Cell::new(1);
{
let b = Some(dtor { x:x });
......
......@@ -11,30 +11,28 @@
#![allow(dead_assignment)]
#![allow(unused_variable)]
use std::gc::{Gc, GC};
struct A { a: int, b: int }
struct Abox { a: Gc<int>, b: Gc<int> }
struct Abox { a: Box<int>, b: Box<int> }
fn ret_int_i() -> int { return 10; }
fn ret_int_i() -> int { 10 }
fn ret_ext_i() -> Gc<int> { return box(GC) 10; }
fn ret_ext_i() -> Box<int> { box 10 }
fn ret_int_rec() -> A { return A {a: 10, b: 10}; }
fn ret_int_rec() -> A { A {a: 10, b: 10} }
fn ret_ext_rec() -> Gc<A> { return box(GC) A {a: 10, b: 10}; }
fn ret_ext_rec() -> Box<A> { box A {a: 10, b: 10} }
fn ret_ext_mem() -> Abox { return Abox {a: box(GC) 10, b: box(GC) 10}; }
fn ret_ext_mem() -> Abox { Abox {a: box 10, b: box 10} }
fn ret_ext_ext_mem() -> Gc<Abox> { box(GC) Abox{a: box(GC) 10, b: box(GC) 10} }
fn ret_ext_ext_mem() -> Box<Abox> { box Abox{a: box 10, b: box 10} }
pub fn main() {
let mut int_i: int;
let mut ext_i: Gc<int>;
let mut ext_i: Box<int>;
let mut int_rec: A;
let mut ext_rec: Gc<A>;
let mut ext_rec: Box<A>;
let mut ext_mem: Abox;
let mut ext_ext_mem: Gc<Abox>;
let mut ext_ext_mem: Box<Abox>;
int_i = ret_int_i(); // initializing
int_i = ret_int_i(); // non-initializing
......
......@@ -10,7 +10,6 @@
use std::mem;
use std::gc::Gc;
#[repr(packed)]
struct S4 {
......@@ -48,7 +47,7 @@ struct S7_Option {
a: f32,
b: u8,
c: u16,
d: Option<Gc<f64>>
d: Option<Box<f64>>
}
// Placing packed structs in statics should work
......@@ -62,5 +61,5 @@ pub fn main() {
assert_eq!(mem::size_of::<S5>(), 5);
assert_eq!(mem::size_of::<S13>(), 13);
assert_eq!(mem::size_of::<S3_Foo>(), 3 + mem::size_of::<Foo>());
assert_eq!(mem::size_of::<S7_Option>(), 7 + mem::size_of::<Option<Gc<f64>>>());
assert_eq!(mem::size_of::<S7_Option>(), 7 + mem::size_of::<Option<Box<f64>>>());
}
......@@ -9,7 +9,6 @@
// except according to those terms.
use std::gc::Gc;
use std::mem;
#[repr(packed)]
......@@ -30,7 +29,7 @@ enum Foo {
struct S3_Foo(u8, u16, Foo);
#[repr(packed)]
struct S7_Option(f32, u8, u16, Option<Gc<f64>>);
struct S7_Option(f32, u8, u16, Option<Box<f64>>);
pub fn main() {
assert_eq!(mem::size_of::<S4>(), 4);
......@@ -43,5 +42,5 @@ pub fn main() {
3 + mem::size_of::<Foo>());
assert_eq!(mem::size_of::<S7_Option>(),
7 + mem::size_of::<Option<Gc<f64>>>());
7 + mem::size_of::<Option<Box<f64>>>());
}
// Copyright 2012 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.
extern crate debug;
use std::gc::{GC, Gc};
fn magic(x: A) { println!("{:?}", x); }
fn magic2(x: Gc<int>) { println!("{:?}", x); }
struct A { a: Gc<int> }
pub fn main() {
let a = A {a: box(GC) 10};
let b = box(GC) 10;
magic(a); magic(A {a: box(GC) 20});
magic2(b); magic2(box(GC) 20);
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
trait get {
fn get(self) -> int;
}
......@@ -25,15 +23,6 @@ fn get(self) -> int {
}
pub fn main() {
let x = box(GC) 6;
let y = x.get();
assert_eq!(y, 6);
let x = box(GC) 6;
let y = x.get();
println!("y={}", y);
assert_eq!(y, 6);
let x = box 6;
let y = x.get();
println!("y={}", y);
......
......@@ -9,14 +9,12 @@
// except according to those terms.
use std::gc::GC;
fn foo(x: &uint) -> uint {
*x
}
pub fn main() {
let p = box(GC) 22u;
let p = box 22u;
let r = foo(&*p);
println!("r={}", r);
assert_eq!(r, 22u);
......
......@@ -9,12 +9,10 @@
// except according to those terms.
use std::gc::GC;
fn foo(x: &uint) -> &uint { x }
fn bar(x: &uint) -> uint { *x }
pub fn main() {
let p = box(GC) 3u;
let p = box 3u;
assert_eq!(bar(foo(&*p)), 3);
}
......@@ -8,12 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::gc::GC;
fn borrow<T>(x: &T) -> &T {x}
pub fn main() {
let x = box(GC) 3i;
let x = box 3i;
loop {
let y = borrow(&*x);
assert_eq!(*x, *y);
......
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
struct Point {x: int, y: int}
fn x_coord(p: &Point) -> &int {
......@@ -18,7 +16,7 @@ fn x_coord(p: &Point) -> &int {
}
pub fn main() {
let p = box(GC) Point {x: 3, y: 4};
let p = box Point {x: 3, y: 4};
let xc = x_coord(&*p);
assert_eq!(*xc, 3);
}
......@@ -10,36 +10,34 @@
#![feature(unsafe_destructor)]
extern crate debug;
use std::cell::Cell;
use std::gc::{Gc, GC};
struct r {
i: Gc<Cell<int>>,
#[deriving(Show)]
struct r<'a> {
i: &'a Cell<int>,
}
#[unsafe_destructor]
impl Drop for r {
impl<'a> Drop for r<'a> {
fn drop(&mut self) {
self.i.set(self.i.get() + 1);
}
}
fn r(i: Gc<Cell<int>>) -> r {
fn r(i: &Cell<int>) -> r {
r {
i: i
}
}
pub fn main() {
let i = box(GC) Cell::new(0i);
let i = &Cell::new(0i);
// Even though these look like copies, they are guaranteed not to be
{
let a = r(i);
let b = (a, 10i);
let (c, _d) = b;
println!("{:?}", c);
println!("{}", c);
}
assert_eq!(i.get(), 1);
}
......@@ -11,31 +11,30 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{GC, Gc};
struct shrinky_pointer {
i: Gc<Gc<Cell<int>>>,
struct shrinky_pointer<'a> {
i: &'a Cell<int>,
}
#[unsafe_destructor]
impl Drop for shrinky_pointer {
impl<'a> Drop for shrinky_pointer<'a> {
fn drop(&mut self) {
println!("Hello!"); self.i.set(self.i.get() - 1);
}
}
impl shrinky_pointer {
impl<'a> shrinky_pointer<'a> {
pub fn look_at(&self) -> int { return self.i.get(); }
}
fn shrinky_pointer(i: Gc<Gc<Cell<int>>>) -> shrinky_pointer {
fn shrinky_pointer(i: &Cell<int>) -> shrinky_pointer {
shrinky_pointer {
i: i
}
}
pub fn main() {
let my_total = box(GC) box(GC) Cell::new(10);
let my_total = &Cell::new(10);
{ let pt = shrinky_pointer(my_total); assert!((pt.look_at() == 10)); }
println!("my_total = {}", my_total.get());
assert_eq!(my_total.get(), 9);
......
......@@ -14,17 +14,16 @@
// variant
use std::cell::Cell;
use std::gc::{Gc, GC};
type closable = Gc<Cell<bool>>;
type closable<'a> = &'a Cell<bool>;
struct close_res {
i: closable,
struct close_res<'a> {
i: closable<'a>,
}
#[unsafe_destructor]
impl Drop for close_res {
impl<'a> Drop for close_res<'a> {
fn drop(&mut self) {
self.i.set(false);
}
......@@ -41,7 +40,7 @@ enum option<T> { none, some(T), }
fn sink(_res: option<close_res>) { }
pub fn main() {
let c = box(GC) Cell::new(true);
let c = &Cell::new(true);
sink(none);
sink(some(close_res(c)));
assert!(!c.get());
......
......@@ -9,30 +9,26 @@
// except according to those terms.
extern crate debug;
// Exercises a bug in the shape code that was exposed
// on x86_64: when there is an enum embedded in an
// interior record which is then itself interior to
// something else, shape calculations were off.
use std::gc::{Gc, GC};
#[deriving(Clone)]
#[deriving(Clone, Show)]
enum opt_span {
//hack (as opposed to option), to make `span` compile
os_none,
os_some(Gc<Span>),
os_some(Box<Span>),
}
#[deriving(Clone)]
#[deriving(Clone, Show)]
struct Span {
lo: uint,
hi: uint,
expanded_from: opt_span,
}
#[deriving(Clone)]
#[deriving(Clone, Show)]
struct Spanned<T> {
data: T,
span: Span,
......@@ -40,17 +36,17 @@ struct Spanned<T> {
type ty_ = uint;
#[deriving(Clone)]
#[deriving(Clone, Show)]
struct Path_ {
global: bool,
idents: Vec<String> ,
types: Vec<Gc<ty>>,
types: Vec<Box<ty>>,
}
type path = Spanned<Path_>;
type ty = Spanned<ty_>;
#[deriving(Clone)]
#[deriving(Clone, Show)]
struct X {
sp: Span,
path: path,
......@@ -58,14 +54,14 @@ struct X {
pub fn main() {
let sp: Span = Span {lo: 57451u, hi: 57542u, expanded_from: os_none};
let t: Gc<ty> = box(GC) Spanned { data: 3u, span: sp };
let t: Box<ty> = box Spanned { data: 3u, span: sp.clone() };
let p_: Path_ = Path_ {
global: true,
idents: vec!("hi".to_string()),
types: vec!(t),
};
let p: path = Spanned { data: p_, span: sp };
let p: path = Spanned { data: p_, span: sp.clone() };
let x = X { sp: sp, path: p };
println!("{:?}", x.path.clone());
println!("{:?}", x.clone());
println!("{}", x.path.clone());
println!("{}", x.clone());
}
......@@ -13,22 +13,21 @@
// Don't try to clean up uninitialized locals
use std::task;
use std::gc::{Gc};
fn test_break() { loop { let _x: Gc<int> = break; } }
fn test_break() { loop { let _x: Box<int> = break; } }
fn test_cont() { let mut i = 0i; while i < 1 { i += 1; let _x: Gc<int> = continue; } }
fn test_cont() { let mut i = 0i; while i < 1 { i += 1; let _x: Box<int> = continue; } }
fn test_ret() { let _x: Gc<int> = return; }
fn test_ret() { let _x: Box<int> = return; }
fn test_fail() {
fn f() { let _x: Gc<int> = fail!(); }
fn f() { let _x: Box<int> = fail!(); }
task::try(proc() f() );
}
fn test_fail_indirect() {
fn f() -> ! { fail!(); }
fn g() { let _x: Gc<int> = f(); }
fn g() { let _x: Box<int> = f(); }
task::try(proc() g() );
}
......
// Copyright 2012 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.
// ignore-pretty FIXME(#14193)
// Test cyclic detector when using trait instances.
use std::cell::RefCell;
use std::gc::{GC, Gc};
struct Tree(Gc<RefCell<TreeR>>);
struct TreeR {
left: Option<Tree>,
right: Option<Tree>,
val: Box<to_str+Send>
}
trait to_str {
fn to_str_(&self) -> String;
}
impl<T:to_str> to_str for Option<T> {
fn to_str_(&self) -> String {
match *self {
None => { "none".to_string() }
Some(ref t) => format!("some({})", t.to_str_()),
}
}
}
impl to_str for int {
fn to_str_(&self) -> String {
self.to_string()
}
}
impl to_str for Tree {
fn to_str_(&self) -> String {
let Tree(t) = *self;
let this = t.borrow();
let (l, r) = (this.left, this.right);
let val = &this.val;
format!("[{}, {}, {}]", val.to_str_(), l.to_str_(), r.to_str_())
}
}
fn foo<T:to_str>(x: T) -> String { x.to_str_() }
pub fn main() {
let t1 = Tree(box(GC) RefCell::new(TreeR{left: None,
right: None,
val: box 1i as Box<to_str+Send>}));
let t2 = Tree(box(GC) RefCell::new(TreeR{left: Some(t1),
right: Some(t1),
val: box 2i as Box<to_str+Send>}));
let expected =
"[2, some([1, none, none]), some([1, none, none])]".to_string();
assert!(t2.to_str_() == expected);
assert!(foo(t2) == expected);
{
let Tree(t1_) = t1;
let mut t1 = t1_.borrow_mut();
t1.left = Some(t2); // create cycle
}
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
fn p_foo<T>(_pinned: T) { }
fn s_foo<T>(_shared: T) { }
fn u_foo<T:Send>(_unique: T) { }
......@@ -31,15 +29,11 @@ fn r(i:int) -> r {
pub fn main() {
p_foo(r(10));
p_foo(box(GC) r(10));
p_foo(box r(10));
p_foo(box(GC) 10i);
p_foo(box 10i);
p_foo(10i);
s_foo(box(GC) r(10));
s_foo(box(GC) 10i);
s_foo(box 10i);
s_foo(10i);
......
......@@ -12,17 +12,15 @@
// Example from lkuper's intern talk, August 2012 -- now with static
// methods!
use std::gc::{GC, Gc};
trait Equal {
fn isEq(a: Self, b: Self) -> bool;
fn isEq(a: &Self, b: &Self) -> bool;
}
enum Color { cyan, magenta, yellow, black }
impl Equal for Color {
fn isEq(a: Color, b: Color) -> bool {
match (a, b) {
fn isEq(a: &Color, b: &Color) -> bool {
match (*a, *b) {
(cyan, cyan) => { true }
(magenta, magenta) => { true }
(yellow, yellow) => { true }
......@@ -34,15 +32,15 @@ fn isEq(a: Color, b: Color) -> bool {
enum ColorTree {
leaf(Color),
branch(Gc<ColorTree>, Gc<ColorTree>)
branch(Box<ColorTree>, Box<ColorTree>)
}
impl Equal for ColorTree {
fn isEq(a: ColorTree, b: ColorTree) -> bool {
fn isEq(a: &ColorTree, b: &ColorTree) -> bool {
match (a, b) {
(leaf(x), leaf(y)) => { Equal::isEq(x, y) }
(branch(l1, r1), branch(l2, r2)) => {
Equal::isEq(*l1, *l2) && Equal::isEq(*r1, *r2)
(&leaf(x), &leaf(y)) => { Equal::isEq(&x, &y) }
(&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => {
Equal::isEq(&**l1, &**l2) && Equal::isEq(&**r1, &**r2)
}
_ => { false }
}
......@@ -50,19 +48,19 @@ fn isEq(a: ColorTree, b: ColorTree) -> bool {
}
pub fn main() {
assert!(Equal::isEq(cyan, cyan));
assert!(Equal::isEq(magenta, magenta));
assert!(!Equal::isEq(cyan, yellow));
assert!(!Equal::isEq(magenta, cyan));
assert!(Equal::isEq(&cyan, &cyan));
assert!(Equal::isEq(&magenta, &magenta));
assert!(!Equal::isEq(&cyan, &yellow));
assert!(!Equal::isEq(&magenta, &cyan));
assert!(Equal::isEq(leaf(cyan), leaf(cyan)));
assert!(!Equal::isEq(leaf(cyan), leaf(yellow)));
assert!(Equal::isEq(&leaf(cyan), &leaf(cyan)));
assert!(!Equal::isEq(&leaf(cyan), &leaf(yellow)));
assert!(Equal::isEq(branch(box(GC) leaf(magenta), box(GC) leaf(cyan)),
branch(box(GC) leaf(magenta), box(GC) leaf(cyan))));
assert!(Equal::isEq(&branch(box leaf(magenta), box leaf(cyan)),
&branch(box leaf(magenta), box leaf(cyan))));
assert!(!Equal::isEq(branch(box(GC) leaf(magenta), box(GC) leaf(cyan)),
branch(box(GC) leaf(magenta), box(GC) leaf(magenta))));
assert!(!Equal::isEq(&branch(box leaf(magenta), box leaf(cyan)),
&branch(box leaf(magenta), box leaf(magenta))));
println!("Assertions all succeeded!");
}
......@@ -11,17 +11,15 @@
// Example from lkuper's intern talk, August 2012.
use std::gc::{GC, Gc};
trait Equal {
fn isEq(&self, a: Self) -> bool;
fn isEq(&self, a: &Self) -> bool;
}
enum Color { cyan, magenta, yellow, black }
impl Equal for Color {
fn isEq(&self, a: Color) -> bool {
match (*self, a) {
fn isEq(&self, a: &Color) -> bool {
match (*self, *a) {
(cyan, cyan) => { true }
(magenta, magenta) => { true }
(yellow, yellow) => { true }
......@@ -33,15 +31,15 @@ fn isEq(&self, a: Color) -> bool {
enum ColorTree {
leaf(Color),
branch(Gc<ColorTree>, Gc<ColorTree>)
branch(Box<ColorTree>, Box<ColorTree>)
}
impl Equal for ColorTree {
fn isEq(&self, a: ColorTree) -> bool {
match (*self, a) {
(leaf(x), leaf(y)) => { x.isEq(y) }
(branch(l1, r1), branch(l2, r2)) => {
(*l1).isEq(*l2) && (*r1).isEq(*r2)
fn isEq(&self, a: &ColorTree) -> bool {
match (self, a) {
(&leaf(x), &leaf(y)) => { x.isEq(&y) }
(&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => {
(&**l1).isEq(&**l2) && (&**r1).isEq(&**r2)
}
_ => { false }
}
......@@ -49,19 +47,19 @@ fn isEq(&self, a: ColorTree) -> bool {
}
pub fn main() {
assert!(cyan.isEq(cyan));
assert!(magenta.isEq(magenta));
assert!(!cyan.isEq(yellow));
assert!(!magenta.isEq(cyan));
assert!(cyan.isEq(&cyan));
assert!(magenta.isEq(&magenta));
assert!(!cyan.isEq(&yellow));
assert!(!magenta.isEq(&cyan));
assert!(leaf(cyan).isEq(leaf(cyan)));
assert!(!leaf(cyan).isEq(leaf(yellow)));
assert!(leaf(cyan).isEq(&leaf(cyan)));
assert!(!leaf(cyan).isEq(&leaf(yellow)));
assert!(branch(box(GC) leaf(magenta), box(GC) leaf(cyan))
.isEq(branch(box(GC) leaf(magenta), box(GC) leaf(cyan))));
assert!(branch(box leaf(magenta), box leaf(cyan))
.isEq(&branch(box leaf(magenta), box leaf(cyan))));
assert!(!branch(box(GC) leaf(magenta), box(GC) leaf(cyan))
.isEq(branch(box(GC) leaf(magenta), box(GC) leaf(magenta))));
assert!(!branch(box leaf(magenta), box leaf(cyan))
.isEq(&branch(box leaf(magenta), box leaf(magenta))));
println!("Assertions all succeeded!");
}
// Copyright 2012-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.
// ignore-pretty FIXME(#14193)
use std::cell::RefCell;
use std::gc::{Gc, GC};
enum maybe_pointy {
none,
p(Gc<RefCell<Pointy>>),
}
struct Pointy {
a : maybe_pointy,
d : proc():Send -> uint,
}
fn make_uniq_closure<A:Send>(a: A) -> proc():Send -> uint {
proc() { &a as *const A as uint }
}
fn empty_pointy() -> Gc<RefCell<Pointy>> {
return box(GC) RefCell::new(Pointy {
a : none,
d : make_uniq_closure("hi".to_string())
})
}
pub fn main() {
let v = empty_pointy();
{
let mut vb = v.borrow_mut();
vb.a = p(v);
}
}
// Copyright 2012 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.
use std::cell::RefCell;
use std::gc::{Gc, GC};
enum maybe_pointy {
none,
p(Gc<RefCell<Pointy>>),
}
struct Pointy {
a : maybe_pointy,
c : Box<int>,
d : proc():Send->(),
}
fn empty_pointy() -> Gc<RefCell<Pointy>> {
return box(GC) RefCell::new(Pointy {
a : none,
c : box 22,
d : proc() {},
})
}
pub fn main() {
let v = empty_pointy();
{
let mut vb = v.borrow_mut();
vb.a = p(v);
}
}
......@@ -9,8 +9,6 @@
// except according to those terms.
use std::gc::GC;
fn f<T>(t: T) -> T {
let t1 = t;
t1
......@@ -19,6 +17,4 @@ fn f<T>(t: T) -> T {
pub fn main() {
let t = f(box 100i);
assert_eq!(t, box 100i);
let t = f(box box(GC) vec!(100i));
assert_eq!(t, box box(GC) vec!(100i));
}
// Copyright 2012 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.
use std::task;
use std::gc::GC;
fn f() {
let _a = box(GC) 0i;
fail!();
}
pub fn main() {
task::spawn(f);
}
// Copyright 2012 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.
#![feature(unsafe_destructor)]
use std::task;
use std::gc::{Gc, GC};
struct complainer {
c: Gc<int>,
}
#[unsafe_destructor]
impl Drop for complainer {
fn drop(&mut self) {}
}
fn complainer(c: Gc<int>) -> complainer {
complainer {
c: c
}
}
fn f() {
let _c = complainer(box(GC) 0);
fail!();
}
pub fn main() {
task::spawn(f);
}
// Copyright 2012 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.
use std::gc::{GC, Gc};
struct Pair { x: int, y: int }
pub fn main() {
// This just tests whether the vec leaks its members.
let _pvec: Vec<Gc<Pair>> =
vec!(box(GC) Pair{x: 1, y: 2},
box(GC) Pair{x: 3, y: 4},
box(GC) Pair{x: 5, y: 6});
}
......@@ -11,28 +11,27 @@
#![feature(unsafe_destructor)]
use std::cell::Cell;
use std::gc::{Gc, GC};
// Make sure that destructors get run on slice literals
struct foo {
x: Gc<Cell<int>>,
struct foo<'a> {
x: &'a Cell<int>,
}
#[unsafe_destructor]
impl Drop for foo {
impl<'a> Drop for foo<'a> {
fn drop(&mut self) {
self.x.set(self.x.get() + 1);
}
}
fn foo(x: Gc<Cell<int>>) -> foo {
fn foo(x: &Cell<int>) -> foo {
foo {
x: x
}
}
pub fn main() {
let x = box(GC) Cell::new(0);
let x = &Cell::new(0);
{
let l = &[foo(x)];
assert_eq!(l[0].x.get(), 0);
......
......@@ -11,7 +11,6 @@
use std::cell::Cell;
use std::mem::swap;
use std::gc::{Gc, GC};
// Just a grab bag of stuff that you wouldn't want to actually write.
......@@ -23,10 +22,10 @@ fn f(_x: ()) { }
}
fn what() {
fn the(x: Gc<Cell<bool>>) {
fn the(x: &Cell<bool>) {
return while !x.get() { x.set(true); };
}
let i = box(GC) Cell::new(false);
let i = &Cell::new(false);
let dont = {||the(i)};
dont();
assert!((i.get()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册