Skip to content

Commit

Permalink
Test variances of TAITs
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Aug 30, 2023
1 parent e0a60f0 commit e82ccd5
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/ui/type-alias-impl-trait/variance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![feature(rustc_attrs, type_alias_impl_trait, impl_trait_in_assoc_type)]
#![allow(internal_features)]
#![rustc_variance_of_opaques]

trait Captures<'a> {}
impl<T> Captures<'_> for T {}

type NotCapturedEarly<'a> = impl Sized; //~ [o]

type CapturedEarly<'a> = impl Sized + Captures<'a>; //~ [o]

type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>; //~ [o]

type CapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'b>>; //~ [o]

type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a> + Captures<'b>>; //~ [o]

type Bar<'a, 'b: 'b, T> = impl Sized; //~ ERROR [o, o, o]

trait Foo<'i> {
type ImplicitCapturedEarly<'a>;

type ExplicitCaptureEarly<'a>;

type ImplicitCaptureLate<'a>;

type ExplicitCaptureLate<'a>;
}

impl<'i> Foo<'i> for &'i () {
type ImplicitCapturedEarly<'a> = impl Sized; //~ [o, o]

type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; //~ [o, o]

type ImplicitCaptureLate<'a> = impl Sized; //~ [o, o]

type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; //~ [o, o]
}

impl<'i> Foo<'i> for () {
type ImplicitCapturedEarly<'a> = impl Sized; //~ [o, o]

type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; //~ [o, o]

type ImplicitCaptureLate<'a> = impl Sized; //~ [o, o]

type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; //~ [o, o]
}

fn main() {}
86 changes: 86 additions & 0 deletions tests/ui/type-alias-impl-trait/variance.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
error: [o]
--> $DIR/variance.rs:8:29
|
LL | type NotCapturedEarly<'a> = impl Sized;
| ^^^^^^^^^^

error: [o]
--> $DIR/variance.rs:10:26
|
LL | type CapturedEarly<'a> = impl Sized + Captures<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: [o]
--> $DIR/variance.rs:12:56
|
LL | type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>;
| ^^^^^^^^^^

error: [o]
--> $DIR/variance.rs:14:53
|
LL | type CapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'b>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: [o]
--> $DIR/variance.rs:16:49
|
LL | type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a> + Captures<'b>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: [o, o, o]
--> $DIR/variance.rs:18:27
|
LL | type Bar<'a, 'b: 'b, T> = impl Sized;
| ^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:31:38
|
LL | type ImplicitCapturedEarly<'a> = impl Sized;
| ^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:33:37
|
LL | type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:35:36
|
LL | type ImplicitCaptureLate<'a> = impl Sized;
| ^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:37:36
|
LL | type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:41:38
|
LL | type ImplicitCapturedEarly<'a> = impl Sized;
| ^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:43:37
|
LL | type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:45:36
|
LL | type ImplicitCaptureLate<'a> = impl Sized;
| ^^^^^^^^^^

error: [o, o]
--> $DIR/variance.rs:47:36
|
LL | type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 14 previous errors

0 comments on commit e82ccd5

Please sign in to comment.