Skip to content

Commit fbcd136

Browse files
Improve the cycle tests
1 parent f408794 commit fbcd136

8 files changed

+240
-41
lines changed

src/test/ui/associated-types/defaults-cyclic-fail.rs renamed to src/test/ui/associated-types/defaults-cyclic-fail-1.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ impl Tr for u8 {
1515
type A = u8;
1616
}
1717

18+
impl Tr for u16 {
19+
type B = ();
20+
}
21+
1822
impl Tr for u32 {
1923
type A = ();
2024
type B = u8;
@@ -28,8 +32,14 @@ impl Tr for bool {
2832
}
2933
// (the error is shown twice for some reason)
3034

35+
impl Tr for usize {
36+
//~^ ERROR overflow evaluating the requirement
37+
type B = &'static Self::A;
38+
//~^ ERROR overflow evaluating the requirement
39+
}
40+
3141
fn main() {
32-
// Check that the overridden type propagates to the other
33-
let _a: <u8 as Tr>::A = 0u8;
34-
let _b: <u8 as Tr>::B = 0u8;
42+
// We don't check that the types project correctly because the cycle errors stop compilation
43+
// before `main` is type-checked.
44+
// `defaults-cyclic-pass-1.rs` does this.
3545
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
2+
--> $DIR/defaults-cyclic-fail-1.rs:12:6
3+
|
4+
LL | impl Tr for () {}
5+
| ^^
6+
7+
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
8+
--> $DIR/defaults-cyclic-fail-1.rs:30:6
9+
|
10+
LL | impl Tr for bool {
11+
| ^^
12+
13+
error[E0275]: overflow evaluating the requirement `<usize as Tr>::B`
14+
--> $DIR/defaults-cyclic-fail-1.rs:37:6
15+
|
16+
LL | impl Tr for usize {
17+
| ^^
18+
19+
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
20+
--> $DIR/defaults-cyclic-fail-1.rs:32:5
21+
|
22+
LL | type A = Box<Self::B>;
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A`
26+
--> $DIR/defaults-cyclic-fail-1.rs:39:5
27+
|
28+
LL | type B = &'static Self::A;
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: aborting due to 5 previous errors
32+
33+
For more information about this error, try `rustc --explain E0275`.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// compile-fail
2+
3+
#![feature(associated_type_defaults)]
4+
5+
// A more complex version of `defaults-cyclic-fail-1.rs`, with non-trivial defaults.
6+
7+
// Having a cycle in assoc. type defaults is okay...
8+
trait Tr {
9+
type A = Vec<Self::B>;
10+
type B = Box<Self::A>;
11+
}
12+
13+
// ...but is an error in any impl that doesn't override at least one of the defaults
14+
impl Tr for () {}
15+
//~^ ERROR overflow evaluating the requirement
16+
17+
// As soon as at least one is redefined, it works:
18+
impl Tr for u8 {
19+
type A = u8;
20+
}
21+
22+
impl Tr for u16 {
23+
type B = ();
24+
}
25+
26+
impl Tr for u32 {
27+
type A = ();
28+
type B = u8;
29+
}
30+
31+
// ...but only if this actually breaks the cycle
32+
impl Tr for bool {
33+
//~^ ERROR overflow evaluating the requirement
34+
type A = Box<Self::B>;
35+
//~^ ERROR overflow evaluating the requirement
36+
}
37+
// (the error is shown twice for some reason)
38+
39+
impl Tr for usize {
40+
//~^ ERROR overflow evaluating the requirement
41+
type B = &'static Self::A;
42+
//~^ ERROR overflow evaluating the requirement
43+
}
44+
45+
fn main() {
46+
// We don't check that the types project correctly because the cycle errors stop compilation
47+
// before `main` is type-checked.
48+
// `defaults-cyclic-pass-2.rs` does this.
49+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
2+
--> $DIR/defaults-cyclic-fail-2.rs:14:6
3+
|
4+
LL | impl Tr for () {}
5+
| ^^
6+
7+
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
8+
--> $DIR/defaults-cyclic-fail-2.rs:32:6
9+
|
10+
LL | impl Tr for bool {
11+
| ^^
12+
13+
error[E0275]: overflow evaluating the requirement `<usize as Tr>::B`
14+
--> $DIR/defaults-cyclic-fail-2.rs:39:6
15+
|
16+
LL | impl Tr for usize {
17+
| ^^
18+
19+
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
20+
--> $DIR/defaults-cyclic-fail-2.rs:34:5
21+
|
22+
LL | type A = Box<Self::B>;
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A`
26+
--> $DIR/defaults-cyclic-fail-2.rs:41:5
27+
|
28+
LL | type B = &'static Self::A;
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: aborting due to 5 previous errors
32+
33+
For more information about this error, try `rustc --explain E0275`.

src/test/ui/associated-types/defaults-cyclic-fail.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// check-pass
2+
3+
#![feature(associated_type_defaults)]
4+
5+
// Having a cycle in assoc. type defaults is okay, as long as there's no impl
6+
// that retains it.
7+
trait Tr {
8+
type A = Self::B;
9+
type B = Self::A;
10+
11+
fn f();
12+
}
13+
14+
// An impl has to break the cycle to be accepted.
15+
impl Tr for u8 {
16+
type A = u8;
17+
18+
fn f() {
19+
// Check that the type propagates as expected (seen from inside the impl)
20+
let _: Self::A = 0u8;
21+
let _: Self::B = 0u8;
22+
}
23+
}
24+
25+
impl Tr for String {
26+
type B = ();
27+
28+
fn f() {
29+
// Check that the type propagates as expected (seen from inside the impl)
30+
let _: Self::A = ();
31+
let _: Self::B = ();
32+
}
33+
}
34+
35+
impl Tr for () {
36+
type A = Vec<()>;
37+
type B = u8;
38+
39+
fn f() {
40+
// Check that the type propagates as expected (seen from inside the impl)
41+
let _: Self::A = Vec::<()>::new();
42+
let _: Self::B = 0u8;
43+
}
44+
}
45+
46+
fn main() {
47+
// Check that both impls now have the right types (seen from outside the impls)
48+
let _: <u8 as Tr>::A = 0u8;
49+
let _: <u8 as Tr>::B = 0u8;
50+
51+
let _: <String as Tr>::A = ();
52+
let _: <String as Tr>::B = ();
53+
54+
let _: <() as Tr>::A = Vec::<()>::new();
55+
let _: <() as Tr>::B = 0u8;
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// check-pass
2+
3+
#![feature(associated_type_defaults)]
4+
5+
// Having a cycle in assoc. type defaults is okay, as long as there's no impl
6+
// that retains it.
7+
trait Tr {
8+
type A = Vec<Self::B>;
9+
type B = Box<Self::A>;
10+
11+
fn f();
12+
}
13+
14+
// An impl has to break the cycle to be accepted.
15+
impl Tr for u8 {
16+
type A = u8;
17+
18+
fn f() {
19+
// Check that the type propagates as expected (seen from inside the impl)
20+
let _: Self::A = 0u8;
21+
let _: Self::B = Box::new(0u8);
22+
}
23+
}
24+
25+
impl Tr for String {
26+
type B = ();
27+
28+
fn f() {
29+
// Check that the type propagates as expected (seen from inside the impl)
30+
let _: Self::A = Vec::<()>::new();
31+
let _: Self::B = ();
32+
}
33+
}
34+
35+
impl Tr for () {
36+
type A = Vec<()>;
37+
type B = u8;
38+
39+
fn f() {
40+
// Check that the type propagates as expected (seen from inside the impl)
41+
let _: Self::A = Vec::<()>::new();
42+
let _: Self::B = 0u8;
43+
}
44+
}
45+
46+
fn main() {
47+
// Check that both impls now have the right types (seen from outside the impls)
48+
let _: <u8 as Tr>::A = 0u8;
49+
let _: <u8 as Tr>::B = Box::new(0u8);
50+
51+
let _: <String as Tr>::A = Vec::<()>::new();
52+
let _: <String as Tr>::B = ();
53+
54+
let _: <() as Tr>::A = Vec::<()>::new();
55+
let _: <() as Tr>::B = 0u8;
56+
}

src/test/ui/associated-types/defaults-cyclic-pass.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)