Skip to content

Commit 1d5897e

Browse files
committed
---
yaml --- r: 170367 b: refs/heads/try c: 7836c72 h: refs/heads/master i: 170365: 0965073 170363: f91ca6b 170359: e0299c6 170351: a0c3b7f 170335: 50747d6 170303: 7318fda 170239: d5e17d3 v: v3
1 parent e00347f commit 1d5897e

22 files changed

+400
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 73a25f55ad748b4d3516417c711b99ce446591af
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 5b3cd3900ceda838f5798c30ab96ceb41f962534
5-
refs/heads/try: 3657ae13f5f7ef4367a6de4b61bd4143fc6b52b4
5+
refs/heads/try: 7836c72ebae3124443fd4009b65eb2cc4cc6cf38
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/test/compile-fail/associated-types-eq-2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl Foo for int {
2525
fn boo(&self) -> uint { 42 }
2626
}
2727

28-
fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {} //~ERROR equality constraints are not allowed in this
28+
fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {}
29+
//~^ ERROR associated type bindings are not allowed here
2930

3031
pub fn main() {}

branches/try/src/test/compile-fail/associated-types-eq-3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ pub fn baz(x: &Foo<A=Bar>) {
4343

4444
pub fn main() {
4545
let a = 42i;
46-
foo1(a); //~ERROR the trait `Foo` is not implemented for the type `int`
47-
baz(&a); //~ERROR the trait `Foo` is not implemented for the type `int`
46+
foo1(a); //~ERROR expected uint, found struct Bar
47+
baz(&a); //~ERROR expected uint, found struct Bar
4848
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 testing of equality constraints in a higher-ranked context.
12+
13+
#![feature(associated_types)]
14+
15+
pub trait TheTrait<T> {
16+
type A;
17+
18+
fn get(&self, t: T) -> Self::A;
19+
}
20+
21+
struct IntStruct {
22+
x: int
23+
}
24+
25+
impl<'a> TheTrait<&'a int> for IntStruct {
26+
type A = &'a int;
27+
28+
fn get(&self, t: &'a int) -> &'a int {
29+
t
30+
}
31+
}
32+
33+
struct UintStruct {
34+
x: int
35+
}
36+
37+
impl<'a> TheTrait<&'a int> for UintStruct {
38+
type A = &'a uint;
39+
40+
fn get(&self, t: &'a int) -> &'a uint {
41+
panic!()
42+
}
43+
}
44+
45+
fn foo<T>()
46+
where T : for<'x> TheTrait<&'x int, A = &'x int>
47+
{
48+
// ok for IntStruct, but not UintStruct
49+
}
50+
51+
fn bar<T>()
52+
where T : for<'x> TheTrait<&'x int, A = &'x uint>
53+
{
54+
// ok for UintStruct, but not IntStruct
55+
}
56+
57+
fn baz<T>()
58+
where T : for<'x,'y> TheTrait<&'x int, A = &'y int>
59+
{
60+
// not ok for either struct, due to the use of two lifetimes
61+
}
62+
63+
pub fn main() {
64+
foo::<IntStruct>();
65+
foo::<UintStruct>(); //~ ERROR type mismatch
66+
67+
bar::<IntStruct>(); //~ ERROR type mismatch
68+
bar::<UintStruct>();
69+
70+
baz::<IntStruct>(); //~ ERROR type mismatch
71+
baz::<UintStruct>(); //~ ERROR type mismatch
72+
}

branches/try/src/test/compile-fail/associated-types-in-ambiguous-context.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ trait Get {
1818
fn get<T:Get,U:Get>(x: T, y: U) -> Get::Value {}
1919
//~^ ERROR ambiguous associated type
2020

21-
trait Other {
22-
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
23-
//~^ ERROR no suitable bound on `Self`
24-
}
25-
26-
impl<T:Get> Other for T {
27-
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
28-
//~^ ERROR currently unsupported
29-
}
30-
3121
trait Grab {
3222
type Value;
3323
fn grab(&self) -> Grab::Value;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 the user gets an errror if they omit a binding from an
12+
// object type.
13+
14+
#![feature(associated_types)]
15+
16+
pub trait Foo {
17+
type A;
18+
type B;
19+
fn boo(&self) -> <Self as Foo>::A;
20+
}
21+
22+
struct Bar;
23+
24+
impl Foo for int {
25+
type A = uint;
26+
type B = char;
27+
fn boo(&self) -> uint {
28+
42
29+
}
30+
}
31+
32+
pub fn main() {
33+
let a = &42i as &Foo<A=uint, B=char>;
34+
35+
let b = &42i as &Foo<A=uint>;
36+
//~^ ERROR the value of the associated type `B` (from the trait `Foo`) must be specified
37+
38+
let c = &42i as &Foo<B=char>;
39+
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
40+
41+
let d = &42i as &Foo;
42+
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
43+
//~| ERROR the value of the associated type `B` (from the trait `Foo`) must be specified
44+
}

branches/try/src/test/compile-fail/associated-types-in-wrong-context.rs renamed to branches/try/src/test/compile-fail/associated-types-no-suitable-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Struct {
2121

2222
impl Struct {
2323
fn uhoh<T>(foo: <T as Get>::Value) {}
24-
//~^ ERROR no suitable bound on `T`
24+
//~^ ERROR the trait `Get` is not implemented for the type `T`
2525
}
2626

2727
fn main() {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(associated_types)]
2+
3+
// Check that we get an error when you use `<Self as Get>::Value` in
4+
// the trait definition but `Self` does not, in fact, implement `Get`.
5+
6+
trait Get {
7+
type Value;
8+
}
9+
10+
trait Other {
11+
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
12+
//~^ ERROR the trait `Get` is not implemented for the type `Self`
13+
}
14+
15+
impl<T:Get> Other for T {
16+
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
17+
//~^ ERROR the trait `Get` is not implemented for the type `(T, U)`
18+
//~| ERROR the trait `Get` is not implemented for the type `(T, U)`
19+
}
20+
21+
fn main() { }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
// Test you can't use a higher-ranked trait bound inside of a qualified
12+
// path (just won't parse).
13+
14+
#![feature(associated_types)]
15+
16+
pub trait Foo<T> {
17+
type A;
18+
19+
fn get(&self, t: T) -> Self::A;
20+
}
21+
22+
fn foo2<I>(x: <I as for<'x> Foo<&'x int>>::A)
23+
//~^ ERROR expected identifier, found keyword `for`
24+
//~| ERROR expected one of `::` or `>`
25+
{
26+
}
27+
28+
pub fn main() {}
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 projection of an associated type out of a higher-ranked
12+
// trait-bound in the context of a function body.
13+
14+
#![feature(associated_types)]
15+
16+
pub trait Foo<T> {
17+
type A;
18+
19+
fn get(&self, t: T) -> Self::A;
20+
}
21+
22+
fn foo<'a, I : for<'x> Foo<&'x int>>(
23+
x: <I as Foo<&'a int>>::A)
24+
{
25+
let y: I::A = x;
26+
}
27+
28+
fn bar<'a, 'b, I : for<'x> Foo<&'x int>>(
29+
x: <I as Foo<&'a int>>::A,
30+
y: <I as Foo<&'b int>>::A,
31+
cond: bool)
32+
{ //~ ERROR cannot infer
33+
// x and y here have two distinct lifetimes:
34+
let z: I::A = if cond { x } else { y };
35+
}
36+
37+
pub fn main() {}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 projection of an associated type out of a higher-ranked trait-bound
12+
// in the context of a function signature.
13+
14+
#![feature(associated_types)]
15+
16+
pub trait Foo<T> {
17+
type A;
18+
19+
fn get(&self, t: T) -> Self::A;
20+
}
21+
22+
fn foo2<I : for<'x> Foo<&'x int>>(
23+
x: I::A)
24+
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
25+
{
26+
// This case is illegal because we have to instantiate `'x`, and
27+
// we don't know what region to instantiate it with.
28+
//
29+
// This could perhaps be made equivalent to the examples below,
30+
// specifically for fn signatures.
31+
}
32+
33+
fn foo3<I : for<'x> Foo<&'x int>>(
34+
x: <I as Foo<&int>>::A)
35+
{
36+
// OK, in this case we spelled out the precise regions involved, though we left one of
37+
// them anonymous.
38+
}
39+
40+
fn foo4<'a, I : for<'x> Foo<&'x int>>(
41+
x: <I as Foo<&'a int>>::A)
42+
{
43+
// OK, in this case we spelled out the precise regions involved.
44+
}
45+
46+
47+
pub fn main() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 projection of an associated type out of a higher-ranked trait-bound
12+
// in the context of a struct definition.
13+
14+
#![feature(associated_types)]
15+
16+
pub trait Foo<T> {
17+
type A;
18+
19+
fn get(&self, t: T) -> Self::A;
20+
}
21+
22+
struct SomeStruct<I : for<'x> Foo<&'x int>> {
23+
field: I::A
24+
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
25+
}
26+
27+
struct AnotherStruct<I : for<'x> Foo<&'x int>> {
28+
field: <I as Foo<&int>>::A
29+
//~^ ERROR missing lifetime specifier
30+
}
31+
32+
struct YetAnotherStruct<'a, I : for<'x> Foo<&'x int>> {
33+
field: <I as Foo<&'a int>>::A
34+
}
35+
36+
pub fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 projection of an associated type out of a higher-ranked trait-bound
12+
// in the context of a method definition in a trait.
13+
14+
#![feature(associated_types)]
15+
16+
pub trait Foo<T> {
17+
type A;
18+
19+
fn get(&self, t: T) -> Self::A;
20+
}
21+
22+
trait SomeTrait<I : for<'x> Foo<&'x int>> {
23+
fn some_method(&self, arg: I::A);
24+
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
25+
}
26+
27+
trait AnotherTrait<I : for<'x> Foo<&'x int>> {
28+
fn some_method(&self, arg: <I as Foo<&int>>::A);
29+
}
30+
31+
trait YetAnotherTrait<I : for<'x> Foo<&'x int>> {
32+
fn some_method<'a>(&self, arg: <I as Foo<&'a int>>::A);
33+
}
34+
35+
pub fn main() {}

branches/try/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ enum Boo {
4141
Quux(Bar<uint>),
4242
}
4343

44-
struct Badness<T> {
44+
struct Badness<U> {
4545
//~^ ERROR not implemented
46-
b: Foo<T>,
46+
b: Foo<U>,
4747
}
4848

49-
enum MoreBadness<T> {
49+
enum MoreBadness<V> {
5050
//~^ ERROR not implemented
51-
EvenMoreBadness(Bar<T>),
51+
EvenMoreBadness(Bar<V>),
5252
}
5353

5454
trait PolyTrait<T> {

0 commit comments

Comments
 (0)