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 or the MIT license +// , 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+'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 or the MIT license +// , 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 or the MIT license +// , 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: T } +struct NotCopy; + +const FOO: IsCopy> = 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 or the MIT license +// , 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 { } + +enum SomeEnum //~ WARN E0277 + where T: ExtraCopy +{ + 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 or the MIT license +// , 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 { + value: T +} + +enum SomeEnum { + SomeVariant(IsCopy) //~ ERROR E0277 +} + +enum AnotherEnum { //~ ERROR E0277 + AnotherVariant { + f: IsCopy + } +} + +#[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 or the MIT license +// , 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 { } + +fn foo() where T: ExtraCopy //~ 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 or the MIT license +// , 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 or the MIT license +// , 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 { + data: Vec +} + +pub trait Foo { + type Bar; +} + +impl Foo for T { + type Bar = MySet; + //~^ 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 or the MIT license +// , 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: T +} + +fn bar(_: &MustBeCopy) //~ 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 or the MIT license +// , 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: T +} + +fn bar() -> MustBeCopy //~ 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 or the MIT license +// , 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: T +} + +struct Bar { + // needs T: Copy + x: fn(MustBeCopy) //~ 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 or the MIT license +// , 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: T +} + +struct Foo { + // needs T: 'static + x: fn() -> MustBeCopy //~ 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 or the MIT license +// , 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: T +} + +struct Foo { //~ WARN E0310 + // needs T: 'static + x: fn() -> &'static T //~ WARN E0310 +} + +struct Bar { //~ 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 or the MIT license +// , 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 { +} + +fn bar() //~ WARN E0277 + where T: MustBeCopy +{ +} + +#[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 or the MIT license +// , 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 { } + +struct MustBeCopy { + t: T +} + +struct Foo { //~ 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 or the MIT license +// , 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 { } + +struct MustBeCopy { + t: T +} + +struct Bar { + // needs T: Copy + x: Object> //~ 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 or the MIT license +// , 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 { } + +struct Foo(T,U); + +impl Foo { + fn foo(self) where T: ExtraCopy //~ 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 or the MIT license +// , 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 { } + +struct Foo(T,U); + +impl Foo where T: ExtraCopy //~ 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 or the MIT license +// , 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 or the MIT license +// , 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 { } + +struct Foo<'a,T> { + //~^ WARN E0309 + f: &'a fn(T), + //~^ WARN E0309 +} + +struct Bar<'a,T> { + //~^ WARN E0309 + f: &'a Trait, + //~^ 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 or the MIT license +// , 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: T } +struct NotCopy; + +static FOO: IsCopy> = 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 or the MIT license +// , 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 { } + +struct SomeStruct //~ WARN E0277 + where T: ExtraCopy +{ + 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 or the MIT license +// , 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 { + value: T +} + +struct SomeStruct { + data: IsCopy //~ 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 or the MIT license +// , 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 { } + +trait SomeTrait { //~ WARN E0277 + type Type1: ExtraCopy; +} + +#[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 or the MIT license +// , 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 Binary files /dev/null and b/src/test/compile-fail/wf-trait-associated-type-trait differ diff --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 or the MIT license +// , 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 { x: T } + +trait SomeTrait { + type Type1; + type Type2 = IsCopy; + //~^ 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 or the MIT license +// , 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 { } + +trait SomeTrait //~ WARN E0277 + where T: ExtraCopy +{ +} + +#[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 or the MIT license +// , 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 { value: Box } + +trait Foo { + fn bar(&self, x: &Bar) { + //~^ 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 or the MIT license +// , 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 { value: Box } + +trait Foo { + fn bar(&self) -> Bar { + //~^ 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 or the MIT license +// , 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 { } + +trait Foo { + fn bar(&self) where A: Bar { + //~^ 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 or the MIT license +// , 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 { value: Box } + +trait Foo { + fn bar(&self, x: &Bar); + //~^ 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 or the MIT license +// , 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 { value: Box } + +trait Foo { + fn bar(&self) -> &Bar; + //~^ 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 or the MIT license +// , 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 { value: Box } + +trait Foo { + fn bar(&self) where Bar: 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 or the MIT license +// , 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 { } + +trait SomeTrait: ExtraCopy { //~ 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 or the MIT license +// , 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 { pub data: [T; 1] } + +impl Pixel for Luma { + type Subpixel = T; +} + +pub struct ImageBuffer { + pixels: P, + c: Container, +} + +pub trait GenericImage: Sized { + type Pixel: Pixel; +} + +pub trait Pixel: Copy + Clone { + type Subpixel: Primitive; +} + +pub trait Primitive: Copy + PartialOrd + Clone { +} + +impl GenericImage for ImageBuffer +where P: Pixel + 'static, + Container: Deref + DerefMut, + P::Subpixel: 'static { + + type Pixel = P; +} + +impl Primitive for u8 { } + +impl ImageBuffer +where P: Pixel + 'static, + P::Subpixel: 'static, + Container: Deref +{ + pub fn pixels<'a>(&'a self) -> Pixels<'a, Self> { + loop { } + } + + pub fn pixels_mut(&mut self) -> PixelsMut

{ + 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(image: &ImageBuffer>) + -> ImageBuffer, Vec> +where Pix: Pixel + '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() { }