]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2015 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 | trait Foo<A> { | |
12 | fn get(&self, A: &A) { } | |
13 | } | |
14 | ||
15 | trait Bar { | |
16 | type Out; | |
17 | } | |
18 | ||
19 | impl<T> Foo<T> for [isize;0] { | |
20 | // OK, T is used in `Foo<T>`. | |
21 | } | |
22 | ||
23 | impl<T,U> Foo<T> for [isize;1] { | |
24 | //~^ ERROR the type parameter `U` is not constrained | |
25 | } | |
26 | ||
27 | impl<T,U> Foo<T> for [isize;2] where T : Bar<Out=U> { | |
28 | // OK, `U` is now constrained by the output type parameter. | |
29 | } | |
30 | ||
31 | impl<T:Bar<Out=U>,U> Foo<T> for [isize;3] { | |
32 | // OK, same as above but written differently. | |
33 | } | |
34 | ||
35 | impl<T,U> Foo<T> for U { | |
36 | // OK, T, U are used everywhere. Note that the coherence check | |
37 | // hasn't executed yet, so no errors about overlap. | |
38 | } | |
39 | ||
40 | impl<T,U> Bar for T { | |
41 | //~^ ERROR the type parameter `U` is not constrained | |
42 | ||
43 | type Out = U; | |
44 | ||
45 | // Using `U` in an associated type within the impl is not good enough! | |
46 | } | |
47 | ||
48 | impl<T,U> Bar for T | |
49 | where T : Bar<Out=U> | |
50 | { | |
51 | //~^^^ ERROR the type parameter `U` is not constrained | |
52 | ||
53 | // This crafty self-referential attempt is still no good. | |
54 | } | |
55 | ||
56 | impl<T,U,V> Foo<T> for T | |
57 | where (T,U): Bar<Out=V> | |
58 | { | |
59 | //~^^^ ERROR the type parameter `U` is not constrained | |
60 | //~| ERROR the type parameter `V` is not constrained | |
61 | ||
62 | // Here, `V` is bound by an output type parameter, but the inputs | |
63 | // are not themselves constrained. | |
64 | } | |
65 | ||
66 | impl<T,U,V> Foo<(T,U)> for T | |
67 | where (T,U): Bar<Out=V> | |
68 | { | |
69 | // As above, but both T and U ARE constrained. | |
70 | } | |
71 | ||
72 | fn main() { } |