]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Test that a type which is covariant with respect to its region |
2 | // parameter yields an error when used in a contravariant way. | |
3 | // | |
4 | // Note: see variance-regions-*.rs for the tests that check that the | |
5 | // variance inference works in the first place. | |
6 | ||
7 | // This is covariant with respect to 'a, meaning that | |
8 | // Covariant<'foo> <: Covariant<'static> because | |
9 | // 'foo <= 'static | |
10 | struct Covariant<'a> { | |
11 | f: extern "Rust" fn(&'a isize) | |
12 | } | |
13 | ||
14 | fn use_<'short,'long>(c: Covariant<'long>, | |
15 | s: &'short isize, | |
16 | l: &'long isize, | |
17 | _where:Option<&'short &'long ()>) { | |
18 | ||
19 | // Test whether Covariant<'long> <: Covariant<'short>. Since | |
20 | // 'short <= 'long, this would be true if the Covariant type were | |
21 | // contravariant with respect to its parameter 'a. | |
22 | ||
04454e1e | 23 | let _: Covariant<'short> = c; |
923072b8 | 24 | //~^ ERROR lifetime may not live long enough |
1a4d82fc JJ |
25 | } |
26 | ||
27 | fn main() {} |