unique-vec-res.rs 1.1 KB
Newer Older
1 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.

11
#![feature(managed_boxes, unsafe_destructor)]
D
Daniel Micay 已提交
12

13
extern crate debug;
P
Patrick Walton 已提交
14
use std::cell::Cell;
15
use std::gc::{Gc, GC};
P
Patrick Walton 已提交
16

B
Brian Anderson 已提交
17
struct r {
18
  i: Gc<Cell<int>>,
19 20
}

21
#[unsafe_destructor]
22
impl Drop for r {
D
Daniel Micay 已提交
23
    fn drop(&mut self) {
24
        unsafe {
P
Patrick Walton 已提交
25
            self.i.set(self.i.get() + 1);
26
        }
27
    }
28 29
}

30
fn f<T>(_i: Vec<T> , _j: Vec<T> ) {
31 32 33
}

fn main() {
34 35
    let i1 = box(GC) Cell::new(0);
    let i2 = box(GC) Cell::new(1);
36 37
    let r1 = vec!(box r { i: i1 });
    let r2 = vec!(box r { i: i2 });
38 39
    f(r1.clone(), r2.clone());
    //~^ ERROR failed to find an implementation of
40 41
    println!("{:?}", (r2, i1.get()));
    println!("{:?}", (r1, i2.get()));
42
}