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 Captures<'_> for T {} + +type NotCapturedEarly<'a> = impl Sized; //~ [o] + +type CapturedEarly<'a> = impl Sized + Captures<'a>; //~ [o] + +type NotCapturedLate<'a> = dyn for<'b> Iterator; //~ [o] + +type CapturedLate<'a> = dyn for<'b> Iterator>; //~ [o] + +type Captured<'a> = dyn for<'b> Iterator + 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; + | ^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:14:53 + | +LL | type CapturedLate<'a> = dyn for<'b> Iterator>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:16:49 + | +LL | type Captured<'a> = dyn for<'b> Iterator + 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 +