]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-variance-invariant-use-contravariant.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-variance-invariant-use-contravariant.rs
1 // Test that an invariant region parameter used in a contravariant way
2 // yields an error.
3 //
4 // Note: see variance-regions-*.rs for the tests that check that the
5 // variance inference works in the first place.
6
7 struct Invariant<'a> {
8     f: &'a mut &'a isize
9 }
10
11 fn use_<'short,'long>(c: Invariant<'long>,
12                       s: &'short isize,
13                       l: &'long isize,
14                       _where:Option<&'short &'long ()>) {
15
16     // Test whether Invariant<'long> <: Invariant<'short>.  Since
17     // 'short <= 'long, this would be true if the Invariant type were
18     // contravariant with respect to its parameter 'a.
19
20     let _: Invariant<'short> = c;
21     //~^ ERROR lifetime may not live long enough
22 }
23
24 fn main() { }