diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-08-30 11:23:42 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-08-30 11:23:42 +0000 |
| commit | e82ccd52db55ac166da02efbc07b9c8ae9e4421b (patch) | |
| tree | baece5e58e9dc05d346f75d4ec9327c793253d49 /tests | |
| parent | e0a60f07400db6e4790cce0b6138d359ecabc2d1 (diff) | |
| download | rust-e82ccd52db55ac166da02efbc07b9c8ae9e4421b.tar.gz rust-e82ccd52db55ac166da02efbc07b9c8ae9e4421b.zip | |
Test variances of TAITs
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/type-alias-impl-trait/variance.rs | 50 | ||||
| -rw-r--r-- | tests/ui/type-alias-impl-trait/variance.stderr | 86 |
2 files changed, 136 insertions, 0 deletions
diff --git a/tests/ui/type-alias-impl-trait/variance.rs b/tests/ui/type-alias-impl-trait/variance.rs new file mode 100644 index 00000000000..eba4816003b --- /dev/null +++ b/tests/ui/type-alias-impl-trait/variance.rs @@ -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() {} diff --git a/tests/ui/type-alias-impl-trait/variance.stderr b/tests/ui/type-alias-impl-trait/variance.stderr new file mode 100644 index 00000000000..f73cf617a4c --- /dev/null +++ b/tests/ui/type-alias-impl-trait/variance.stderr @@ -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 + |
