2013-11-08 14:52:36 -06:00
|
|
|
// Test that an invariant region parameter used in a contravariant way
|
2013-10-29 05:08:34 -05:00
|
|
|
// yields an error.
|
|
|
|
//
|
|
|
|
// Note: see variance-regions-*.rs for the tests that check that the
|
|
|
|
// variance inference works in the first place.
|
|
|
|
|
|
|
|
struct Invariant<'a> {
|
2015-01-08 04:54:35 -06:00
|
|
|
f: &'a mut &'a isize
|
2013-10-29 05:08:34 -05:00
|
|
|
}
|
|
|
|
|
2013-11-08 14:52:36 -06:00
|
|
|
fn use_<'short,'long>(c: Invariant<'long>,
|
2015-01-08 04:54:35 -06:00
|
|
|
s: &'short isize,
|
|
|
|
l: &'long isize,
|
2013-11-08 14:52:36 -06:00
|
|
|
_where:Option<&'short &'long ()>) {
|
2013-10-29 05:08:34 -05:00
|
|
|
|
2013-11-08 14:52:36 -06:00
|
|
|
// Test whether Invariant<'long> <: Invariant<'short>. Since
|
|
|
|
// 'short <= 'long, this would be true if the Invariant type were
|
|
|
|
// contravariant with respect to its parameter 'a.
|
2013-10-29 05:08:34 -05:00
|
|
|
|
2022-04-19 05:56:18 -05:00
|
|
|
let _: Invariant<'short> = c;
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2013-10-29 05:08:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|