File tree Expand file tree Collapse file tree 8 files changed +240
-41
lines changed
src/test/ui/associated-types Expand file tree Collapse file tree 8 files changed +240
-41
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ impl Tr for u8 {
15
15
type A = u8 ;
16
16
}
17
17
18
+ impl Tr for u16 {
19
+ type B = ( ) ;
20
+ }
21
+
18
22
impl Tr for u32 {
19
23
type A = ( ) ;
20
24
type B = u8 ;
@@ -28,8 +32,14 @@ impl Tr for bool {
28
32
}
29
33
// (the error is shown twice for some reason)
30
34
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
+
31
41
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.
35
45
}
Original file line number Diff line number Diff line change
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`.
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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`.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments