1 // Test that we correctly infer variance for region parameters in
2 // various self-contained types.
4 #![feature(rustc_attrs)]
6 // Regions that just appear in normal spots are contravariant:
9 struct Test2<'a, 'b, 'c> { //~ ERROR [-, -, -]
15 // Those same annotations in function arguments become covariant:
18 struct Test3<'a, 'b, 'c> { //~ ERROR [+, +, +]
19 x: extern "Rust" fn(&'a isize),
20 y: extern "Rust" fn(&'b [isize]),
21 c: extern "Rust" fn(&'c str),
24 // Mutability induces invariance:
27 struct Test4<'a, 'b:'a> { //~ ERROR [-, o]
31 // Mutability induces invariance, even when in a
32 // contravariant context:
35 struct Test5<'a, 'b:'a> { //~ ERROR [+, o]
36 x: extern "Rust" fn(&'a mut &'b isize),
39 // Invariance is a trap from which NO ONE CAN ESCAPE.
40 // In other words, even though the `&'b isize` occurs in
41 // an argument list (which is contravariant), that
42 // argument list occurs in an invariant context.
45 struct Test6<'a, 'b:'a> { //~ ERROR [-, o]
46 x: &'a mut extern "Rust" fn(&'b isize),
49 // No uses at all is bivariant:
52 struct Test7<'a> { //~ ERROR [*]
59 enum Test8<'a, 'b, 'c:'b> { //~ ERROR [+, -, o]
60 Test8A(extern "Rust" fn(&'a isize)),
62 Test8C(&'b mut &'c str),