Skip to content

Commit e82ccd5

Browse files
committed
Test variances of TAITs
1 parent e0a60f0 commit e82ccd5

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#![feature(rustc_attrs, type_alias_impl_trait, impl_trait_in_assoc_type)]
2+
#![allow(internal_features)]
3+
#![rustc_variance_of_opaques]
4+
5+
trait Captures<'a> {}
6+
impl<T> Captures<'_> for T {}
7+
8+
type NotCapturedEarly<'a> = impl Sized; //~ [o]
9+
10+
type CapturedEarly<'a> = impl Sized + Captures<'a>; //~ [o]
11+
12+
type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>; //~ [o]
13+
14+
type CapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'b>>; //~ [o]
15+
16+
type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a> + Captures<'b>>; //~ [o]
17+
18+
type Bar<'a, 'b: 'b, T> = impl Sized; //~ ERROR [o, o, o]
19+
20+
trait Foo<'i> {
21+
type ImplicitCapturedEarly<'a>;
22+
23+
type ExplicitCaptureEarly<'a>;
24+
25+
type ImplicitCaptureLate<'a>;
26+
27+
type ExplicitCaptureLate<'a>;
28+
}
29+
30+
impl<'i> Foo<'i> for &'i () {
31+
type ImplicitCapturedEarly<'a> = impl Sized; //~ [o, o]
32+
33+
type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; //~ [o, o]
34+
35+
type ImplicitCaptureLate<'a> = impl Sized; //~ [o, o]
36+
37+
type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; //~ [o, o]
38+
}
39+
40+
impl<'i> Foo<'i> for () {
41+
type ImplicitCapturedEarly<'a> = impl Sized; //~ [o, o]
42+
43+
type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; //~ [o, o]
44+
45+
type ImplicitCaptureLate<'a> = impl Sized; //~ [o, o]
46+
47+
type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; //~ [o, o]
48+
}
49+
50+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
error: [o]
2+
--> $DIR/variance.rs:8:29
3+
|
4+
LL | type NotCapturedEarly<'a> = impl Sized;
5+
| ^^^^^^^^^^
6+
7+
error: [o]
8+
--> $DIR/variance.rs:10:26
9+
|
10+
LL | type CapturedEarly<'a> = impl Sized + Captures<'a>;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: [o]
14+
--> $DIR/variance.rs:12:56
15+
|
16+
LL | type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>;
17+
| ^^^^^^^^^^
18+
19+
error: [o]
20+
--> $DIR/variance.rs:14:53
21+
|
22+
LL | type CapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'b>>;
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: [o]
26+
--> $DIR/variance.rs:16:49
27+
|
28+
LL | type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a> + Captures<'b>>;
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: [o, o, o]
32+
--> $DIR/variance.rs:18:27
33+
|
34+
LL | type Bar<'a, 'b: 'b, T> = impl Sized;
35+
| ^^^^^^^^^^
36+
37+
error: [o, o]
38+
--> $DIR/variance.rs:31:38
39+
|
40+
LL | type ImplicitCapturedEarly<'a> = impl Sized;
41+
| ^^^^^^^^^^
42+
43+
error: [o, o]
44+
--> $DIR/variance.rs:33:37
45+
|
46+
LL | type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>;
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
48+
49+
error: [o, o]
50+
--> $DIR/variance.rs:35:36
51+
|
52+
LL | type ImplicitCaptureLate<'a> = impl Sized;
53+
| ^^^^^^^^^^
54+
55+
error: [o, o]
56+
--> $DIR/variance.rs:37:36
57+
|
58+
LL | type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>;
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
60+
61+
error: [o, o]
62+
--> $DIR/variance.rs:41:38
63+
|
64+
LL | type ImplicitCapturedEarly<'a> = impl Sized;
65+
| ^^^^^^^^^^
66+
67+
error: [o, o]
68+
--> $DIR/variance.rs:43:37
69+
|
70+
LL | type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>;
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
72+
73+
error: [o, o]
74+
--> $DIR/variance.rs:45:36
75+
|
76+
LL | type ImplicitCaptureLate<'a> = impl Sized;
77+
| ^^^^^^^^^^
78+
79+
error: [o, o]
80+
--> $DIR/variance.rs:47:36
81+
|
82+
LL | type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>;
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
84+
85+
error: aborting due to 14 previous errors
86+

0 commit comments

Comments
 (0)