]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/objects-owned-object-borrowed-method-header.rs
test: Make manual changes to deal with the fallout from removal of
[rust.git] / src / test / run-pass / objects-owned-object-borrowed-method-header.rs
1 // ignore-pretty
2
3 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
4 // file at the top-level directory of this distribution and at
5 // http://rust-lang.org/COPYRIGHT.
6 //
7 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 // option. This file may not be copied, modified, or distributed
11 // except according to those terms.
12
13 #[feature(managed_boxes)];
14
15 use std::vec_ng::Vec;
16
17 // Test invoked `&self` methods on owned objects where the values
18 // closed over contain managed values. This implies that the ~ boxes
19 // will have headers that must be skipped over.
20
21 trait FooTrait {
22     fn foo(&self) -> uint;
23 }
24
25 struct BarStruct {
26     x: @uint
27 }
28
29 impl FooTrait for BarStruct {
30     fn foo(&self) -> uint {
31         *self.x
32     }
33 }
34
35 pub fn main() {
36     let foos: Vec<~FooTrait:> = vec!(
37         ~BarStruct{ x: @0 } as ~FooTrait:,
38         ~BarStruct{ x: @1 } as ~FooTrait:,
39         ~BarStruct{ x: @2 } as ~FooTrait:
40     );
41
42     for i in range(0u, foos.len()) {
43         assert_eq!(i, foos.get(i).foo());
44     }
45 }