Skip to content

Commit 39d164d

Browse files
committed
New tests --- check that wf relation is being checked in various positions
1 parent 6bb1e22 commit 39d164d

36 files changed

+985
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.t
10+
11+
// Check that the explicit lifetime bound (`'b`, in this example) must
12+
// outlive all the superbound from the trait (`'a`, in this example).
13+
14+
trait TheTrait<'t>: 't { }
15+
16+
struct Foo<'a,'b> {
17+
//~^ ERROR lifetime bound not satisfied
18+
x: Box<TheTrait<'a>+'b>
19+
}
20+
21+
fn main() { }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that array elemen types must be Sized. Issue #25692.
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
struct Foo { //~ WARN E0277
17+
foo: [[u8]],
18+
}
19+
20+
#[rustc_error]
21+
fn main() { } //~ ERROR compilation successful
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we check the types of constants are well-formed.
12+
13+
#![feature(associated_type_defaults)]
14+
#![feature(rustc_attrs)]
15+
#![allow(dead_code)]
16+
17+
struct IsCopy<T:Copy> { t: T }
18+
struct NotCopy;
19+
20+
const FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None };
21+
//~^ ERROR E0277
22+
23+
#[rustc_error]
24+
fn main() { }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we check enum bounds for WFedness.
12+
13+
#![feature(associated_type_defaults)]
14+
#![feature(rustc_attrs)]
15+
#![allow(dead_code)]
16+
17+
trait ExtraCopy<T:Copy> { }
18+
19+
enum SomeEnum<T,U> //~ WARN E0277
20+
where T: ExtraCopy<U>
21+
{
22+
SomeVariant(T,U)
23+
}
24+
25+
#[rustc_error]
26+
fn main() { } //~ ERROR compilation successful
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we check struct fields for WFedness.
12+
13+
#![feature(associated_type_defaults)]
14+
#![feature(rustc_attrs)]
15+
#![allow(dead_code)]
16+
17+
struct IsCopy<T:Copy> {
18+
value: T
19+
}
20+
21+
enum SomeEnum<A> {
22+
SomeVariant(IsCopy<A>) //~ ERROR E0277
23+
}
24+
25+
enum AnotherEnum<A> { //~ ERROR E0277
26+
AnotherVariant {
27+
f: IsCopy<A>
28+
}
29+
}
30+
31+
#[rustc_error]
32+
fn main() { }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we check where-clauses on fn items.
12+
13+
#![feature(associated_type_defaults)]
14+
#![feature(rustc_attrs)]
15+
#![allow(dead_code)]
16+
17+
trait ExtraCopy<T:Copy> { }
18+
19+
fn foo<T,U>() where T: ExtraCopy<U> //~ WARN E0277
20+
{
21+
}
22+
23+
#[rustc_error]
24+
fn main() { } //~ ERROR compilation successful
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we require that associated types in an impl are well-formed.
12+
13+
#![feature(rustc_attrs)]
14+
15+
pub trait Foo<'a> {
16+
type Bar;
17+
}
18+
19+
impl<'a, T> Foo<'a> for T {
20+
type Bar = &'a T; //~ WARN E0309
21+
}
22+
23+
#[rustc_error]
24+
fn main() { } //~ ERROR compilation
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we require that associated types in an impl are well-formed.
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
pub trait MyHash { }
17+
18+
pub struct MySet<T:MyHash> {
19+
data: Vec<T>
20+
}
21+
22+
pub trait Foo {
23+
type Bar;
24+
}
25+
26+
impl<T> Foo for T {
27+
type Bar = MySet<T>;
28+
//~^ WARN the trait `MyHash` is not implemented for the type `T`
29+
}
30+
31+
#[rustc_error]
32+
fn main() { } //~ ERROR compilation successful
33+

src/test/compile-fail/wf-in-fn-arg.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions also for argument types in fn items.
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
struct MustBeCopy<T:Copy> {
17+
t: T
18+
}
19+
20+
fn bar<T>(_: &MustBeCopy<T>) //~ ERROR E0277
21+
{
22+
}
23+
24+
fn main() { }

src/test/compile-fail/wf-in-fn-ret.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions also for return types in fn items.
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
struct MustBeCopy<T:Copy> {
17+
t: T
18+
}
19+
20+
fn bar<T>() -> MustBeCopy<T> //~ ERROR E0277
21+
{
22+
}
23+
24+
fn main() { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions also for types in fns.
12+
13+
struct MustBeCopy<T:Copy> {
14+
t: T
15+
}
16+
17+
struct Bar<T> {
18+
// needs T: Copy
19+
x: fn(MustBeCopy<T>) //~ ERROR E0277
20+
}
21+
22+
fn main() { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions also for types in fns.
12+
13+
struct MustBeCopy<T:Copy> {
14+
t: T
15+
}
16+
17+
struct Foo<T> {
18+
// needs T: 'static
19+
x: fn() -> MustBeCopy<T> //~ ERROR E0277
20+
}
21+
22+
fn main() { }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions related to regions also for
12+
// types in fns.
13+
14+
#![allow(dead_code)]
15+
#![feature(rustc_attrs)]
16+
17+
struct MustBeCopy<T:Copy> {
18+
t: T
19+
}
20+
21+
struct Foo<T> { //~ WARN E0310
22+
// needs T: 'static
23+
x: fn() -> &'static T //~ WARN E0310
24+
}
25+
26+
struct Bar<T> { //~ WARN E0310
27+
// needs T: Copy
28+
x: fn(&'static T) //~ WARN E0310
29+
}
30+
31+
#[rustc_error]
32+
fn main() { } //~ ERROR compilation successful
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions also for where clauses in fn items.
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
trait MustBeCopy<T:Copy> {
17+
}
18+
19+
fn bar<T,U>() //~ WARN E0277
20+
where T: MustBeCopy<U>
21+
{
22+
}
23+
24+
#[rustc_error]
25+
fn main() { } //~ ERROR compilation successful
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we enforce WF conditions also for types in fns.
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
trait Object<T> { }
17+
18+
struct MustBeCopy<T:Copy> {
19+
t: T
20+
}
21+
22+
struct Foo<T> { //~ WARN E0310
23+
// needs T: 'static
24+
x: Object<&'static T> //~ WARN E0310
25+
}
26+
27+
#[rustc_error]
28+
fn main() { } //~ ERROR compilation successful

0 commit comments

Comments
 (0)