unique-vec-res.rs 954 字节
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.

B
Brian Anderson 已提交
11
struct r {
12
  i: @mut int,
13 14
}

15
#[unsafe_destructor]
16
impl Drop for r {
L
Luqman Aden 已提交
17
    fn drop(&self) {
18 19 20
        unsafe {
            *(self.i) = *(self.i) + 1;
        }
21
    }
22 23
}

P
Patrick Walton 已提交
24
fn f<T>(_i: ~[T], _j: ~[T]) {
25 26 27
}

fn main() {
G
Graydon Hoare 已提交
28 29
    let i1 = @mut 0;
    let i2 = @mut 1;
30 31
    let r1 = ~[~r { i: i1 }];
    let r2 = ~[~r { i: i2 }];
32
    f(copy r1, copy r2);
33 34
    //~^ ERROR copying a value of non-copyable type
    //~^^ ERROR copying a value of non-copyable type
35 36
    info!((r2, *i1));
    info!((r1, *i2));
37
}