rust/tests/ui/regions/regions-variance-invariant-use-contravariant.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
736 B
Rust
Raw Normal View History

// Test that an invariant region parameter used in a contravariant way
// 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> {
f: &'a mut &'a isize
}
fn use_<'short,'long>(c: Invariant<'long>,
s: &'short isize,
l: &'long isize,
_where:Option<&'short &'long ()>) {
// 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.
let _: Invariant<'short> = c;
2022-04-01 12:13:25 -05:00
//~^ ERROR lifetime may not live long enough
}
fn main() { }