]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/ufcs-explicit-self-bad.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / compile-fail / ufcs-explicit-self-bad.rs
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 #![feature(box_syntax)]
12
13 struct Foo {
14 f: isize,
15 }
16
17 impl Foo {
18 fn foo(self: isize, x: isize) -> isize { //~ ERROR mismatched self type
19 self.f + x
20 }
21 }
22
23 struct Bar<T> {
24 f: T,
25 }
26
27 impl<T> Bar<T> {
28 fn foo(self: Bar<isize>, x: isize) -> isize { //~ ERROR mismatched self type
29 x
30 }
31 fn bar(self: &Bar<usize>, x: isize) -> isize { //~ ERROR mismatched self type
32 x
33 }
34 }
35
36 trait SomeTrait {
37 fn dummy1(&self);
38 fn dummy2(&self);
39 fn dummy3(&self);
40 }
41
42 impl<'a, T> SomeTrait for &'a Bar<T> {
43 fn dummy1(self: &&'a Bar<T>) { }
44 fn dummy2(self: &Bar<T>) {} //~ ERROR mismatched self type
45 fn dummy3(self: &&Bar<T>) {}
46 //~^ ERROR mismatched types
47 //~| expected `&'a Bar<T>`
48 //~| found `&Bar<T>`
49 //~| lifetime mismatch
50 //~| ERROR mismatched types
51 //~| expected `&'a Bar<T>`
52 //~| found `&Bar<T>`
53 //~| lifetime mismatch
54 }
55
56 fn main() {
57 let foo = box Foo {
58 f: 1,
59 };
60 println!("{}", foo.foo(2));
61 let bar = box Bar {
62 f: 1,
63 };
64 println!("{} {}", bar.foo(2), bar.bar(2));
65 }