diff --git a/src/test/compile-fail/associated-types-eq-2.rs b/src/test/compile-fail/associated-types-eq-2.rs index 652bf4fb577..b89cdd8c0ee 100644 --- a/src/test/compile-fail/associated-types-eq-2.rs +++ b/src/test/compile-fail/associated-types-eq-2.rs @@ -25,6 +25,7 @@ impl Foo for int { fn boo(&self) -> uint { 42 } } -fn baz(x: &>::A) {} //~ERROR equality constraints are not allowed in this +fn baz(x: &>::A) {} +//~^ ERROR associated type bindings are not allowed here pub fn main() {} diff --git a/src/test/compile-fail/associated-types-eq-3.rs b/src/test/compile-fail/associated-types-eq-3.rs index 880b2e9cc4a..e5974925d73 100644 --- a/src/test/compile-fail/associated-types-eq-3.rs +++ b/src/test/compile-fail/associated-types-eq-3.rs @@ -43,6 +43,6 @@ pub fn baz(x: &Foo) { pub fn main() { let a = 42i; - foo1(a); //~ERROR the trait `Foo` is not implemented for the type `int` - baz(&a); //~ERROR the trait `Foo` is not implemented for the type `int` + foo1(a); //~ERROR expected uint, found struct Bar + baz(&a); //~ERROR expected uint, found struct Bar } diff --git a/src/test/compile-fail/associated-types-eq-hr.rs b/src/test/compile-fail/associated-types-eq-hr.rs new file mode 100644 index 00000000000..aad55745c25 --- /dev/null +++ b/src/test/compile-fail/associated-types-eq-hr.rs @@ -0,0 +1,72 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check testing of equality constraints in a higher-ranked context. + +#![feature(associated_types)] + +pub trait TheTrait { + type A; + + fn get(&self, t: T) -> Self::A; +} + +struct IntStruct { + x: int +} + +impl<'a> TheTrait<&'a int> for IntStruct { + type A = &'a int; + + fn get(&self, t: &'a int) -> &'a int { + t + } +} + +struct UintStruct { + x: int +} + +impl<'a> TheTrait<&'a int> for UintStruct { + type A = &'a uint; + + fn get(&self, t: &'a int) -> &'a uint { + panic!() + } +} + +fn foo() + where T : for<'x> TheTrait<&'x int, A = &'x int> +{ + // ok for IntStruct, but not UintStruct +} + +fn bar() + where T : for<'x> TheTrait<&'x int, A = &'x uint> +{ + // ok for UintStruct, but not IntStruct +} + +fn baz() + where T : for<'x,'y> TheTrait<&'x int, A = &'y int> +{ + // not ok for either struct, due to the use of two lifetimes +} + +pub fn main() { + foo::(); + foo::(); //~ ERROR type mismatch + + bar::(); //~ ERROR type mismatch + bar::(); + + baz::(); //~ ERROR type mismatch + baz::(); //~ ERROR type mismatch +} diff --git a/src/test/compile-fail/associated-types-in-ambiguous-context.rs b/src/test/compile-fail/associated-types-in-ambiguous-context.rs index 24de1fa2f78..fcd3e4d1636 100644 --- a/src/test/compile-fail/associated-types-in-ambiguous-context.rs +++ b/src/test/compile-fail/associated-types-in-ambiguous-context.rs @@ -18,16 +18,6 @@ trait Get { fn get(x: T, y: U) -> Get::Value {} //~^ ERROR ambiguous associated type -trait Other { - fn uhoh(&self, foo: U, bar: ::Value) {} - //~^ ERROR no suitable bound on `Self` -} - -impl Other for T { - fn uhoh(&self, foo: U, bar: <(T, U) as Get>::Value) {} - //~^ ERROR currently unsupported -} - trait Grab { type Value; fn grab(&self) -> Grab::Value; diff --git a/src/test/compile-fail/associated-types-incomplete-object.rs b/src/test/compile-fail/associated-types-incomplete-object.rs new file mode 100644 index 00000000000..7e4e1315110 --- /dev/null +++ b/src/test/compile-fail/associated-types-incomplete-object.rs @@ -0,0 +1,44 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that the user gets an errror if they omit a binding from an +// object type. + +#![feature(associated_types)] + +pub trait Foo { + type A; + type B; + fn boo(&self) -> ::A; +} + +struct Bar; + +impl Foo for int { + type A = uint; + type B = char; + fn boo(&self) -> uint { + 42 + } +} + +pub fn main() { + let a = &42i as &Foo; + + let b = &42i as &Foo; + //~^ ERROR the value of the associated type `B` (from the trait `Foo`) must be specified + + let c = &42i as &Foo; + //~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified + + let d = &42i as &Foo; + //~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified + //~| ERROR the value of the associated type `B` (from the trait `Foo`) must be specified +} diff --git a/src/test/compile-fail/associated-types-in-wrong-context.rs b/src/test/compile-fail/associated-types-no-suitable-bound.rs similarity index 90% rename from src/test/compile-fail/associated-types-in-wrong-context.rs rename to src/test/compile-fail/associated-types-no-suitable-bound.rs index 28a4ad01e23..6b856204091 100644 --- a/src/test/compile-fail/associated-types-in-wrong-context.rs +++ b/src/test/compile-fail/associated-types-no-suitable-bound.rs @@ -21,7 +21,7 @@ struct Struct { impl Struct { fn uhoh(foo: ::Value) {} - //~^ ERROR no suitable bound on `T` + //~^ ERROR the trait `Get` is not implemented for the type `T` } fn main() { diff --git a/src/test/compile-fail/associated-types-no-suitable-supertrait.rs b/src/test/compile-fail/associated-types-no-suitable-supertrait.rs new file mode 100644 index 00000000000..c4110a6946d --- /dev/null +++ b/src/test/compile-fail/associated-types-no-suitable-supertrait.rs @@ -0,0 +1,21 @@ +#![feature(associated_types)] + +// Check that we get an error when you use `::Value` in +// the trait definition but `Self` does not, in fact, implement `Get`. + +trait Get { + type Value; +} + +trait Other { + fn uhoh(&self, foo: U, bar: ::Value) {} + //~^ ERROR the trait `Get` is not implemented for the type `Self` +} + +impl Other for T { + fn uhoh(&self, foo: U, bar: <(T, U) as Get>::Value) {} + //~^ ERROR the trait `Get` is not implemented for the type `(T, U)` + //~| ERROR the trait `Get` is not implemented for the type `(T, U)` +} + +fn main() { } diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs b/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs new file mode 100644 index 00000000000..1f0f044a4c0 --- /dev/null +++ b/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs @@ -0,0 +1,28 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test you can't use a higher-ranked trait bound inside of a qualified +// path (just won't parse). + +#![feature(associated_types)] + +pub trait Foo { + type A; + + fn get(&self, t: T) -> Self::A; +} + +fn foo2(x: Foo<&'x int>>::A) + //~^ ERROR expected identifier, found keyword `for` + //~| ERROR expected one of `::` or `>` +{ +} + +pub fn main() {} diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn new file mode 100755 index 00000000000..6d2392c124b Binary files /dev/null and b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn differ diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs new file mode 100644 index 00000000000..8cdca50d9b6 --- /dev/null +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs @@ -0,0 +1,37 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check projection of an associated type out of a higher-ranked +// trait-bound in the context of a function body. + +#![feature(associated_types)] + +pub trait Foo { + type A; + + fn get(&self, t: T) -> Self::A; +} + +fn foo<'a, I : for<'x> Foo<&'x int>>( + x: >::A) +{ + let y: I::A = x; +} + +fn bar<'a, 'b, I : for<'x> Foo<&'x int>>( + x: >::A, + y: >::A, + cond: bool) +{ //~ ERROR cannot infer + // x and y here have two distinct lifetimes: + let z: I::A = if cond { x } else { y }; +} + +pub fn main() {} diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs new file mode 100644 index 00000000000..0d5c6959142 --- /dev/null +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs @@ -0,0 +1,47 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check projection of an associated type out of a higher-ranked trait-bound +// in the context of a function signature. + +#![feature(associated_types)] + +pub trait Foo { + type A; + + fn get(&self, t: T) -> Self::A; +} + +fn foo2 Foo<&'x int>>( + x: I::A) + //~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context +{ + // This case is illegal because we have to instantiate `'x`, and + // we don't know what region to instantiate it with. + // + // This could perhaps be made equivalent to the examples below, + // specifically for fn signatures. +} + +fn foo3 Foo<&'x int>>( + x: >::A) +{ + // OK, in this case we spelled out the precise regions involved, though we left one of + // them anonymous. +} + +fn foo4<'a, I : for<'x> Foo<&'x int>>( + x: >::A) +{ + // OK, in this case we spelled out the precise regions involved. +} + + +pub fn main() {} diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs new file mode 100644 index 00000000000..5016c6448a5 --- /dev/null +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs @@ -0,0 +1,36 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check projection of an associated type out of a higher-ranked trait-bound +// in the context of a struct definition. + +#![feature(associated_types)] + +pub trait Foo { + type A; + + fn get(&self, t: T) -> Self::A; +} + +struct SomeStruct Foo<&'x int>> { + field: I::A + //~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context +} + +struct AnotherStruct Foo<&'x int>> { + field: >::A + //~^ ERROR missing lifetime specifier +} + +struct YetAnotherStruct<'a, I : for<'x> Foo<&'x int>> { + field: >::A +} + +pub fn main() {} diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs new file mode 100644 index 00000000000..a92d4ec04cb --- /dev/null +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs @@ -0,0 +1,35 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check projection of an associated type out of a higher-ranked trait-bound +// in the context of a method definition in a trait. + +#![feature(associated_types)] + +pub trait Foo { + type A; + + fn get(&self, t: T) -> Self::A; +} + +trait SomeTrait Foo<&'x int>> { + fn some_method(&self, arg: I::A); + //~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context +} + +trait AnotherTrait Foo<&'x int>> { + fn some_method(&self, arg: >::A); +} + +trait YetAnotherTrait Foo<&'x int>> { + fn some_method<'a>(&self, arg: >::A); +} + +pub fn main() {} diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs index 5fe8e435e68..c11b5d22878 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs @@ -41,14 +41,14 @@ enum Boo { Quux(Bar), } -struct Badness { +struct Badness { //~^ ERROR not implemented - b: Foo, + b: Foo, } -enum MoreBadness { +enum MoreBadness { //~^ ERROR not implemented - EvenMoreBadness(Bar), + EvenMoreBadness(Bar), } trait PolyTrait { diff --git a/src/test/compile-fail/unsized-inherent-impl-self-type.rs b/src/test/compile-fail/unsized-inherent-impl-self-type.rs new file mode 100644 index 00000000000..2c8a2b361d5 --- /dev/null +++ b/src/test/compile-fail/unsized-inherent-impl-self-type.rs @@ -0,0 +1,20 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test sized-ness checking in substitution in impls. + +// impl - struct + +struct S5; + +impl S5 { //~ ERROR not implemented +} + +fn main() { } diff --git a/src/test/compile-fail/unsized-trait-impl-self-type.rs b/src/test/compile-fail/unsized-trait-impl-self-type.rs new file mode 100644 index 00000000000..0f0a97fab4d --- /dev/null +++ b/src/test/compile-fail/unsized-trait-impl-self-type.rs @@ -0,0 +1,22 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test sized-ness checking in substitution in impls. + +// impl - struct +trait T3 { +} + +struct S5; + +impl T3 for S5 { //~ ERROR not implemented +} + +fn main() { } diff --git a/src/test/compile-fail/unsized-trait-impl-trait-arg.rs b/src/test/compile-fail/unsized-trait-impl-trait-arg.rs new file mode 100644 index 00000000000..bdb652b168a --- /dev/null +++ b/src/test/compile-fail/unsized-trait-impl-trait-arg.rs @@ -0,0 +1,21 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test sized-ness checking in substitution in impls. + +// impl - unbounded +trait T2 { +} +struct S4; +impl T2 for S4 { + //~^ ERROR `core::kinds::Sized` is not implemented for the type `X` +} + +fn main() { } diff --git a/src/test/compile-fail/unsized4.rs b/src/test/compile-fail/unsized4.rs index 253ec2a84ea..0537fc1f94a 100644 --- a/src/test/compile-fail/unsized4.rs +++ b/src/test/compile-fail/unsized4.rs @@ -13,7 +13,7 @@ trait T {} fn f() { -//~^ERROR incompatible bounds on type parameter `Y`, bound `T` does not allow unsized type +//~^ERROR incompatible bounds on `Y`, bound `T` does not allow unsized type } pub fn main() { diff --git a/src/test/compile-fail/unsized7.rs b/src/test/compile-fail/unsized7.rs index fd9dffe00d2..c0e6ae1db92 100644 --- a/src/test/compile-fail/unsized7.rs +++ b/src/test/compile-fail/unsized7.rs @@ -21,23 +21,4 @@ impl T1 for S3 { //~^ ERROR `core::kinds::Sized` is not implemented for the type `X` } -// impl - unbounded -trait T2 { -} -struct S4; -impl T2 for S4 { - //~^ ERROR `core::kinds::Sized` is not implemented for the type `X` -} - -// impl - struct -trait T3 { -} -struct S5; -impl T3 for S5 { //~ ERROR not implemented -} - -impl S5 { //~ ERROR not implemented -} - - fn main() { } diff --git a/src/test/compile-fail/issue-19081.rs b/src/test/run-pass/issue-19081.rs similarity index 83% rename from src/test/compile-fail/issue-19081.rs rename to src/test/run-pass/issue-19081.rs index 2f42dbd77fd..aeb14087477 100644 --- a/src/test/compile-fail/issue-19081.rs +++ b/src/test/run-pass/issue-19081.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-pretty -- currently pretty prints as `Hash<::State //~ ERROR no suitable bound on `Self` + ::State >>(&self, value: &T) -> u64; } diff --git a/src/test/compile-fail/issue-19121.rs b/src/test/run-pass/issue-19121.rs similarity index 83% rename from src/test/compile-fail/issue-19121.rs rename to src/test/run-pass/issue-19121.rs index 998c6a82535..79afb856be2 100644 --- a/src/test/compile-fail/issue-19121.rs +++ b/src/test/run-pass/issue-19121.rs @@ -17,6 +17,8 @@ trait Foo { type A; } -fn bar(x: &Foo) {} //~ERROR missing type for associated type `A` +fn bar(x: &Foo) {} +// FIXME(#19482) -- `Foo` should specify `A`, but this is not +// currently enforced except at object creation pub fn main() {}