mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Test variances of TAITs
This commit is contained in:
parent
e0a60f0740
commit
e82ccd52db
50
tests/ui/type-alias-impl-trait/variance.rs
Normal file
50
tests/ui/type-alias-impl-trait/variance.rs
Normal file
@ -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
tests/ui/type-alias-impl-trait/variance.stderr
Normal file
86
tests/ui/type-alias-impl-trait/variance.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user