]> git.lizzy.rs Git - rust.git/blob - src/test/ui/variance/variance-types.rs
Rollup merge of #88858 - spektom:to_lower_upper_rev, r=dtolnay
[rust.git] / src / test / ui / variance / variance-types.rs
1 #![allow(dead_code)]
2 #![feature(rustc_attrs)]
3
4 use std::cell::Cell;
5
6 // Check that a type parameter which is only used in a trait bound is
7 // not considered bivariant.
8
9 #[rustc_variance]
10 struct InvariantMut<'a,A:'a,B:'a> { //~ ERROR [-, o, o]
11     t: &'a mut (A,B)
12 }
13
14 #[rustc_variance]
15 struct InvariantCell<A> { //~ ERROR [o]
16     t: Cell<A>
17 }
18
19 #[rustc_variance]
20 struct InvariantIndirect<A> { //~ ERROR [o]
21     t: InvariantCell<A>
22 }
23
24 #[rustc_variance]
25 struct Covariant<A> { //~ ERROR [+]
26     t: A, u: fn() -> A
27 }
28
29 #[rustc_variance]
30 struct Contravariant<A> { //~ ERROR [-]
31     t: fn(A)
32 }
33
34 #[rustc_variance]
35 enum Enum<A,B,C> { //~ ERROR [+, -, o]
36     Foo(Covariant<A>),
37     Bar(Contravariant<B>),
38     Zed(Covariant<C>,Contravariant<C>)
39 }
40
41 pub fn main() { }