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(unsafe_destructor)]
D
Daniel Micay 已提交
12

P
Patrick Walton 已提交
13 14
use std::cell::Cell;

E
Eduard Burtescu 已提交
15 16 17
#[deriving(Show)]
struct r<'a> {
  i: &'a Cell<int>,
18 19
}

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

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

fn main() {
E
Eduard Burtescu 已提交
33 34
    let i1 = &Cell::new(0);
    let i2 = &Cell::new(1);
35 36
    let r1 = vec!(box r { i: i1 });
    let r2 = vec!(box r { i: i2 });
37
    f(r1.clone(), r2.clone());
38 39
    //~^ ERROR the trait `core::clone::Clone` is not implemented
    //~^^ ERROR the trait `core::clone::Clone` is not implemented
E
Eduard Burtescu 已提交
40 41
    println!("{}", (r2, i1.get()));
    println!("{}", (r1, i2.get()));
42
}