]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 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 | // Check that we correctly prevent users from making trait objects | |
c34b1796 AL |
12 | // form traits that make use of `Self` in an argument or return |
13 | // position, unless `where Self : Sized` is present.. | |
1a4d82fc JJ |
14 | |
15 | trait Bar { | |
16 | fn bar(&self, x: &Self); | |
17 | } | |
18 | ||
19 | trait Baz { | |
20 | fn bar(&self) -> Self; | |
21 | } | |
22 | ||
c34b1796 AL |
23 | trait Quux { |
24 | fn get(&self, s: &Self) -> Self where Self : Sized; | |
25 | } | |
26 | ||
1a4d82fc | 27 | fn make_bar<T:Bar>(t: &T) -> &Bar { |
e9174d1e | 28 | //~^ ERROR E0038 |
1a4d82fc | 29 | //~| NOTE method `bar` references the `Self` type in its arguments or return type |
5bcae85e | 30 | //~| NOTE the trait `Bar` cannot be made into an object |
9cc50fc6 | 31 | loop { } |
1a4d82fc JJ |
32 | } |
33 | ||
34 | fn make_baz<T:Baz>(t: &T) -> &Baz { | |
e9174d1e | 35 | //~^ ERROR E0038 |
1a4d82fc | 36 | //~| NOTE method `bar` references the `Self` type in its arguments or return type |
5bcae85e | 37 | //~| NOTE the trait `Baz` cannot be made into an object |
9cc50fc6 | 38 | t |
1a4d82fc JJ |
39 | } |
40 | ||
c34b1796 AL |
41 | fn make_quux<T:Quux>(t: &T) -> &Quux { |
42 | t | |
43 | } | |
44 | ||
45 | fn make_quux_explicit<T:Quux>(t: &T) -> &Quux { | |
46 | t as &Quux | |
47 | } | |
48 | ||
1a4d82fc JJ |
49 | fn main() { |
50 | } |