Expand description
Dumps the variances of the annotated item.
See also the variances_of query and ty::Variance.
See AttributeKind::RustcDumpVariances for the internal representation of this attribute.
§Example
ⓘ
//@ dont-require-annotations: ERROR
//@ compile-flags: --crate-type lib -Z ui-testing=no
#![feature(rustc_attrs)]
#[rustc_dump_variances]
struct Ref<'a, T> {
r: &'a T,
}
#[rustc_dump_variances]
struct RefMut<'a, T> {
r: &'a mut T,
}
#[rustc_dump_variances]
struct CellRef<'a, T> {
r: &'a core::cell::UnsafeCell<T>,
}
#[rustc_dump_variances]
fn x<T, U>(_t: T) -> U {
todo!()
}produces:
error: ['a: +, T: +]
--> $DIR/rustc_dump_variances.rs:7:1
|
7 | struct Ref<'a, T> {
| ^^^^^^^^^^^^^^^^^
error: ['a: +, T: o]
--> $DIR/rustc_dump_variances.rs:12:1
|
12 | struct RefMut<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^
error: ['a: +, T: o]
--> $DIR/rustc_dump_variances.rs:17:1
|
17 | struct CellRef<'a, T> {
| ^^^^^^^^^^^^^^^^^^^^^
error: [T: -, U: +]
--> $DIR/rustc_dump_variances.rs:22:1
|
22 | fn x<T, U>(_t: T) -> U {
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors