New tests --- check that wf relation is being checked in various positions

This commit is contained in:
Niko Matsakis 2015-08-07 13:31:42 -04:00
parent 6bb1e22911
commit 39d164d042
36 changed files with 985 additions and 0 deletions

View file

@ -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() { }

View file

@ -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

View file

@ -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() { }

View file

@ -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

View file

@ -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() { }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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() { }

View file

@ -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() { }

View file

@ -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() { }

View file

@ -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() { }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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() { }

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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() { }

View file

@ -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

View file

@ -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() { }

View file

@ -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

View file

@ -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

Binary file not shown.

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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() { }