Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 1 | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
| 2 | // file at the top-level directory of this distribution and at |
| 3 | // http://rust-lang.org/COPYRIGHT. |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | // option. This file may not be copied, modified, or distributed |
| 9 | // except according to those terms. |
| 10 | |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 11 | // Test invoked `&self` methods on owned objects where the values |
| 12 | // closed over contain managed values. This implies that the ~ boxes |
| 13 | // will have headers that must be skipped over. |
| 14 | |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 15 | trait FooTrait { |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 16 | fn foo(~self) -> uint; |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | struct BarStruct { |
| 20 | x: uint |
| 21 | } |
| 22 | |
| 23 | impl FooTrait for BarStruct { |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 24 | fn foo(~self) -> uint { |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 25 | self.x |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | pub fn main() { |
Niko Matsakis | b402e34 | 2013-08-11 17:58:48 | [diff] [blame] | 30 | let foo = ~BarStruct{ x: 22 } as ~FooTrait; |
| 31 | assert_eq!(22, foo.foo()); |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 32 | } |