diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-08-07 13:31:42 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-08-12 17:57:58 -0400 |
| commit | 39d164d0421a7560ea1e35a2347fda223cd43f6e (patch) | |
| tree | 138ecaa447ad58e7c1e2068bcd927427236597b4 | |
| parent | 6bb1e2291195a518ddeef6e64337f4edb1432a72 (diff) | |
| download | rust-39d164d0421a7560ea1e35a2347fda223cd43f6e.tar.gz rust-39d164d0421a7560ea1e35a2347fda223cd43f6e.zip | |
New tests --- check that wf relation is being checked in various positions
36 files changed, 985 insertions, 0 deletions
diff --git a/src/test/compile-fail/regions-wf-trait-object.rs b/src/test/compile-fail/regions-wf-trait-object.rs new file mode 100644 index 00000000000..2ad1163052b --- /dev/null +++ b/src/test/compile-fail/regions-wf-trait-object.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms.t + +// Check that the explicit lifetime bound (`'b`, in this example) must +// outlive all the superbound from the trait (`'a`, in this example). + +trait TheTrait<'t>: 't { } + +struct Foo<'a,'b> { + //~^ ERROR lifetime bound not satisfied + x: Box<TheTrait<'a>+'b> +} + +fn main() { } diff --git a/src/test/compile-fail/wf-array-elem-sized.rs b/src/test/compile-fail/wf-array-elem-sized.rs new file mode 100644 index 00000000000..aaae41c7667 --- /dev/null +++ b/src/test/compile-fail/wf-array-elem-sized.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that array elemen types must be Sized. Issue #25692. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct Foo { //~ WARN E0277 + foo: [[u8]], +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-const-type.rs b/src/test/compile-fail/wf-const-type.rs new file mode 100644 index 00000000000..c3015afd8dd --- /dev/null +++ b/src/test/compile-fail/wf-const-type.rs @@ -0,0 +1,24 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check the types of constants are well-formed. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct IsCopy<T:Copy> { t: T } +struct NotCopy; + +const FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None }; +//~^ ERROR E0277 + +#[rustc_error] +fn main() { } diff --git a/src/test/compile-fail/wf-enum-bound.rs b/src/test/compile-fail/wf-enum-bound.rs new file mode 100644 index 00000000000..1d271d1530a --- /dev/null +++ b/src/test/compile-fail/wf-enum-bound.rs @@ -0,0 +1,26 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check enum bounds for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +enum SomeEnum<T,U> //~ WARN E0277 + where T: ExtraCopy<U> +{ + SomeVariant(T,U) +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-enum-fields.rs b/src/test/compile-fail/wf-enum-fields.rs new file mode 100644 index 00000000000..40a93935082 --- /dev/null +++ b/src/test/compile-fail/wf-enum-fields.rs @@ -0,0 +1,32 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check struct fields for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct IsCopy<T:Copy> { + value: T +} + +enum SomeEnum<A> { + SomeVariant(IsCopy<A>) //~ ERROR E0277 +} + +enum AnotherEnum<A> { //~ ERROR E0277 + AnotherVariant { + f: IsCopy<A> + } +} + +#[rustc_error] +fn main() { } diff --git a/src/test/compile-fail/wf-fn-where-clause.rs b/src/test/compile-fail/wf-fn-where-clause.rs new file mode 100644 index 00000000000..769894613c7 --- /dev/null +++ b/src/test/compile-fail/wf-fn-where-clause.rs @@ -0,0 +1,24 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check where-clauses on fn items. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +fn foo<T,U>() where T: ExtraCopy<U> //~ WARN E0277 +{ +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-impl-associated-type-region.rs b/src/test/compile-fail/wf-impl-associated-type-region.rs new file mode 100644 index 00000000000..2d7727fff35 --- /dev/null +++ b/src/test/compile-fail/wf-impl-associated-type-region.rs @@ -0,0 +1,24 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we require that associated types in an impl are well-formed. + +#![feature(rustc_attrs)] + +pub trait Foo<'a> { + type Bar; +} + +impl<'a, T> Foo<'a> for T { + type Bar = &'a T; //~ WARN E0309 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation diff --git a/src/test/compile-fail/wf-impl-associated-type-trait.rs b/src/test/compile-fail/wf-impl-associated-type-trait.rs new file mode 100644 index 00000000000..8a612c32157 --- /dev/null +++ b/src/test/compile-fail/wf-impl-associated-type-trait.rs @@ -0,0 +1,33 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we require that associated types in an impl are well-formed. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +pub trait MyHash { } + +pub struct MySet<T:MyHash> { + data: Vec<T> +} + +pub trait Foo { + type Bar; +} + +impl<T> Foo for T { + type Bar = MySet<T>; + //~^ WARN the trait `MyHash` is not implemented for the type `T` +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful + diff --git a/src/test/compile-fail/wf-in-fn-arg.rs b/src/test/compile-fail/wf-in-fn-arg.rs new file mode 100644 index 00000000000..e302cac0006 --- /dev/null +++ b/src/test/compile-fail/wf-in-fn-arg.rs @@ -0,0 +1,24 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for argument types in fn items. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct MustBeCopy<T:Copy> { + t: T +} + +fn bar<T>(_: &MustBeCopy<T>) //~ ERROR E0277 +{ +} + +fn main() { } diff --git a/src/test/compile-fail/wf-in-fn-ret.rs b/src/test/compile-fail/wf-in-fn-ret.rs new file mode 100644 index 00000000000..719bc9282ad --- /dev/null +++ b/src/test/compile-fail/wf-in-fn-ret.rs @@ -0,0 +1,24 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for return types in fn items. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct MustBeCopy<T:Copy> { + t: T +} + +fn bar<T>() -> MustBeCopy<T> //~ ERROR E0277 +{ +} + +fn main() { } diff --git a/src/test/compile-fail/wf-in-fn-type-arg.rs b/src/test/compile-fail/wf-in-fn-type-arg.rs new file mode 100644 index 00000000000..08ee0e954ac --- /dev/null +++ b/src/test/compile-fail/wf-in-fn-type-arg.rs @@ -0,0 +1,22 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for types in fns. + +struct MustBeCopy<T:Copy> { + t: T +} + +struct Bar<T> { + // needs T: Copy + x: fn(MustBeCopy<T>) //~ ERROR E0277 +} + +fn main() { } diff --git a/src/test/compile-fail/wf-in-fn-type-ret.rs b/src/test/compile-fail/wf-in-fn-type-ret.rs new file mode 100644 index 00000000000..6942f786060 --- /dev/null +++ b/src/test/compile-fail/wf-in-fn-type-ret.rs @@ -0,0 +1,22 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for types in fns. + +struct MustBeCopy<T:Copy> { + t: T +} + +struct Foo<T> { + // needs T: 'static + x: fn() -> MustBeCopy<T> //~ ERROR E0277 +} + +fn main() { } diff --git a/src/test/compile-fail/wf-in-fn-type-static.rs b/src/test/compile-fail/wf-in-fn-type-static.rs new file mode 100644 index 00000000000..08853c69d6d --- /dev/null +++ b/src/test/compile-fail/wf-in-fn-type-static.rs @@ -0,0 +1,32 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions related to regions also for +// types in fns. + +#![allow(dead_code)] +#![feature(rustc_attrs)] + +struct MustBeCopy<T:Copy> { + t: T +} + +struct Foo<T> { //~ WARN E0310 + // needs T: 'static + x: fn() -> &'static T //~ WARN E0310 +} + +struct Bar<T> { //~ WARN E0310 + // needs T: Copy + x: fn(&'static T) //~ WARN E0310 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-in-fn-where-clause.rs b/src/test/compile-fail/wf-in-fn-where-clause.rs new file mode 100644 index 00000000000..fc3d234aac2 --- /dev/null +++ b/src/test/compile-fail/wf-in-fn-where-clause.rs @@ -0,0 +1,25 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for where clauses in fn items. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait MustBeCopy<T:Copy> { +} + +fn bar<T,U>() //~ WARN E0277 + where T: MustBeCopy<U> +{ +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-in-obj-type-static.rs b/src/test/compile-fail/wf-in-obj-type-static.rs new file mode 100644 index 00000000000..36c8f5be308 --- /dev/null +++ b/src/test/compile-fail/wf-in-obj-type-static.rs @@ -0,0 +1,28 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for types in fns. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait Object<T> { } + +struct MustBeCopy<T:Copy> { + t: T +} + +struct Foo<T> { //~ WARN E0310 + // needs T: 'static + x: Object<&'static T> //~ WARN E0310 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-in-obj-type-trait.rs b/src/test/compile-fail/wf-in-obj-type-trait.rs new file mode 100644 index 00000000000..add48219c1d --- /dev/null +++ b/src/test/compile-fail/wf-in-obj-type-trait.rs @@ -0,0 +1,24 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we enforce WF conditions also for types in fns. + +trait Object<T> { } + +struct MustBeCopy<T:Copy> { + t: T +} + +struct Bar<T> { + // needs T: Copy + x: Object<MustBeCopy<T>> //~ ERROR E0277 +} + +fn main() { } diff --git a/src/test/compile-fail/wf-inherent-impl-method-where-clause.rs b/src/test/compile-fail/wf-inherent-impl-method-where-clause.rs new file mode 100644 index 00000000000..44671be8355 --- /dev/null +++ b/src/test/compile-fail/wf-inherent-impl-method-where-clause.rs @@ -0,0 +1,27 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check where-clauses on inherent impl methods. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +struct Foo<T,U>(T,U); + +impl<T,U> Foo<T,U> { + fn foo(self) where T: ExtraCopy<U> //~ WARN E0277 + {} +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-inherent-impl-where-clause.rs b/src/test/compile-fail/wf-inherent-impl-where-clause.rs new file mode 100644 index 00000000000..a0f588c1961 --- /dev/null +++ b/src/test/compile-fail/wf-inherent-impl-where-clause.rs @@ -0,0 +1,26 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check where-clauses on inherent impls. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +struct Foo<T,U>(T,U); + +impl<T,U> Foo<T,U> where T: ExtraCopy<U> //~ WARN E0277 +{ +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-object-safe.rs b/src/test/compile-fail/wf-object-safe.rs new file mode 100644 index 00000000000..92c0a8c5be8 --- /dev/null +++ b/src/test/compile-fail/wf-object-safe.rs @@ -0,0 +1,20 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that object-safe traits are not WF when used as object types. +// Issue #21953. + +trait A { + fn foo(&self, _x: &Self); +} + +fn main() { + let _x: &A; //~ ERROR E0038 +} diff --git a/src/test/compile-fail/wf-outlives-ty-in-fn-or-trait.rs b/src/test/compile-fail/wf-outlives-ty-in-fn-or-trait.rs new file mode 100644 index 00000000000..eca128f4a13 --- /dev/null +++ b/src/test/compile-fail/wf-outlives-ty-in-fn-or-trait.rs @@ -0,0 +1,34 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that an appearance of `T` in fn args or in a trait object must +// still meet the outlives bounds. Since this is a new requirement, +// this is currently only a warning, not a hard error. + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait Trait<T> { } + +struct Foo<'a,T> { + //~^ WARN E0309 + f: &'a fn(T), + //~^ WARN E0309 +} + +struct Bar<'a,T> { + //~^ WARN E0309 + f: &'a Trait<T>, + //~^ WARN E0309 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful + diff --git a/src/test/compile-fail/wf-static-type.rs b/src/test/compile-fail/wf-static-type.rs new file mode 100644 index 00000000000..ba02c5dca3e --- /dev/null +++ b/src/test/compile-fail/wf-static-type.rs @@ -0,0 +1,24 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check the types of statics are well-formed. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct IsCopy<T:Copy> { t: T } +struct NotCopy; + +static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None }; +//~^ ERROR E0277 + +#[rustc_error] +fn main() { } diff --git a/src/test/compile-fail/wf-struct-bound.rs b/src/test/compile-fail/wf-struct-bound.rs new file mode 100644 index 00000000000..43378061e40 --- /dev/null +++ b/src/test/compile-fail/wf-struct-bound.rs @@ -0,0 +1,26 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check struct bounds for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +struct SomeStruct<T,U> //~ WARN E0277 + where T: ExtraCopy<U> +{ + data: (T,U) +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-struct-field.rs b/src/test/compile-fail/wf-struct-field.rs new file mode 100644 index 00000000000..8a631a6c335 --- /dev/null +++ b/src/test/compile-fail/wf-struct-field.rs @@ -0,0 +1,26 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check struct fields for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct IsCopy<T:Copy> { + value: T +} + +struct SomeStruct<A> { + data: IsCopy<A> //~ ERROR E0277 +} + +#[rustc_error] +fn main() { } diff --git a/src/test/compile-fail/wf-trait-associated-type-bound.rs b/src/test/compile-fail/wf-trait-associated-type-bound.rs new file mode 100644 index 00000000000..63a532138e3 --- /dev/null +++ b/src/test/compile-fail/wf-trait-associated-type-bound.rs @@ -0,0 +1,24 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check associated type bounds for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +trait SomeTrait<T> { //~ WARN E0277 + type Type1: ExtraCopy<T>; +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-associated-type-region.rs b/src/test/compile-fail/wf-trait-associated-type-region.rs new file mode 100644 index 00000000000..b3aa4e19c96 --- /dev/null +++ b/src/test/compile-fail/wf-trait-associated-type-region.rs @@ -0,0 +1,24 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check associated type default values for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait SomeTrait<'a> { + type Type1; + type Type2 = &'a Self::Type1; + //~^ WARN E0309 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-associated-type-trait b/src/test/compile-fail/wf-trait-associated-type-trait new file mode 100755 index 00000000000..a11cbc2cb19 --- /dev/null +++ b/src/test/compile-fail/wf-trait-associated-type-trait Binary files differdiff --git a/src/test/compile-fail/wf-trait-associated-type-trait.rs b/src/test/compile-fail/wf-trait-associated-type-trait.rs new file mode 100644 index 00000000000..8c491e04c98 --- /dev/null +++ b/src/test/compile-fail/wf-trait-associated-type-trait.rs @@ -0,0 +1,26 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check associated type default values for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct IsCopy<T:Copy> { x: T } + +trait SomeTrait { + type Type1; + type Type2 = IsCopy<Self::Type1>; + //~^ WARN E0277 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-bound.rs b/src/test/compile-fail/wf-trait-bound.rs new file mode 100644 index 00000000000..147b3ce236d --- /dev/null +++ b/src/test/compile-fail/wf-trait-bound.rs @@ -0,0 +1,25 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check supertrait bounds for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +trait SomeTrait<T,U> //~ WARN E0277 + where T: ExtraCopy<U> +{ +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-default-fn-arg.rs b/src/test/compile-fail/wf-trait-default-fn-arg.rs new file mode 100644 index 00000000000..57c6c1979f8 --- /dev/null +++ b/src/test/compile-fail/wf-trait-default-fn-arg.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we test WF conditions for fn arguments. Because the +// current code is so goofy, this is only a warning for now. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +struct Bar<T:Eq+?Sized> { value: Box<T> } + +trait Foo { + fn bar(&self, x: &Bar<Self>) { + //~^ WARN E0277 + // + // Here, Eq ought to be implemented. + } +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-default-fn-ret.rs b/src/test/compile-fail/wf-trait-default-fn-ret.rs new file mode 100644 index 00000000000..939876403e5 --- /dev/null +++ b/src/test/compile-fail/wf-trait-default-fn-ret.rs @@ -0,0 +1,30 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we test WF conditions for fn arguments. Because the +// current code is so goofy, this is only a warning for now. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +struct Bar<T:Eq+?Sized> { value: Box<T> } + +trait Foo { + fn bar(&self) -> Bar<Self> { + //~^ WARN E0277 + // + // Here, Eq ought to be implemented. + loop { } + } +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-default-fn-where-clause.rs b/src/test/compile-fail/wf-trait-default-fn-where-clause.rs new file mode 100644 index 00000000000..b1c0d71fc5b --- /dev/null +++ b/src/test/compile-fail/wf-trait-default-fn-where-clause.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we test WF conditions for fn arguments. Because the +// current code is so goofy, this is only a warning for now. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +trait Bar<T:Eq+?Sized> { } + +trait Foo { + fn bar<A>(&self) where A: Bar<Self> { + //~^ WARN E0277 + // + // Here, Eq ought to be implemented. + } +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-fn-arg.rs b/src/test/compile-fail/wf-trait-fn-arg.rs new file mode 100644 index 00000000000..ff263c85eb3 --- /dev/null +++ b/src/test/compile-fail/wf-trait-fn-arg.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we test WF conditions for fn arguments in a trait definition. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +struct Bar<T:Eq+?Sized> { value: Box<T> } + +trait Foo { + fn bar(&self, x: &Bar<Self>); + //~^ WARN E0277 + // + // Here, Eq ought to be implemented. +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-fn-ret.rs b/src/test/compile-fail/wf-trait-fn-ret.rs new file mode 100644 index 00000000000..5c8f3030c2c --- /dev/null +++ b/src/test/compile-fail/wf-trait-fn-ret.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we test WF conditions for fn return types in a trait definition. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +struct Bar<T:Eq+?Sized> { value: Box<T> } + +trait Foo { + fn bar(&self) -> &Bar<Self>; + //~^ WARN E0277 + // + // Here, Eq ought to be implemented. +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-fn-where-clause.rs b/src/test/compile-fail/wf-trait-fn-where-clause.rs new file mode 100644 index 00000000000..51b5475e51f --- /dev/null +++ b/src/test/compile-fail/wf-trait-fn-where-clause.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we test WF conditions for fn where clauses in a trait definition. + +#![feature(rustc_attrs)] +#![allow(dead_code)] +#![allow(unused_variables)] + +struct Bar<T:Eq+?Sized> { value: Box<T> } + +trait Foo { + fn bar(&self) where Bar<Self>: Copy; + //~^ WARN E0277 + // + // Here, Eq ought to be implemented. +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/wf-trait-superbound.rs b/src/test/compile-fail/wf-trait-superbound.rs new file mode 100644 index 00000000000..58ee766dad1 --- /dev/null +++ b/src/test/compile-fail/wf-trait-superbound.rs @@ -0,0 +1,23 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we check supertrait bounds for WFedness. + +#![feature(associated_type_defaults)] +#![feature(rustc_attrs)] +#![allow(dead_code)] + +trait ExtraCopy<T:Copy> { } + +trait SomeTrait<T>: ExtraCopy<T> { //~ WARN E0277 +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/run-pass/project-defer-unification.rs b/src/test/run-pass/project-defer-unification.rs new file mode 100644 index 00000000000..9a6ea2272fe --- /dev/null +++ b/src/test/run-pass/project-defer-unification.rs @@ -0,0 +1,105 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// A regression test extracted from image-0.3.11. The point of +// failure was in `index_colors` below. + +use std::ops::{Deref, DerefMut}; + +#[derive(Copy, Clone)] +pub struct Luma<T: Primitive> { pub data: [T; 1] } + +impl<T: Primitive + 'static> Pixel for Luma<T> { + type Subpixel = T; +} + +pub struct ImageBuffer<P: Pixel, Container> { + pixels: P, + c: Container, +} + +pub trait GenericImage: Sized { + type Pixel: Pixel; +} + +pub trait Pixel: Copy + Clone { + type Subpixel: Primitive; +} + +pub trait Primitive: Copy + PartialOrd<Self> + Clone { +} + +impl<P, Container> GenericImage for ImageBuffer<P, Container> +where P: Pixel + 'static, + Container: Deref<Target=[P::Subpixel]> + DerefMut, + P::Subpixel: 'static { + + type Pixel = P; +} + +impl Primitive for u8 { } + +impl<P, Container> ImageBuffer<P, Container> +where P: Pixel + 'static, + P::Subpixel: 'static, + Container: Deref<Target=[P::Subpixel]> +{ + pub fn pixels<'a>(&'a self) -> Pixels<'a, Self> { + loop { } + } + + pub fn pixels_mut(&mut self) -> PixelsMut<P> { + loop { } + } +} + +pub struct Pixels<'a, I: 'a> { + image: &'a I, + x: u32, + y: u32, + width: u32, + height: u32 +} + +impl<'a, I: GenericImage> Iterator for Pixels<'a, I> { + type Item = (u32, u32, I::Pixel); + + fn next(&mut self) -> Option<(u32, u32, I::Pixel)> { + loop { } + } +} + +pub struct PixelsMut<'a, P: Pixel + 'a> where P::Subpixel: 'a { + chunks: &'a mut P::Subpixel +} + +impl<'a, P: Pixel + 'a> Iterator for PixelsMut<'a, P> where P::Subpixel: 'a { + type Item = &'a mut P; + + fn next(&mut self) -> Option<&'a mut P> { + loop { } + } +} + +pub fn index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>) + -> ImageBuffer<Luma<u8>, Vec<u8>> +where Pix: Pixel<Subpixel=u8> + 'static, +{ + let mut indices: ImageBuffer<_,Vec<_>> = loop { }; + for (pixel, idx) in image.pixels().zip(indices.pixels_mut()) { + // failured occurred here ^^ because we were requiring that we + // could project Pixel or Subpixel from `T_indices` (type of + // `indices`), but the type is insufficiently constrained + // until we reach the return below. + } + indices +} + +fn main() { } |
