1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test that we correctly infer variance for region parameters in
12 // various self-contained types.
14 #![feature(rustc_attrs)]
16 // Regions that just appear in normal spots are contravariant:
19 struct Test2<'a, 'b, 'c> { //~ ERROR [-, -, -]
25 // Those same annotations in function arguments become covariant:
28 struct Test3<'a, 'b, 'c> { //~ ERROR [+, +, +]
29 x: extern "Rust" fn(&'a isize),
30 y: extern "Rust" fn(&'b [isize]),
31 c: extern "Rust" fn(&'c str),
34 // Mutability induces invariance:
37 struct Test4<'a, 'b:'a> { //~ ERROR [-, o]
41 // Mutability induces invariance, even when in a
42 // contravariant context:
45 struct Test5<'a, 'b:'a> { //~ ERROR [+, o]
46 x: extern "Rust" fn(&'a mut &'b isize),
49 // Invariance is a trap from which NO ONE CAN ESCAPE.
50 // In other words, even though the `&'b isize` occurs in
51 // an argument list (which is contravariant), that
52 // argument list occurs in an invariant context.
55 struct Test6<'a, 'b:'a> { //~ ERROR [-, o]
56 x: &'a mut extern "Rust" fn(&'b isize),
59 // No uses at all is bivariant:
62 struct Test7<'a> { //~ ERROR [*]
63 //~^ ERROR parameter `'a` is never used
70 enum Test8<'a, 'b, 'c:'b> { //~ ERROR [+, -, o]
71 Test8A(extern "Rust" fn(&'a isize)),
73 Test8C(&'b mut &'c str),