]>
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 | use std::marker; | |
8 | ||
9 | struct Covariant<'a> { | |
85aaf69f | 10 | marker: marker::PhantomData<fn(&'a ())> |
1a4d82fc JJ |
11 | } |
12 | ||
13 | fn use_<'short,'long>(c: Covariant<'long>, | |
14 | s: &'short isize, | |
15 | l: &'long isize, | |
16 | _where:Option<&'short &'long ()>) { | |
17 | ||
18 | // Test whether Covariant<'long> <: Covariant<'short>. Since | |
19 | // 'short <= 'long, this would be true if the Covariant type were | |
20 | // contravariant with respect to its parameter 'a. | |
21 | ||
04454e1e | 22 | let _: Covariant<'short> = c; |
923072b8 | 23 | //~^ ERROR lifetime may not live long enough |
1a4d82fc JJ |
24 | } |
25 | ||
26 | fn main() {} |