Skip to content

Commit d31105e

Browse files
committed
Add new tests covering various cases.
1 parent d913239 commit d31105e

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
struct MyType;
12+
13+
struct MyType1<T>(T);
14+
15+
trait Bar {
16+
type Out;
17+
}
18+
19+
impl<T> MyType {
20+
//~^ ERROR the type parameter `T` is not constrained
21+
}
22+
23+
impl<T> MyType1<T> {
24+
// OK, T is used in `Foo<T>`.
25+
}
26+
27+
impl<T,U> MyType1<T> {
28+
//~^ ERROR the type parameter `U` is not constrained
29+
}
30+
31+
impl<T,U> MyType1<T> where T: Bar<Out=U> {
32+
// OK, T is used in `Foo<T>`.
33+
}
34+
35+
fn main() { }
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 [int;0] {
20+
// OK, T is used in `Foo<T>`.
21+
}
22+
23+
impl<T,U> Foo<T> for [int;1] {
24+
//~^ ERROR the type parameter `U` is not constrained
25+
}
26+
27+
impl<T,U> Foo<T> for [int;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 [int;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() { }

0 commit comments

Comments
 (0)