Patrick Walton | aac9d6e | 2013-08-28 01:45:13 | [diff] [blame] | 1 | // xfail-pretty |
| 2 | |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 3 | // Copyright 2013 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 | |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 13 | // Test invoked `&self` methods on owned objects where the values |
| 14 | // closed over contain managed values. This implies that the ~ boxes |
| 15 | // will have headers that must be skipped over. |
| 16 | |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 17 | trait FooTrait { |
| 18 | fn foo(&self) -> uint; |
| 19 | } |
| 20 | |
| 21 | struct BarStruct { |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 22 | x: @uint |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | impl FooTrait for BarStruct { |
| 26 | fn foo(&self) -> uint { |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 27 | *self.x |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 28 | } |
| 29 | } |
| 30 | |
| 31 | pub fn main() { |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 32 | let foos: ~[ ~FooTrait: ] = ~[ |
| 33 | ~BarStruct{ x: @0 } as ~FooTrait:, |
| 34 | ~BarStruct{ x: @1 } as ~FooTrait:, |
| 35 | ~BarStruct{ x: @2 } as ~FooTrait: |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 36 | ]; |
| 37 | |
Daniel Micay | 10089455 | 2013-08-03 16:45:23 | [diff] [blame] | 38 | for i in range(0u, foos.len()) { |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 39 | assert_eq!(i, foos[i].foo()); |
| 40 | } |
| 41 | } |