blob: baef20944f7047a0fbc825b0bd3be85286f74f35 [file] [log] [blame]
Patrick Waltonaac9d6e2013-08-28 01:45:131// xfail-pretty
2
Philipp Brüschweilerde471a22013-06-22 07:37:403// 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 Matsakisb402e342013-08-11 17:58:4813// 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üschweilerde471a22013-06-22 07:37:4017trait FooTrait {
18 fn foo(&self) -> uint;
19}
20
21struct BarStruct {
Niko Matsakisb402e342013-08-11 17:58:4822 x: @uint
Philipp Brüschweilerde471a22013-06-22 07:37:4023}
24
25impl FooTrait for BarStruct {
26 fn foo(&self) -> uint {
Niko Matsakisb402e342013-08-11 17:58:4827 *self.x
Philipp Brüschweilerde471a22013-06-22 07:37:4028 }
29}
30
31pub fn main() {
Niko Matsakisb402e342013-08-11 17:58:4832 let foos: ~[ ~FooTrait: ] = ~[
33 ~BarStruct{ x: @0 } as ~FooTrait:,
34 ~BarStruct{ x: @1 } as ~FooTrait:,
35 ~BarStruct{ x: @2 } as ~FooTrait:
Philipp Brüschweilerde471a22013-06-22 07:37:4036 ];
37
Daniel Micay100894552013-08-03 16:45:2338 for i in range(0u, foos.len()) {
Philipp Brüschweilerde471a22013-06-22 07:37:4039 assert_eq!(i, foos[i].foo());
40 }
41}