]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/ufcs-explicit-self.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / ufcs-explicit-self.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2012 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
11#![allow(unknown_features)]
12#![feature(box_syntax)]
13
c34b1796 14#[derive(Copy, Clone)]
1a4d82fc 15struct Foo {
c34b1796 16 f: isize,
1a4d82fc
JJ
17}
18
1a4d82fc 19impl Foo {
c34b1796 20 fn foo(self: Foo, x: isize) -> isize {
1a4d82fc
JJ
21 self.f + x
22 }
c34b1796 23 fn bar(self: &Foo, x: isize) -> isize {
1a4d82fc
JJ
24 self.f + x
25 }
c34b1796 26 fn baz(self: Box<Foo>, x: isize) -> isize {
1a4d82fc
JJ
27 self.f + x
28 }
29}
30
c34b1796 31#[derive(Copy, Clone)]
1a4d82fc
JJ
32struct Bar<T> {
33 f: T,
34}
35
1a4d82fc 36impl<T> Bar<T> {
c34b1796 37 fn foo(self: Bar<T>, x: isize) -> isize {
1a4d82fc
JJ
38 x
39 }
c34b1796 40 fn bar<'a>(self: &'a Bar<T>, x: isize) -> isize {
1a4d82fc
JJ
41 x
42 }
c34b1796 43 fn baz(self: Bar<T>, x: isize) -> isize {
1a4d82fc
JJ
44 x
45 }
46}
47
48fn main() {
c34b1796 49 let foo: Box<_> = box Foo {
1a4d82fc
JJ
50 f: 1,
51 };
52 println!("{} {} {}", foo.foo(2), foo.bar(2), foo.baz(2));
c34b1796 53 let bar: Box<_> = box Bar {
1a4d82fc
JJ
54 f: 1,
55 };
56 println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2));
c34b1796 57 let bar: Box<Bar<isize>> = bar;
1a4d82fc
JJ
58 println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2));
59}