]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-variance-contravariant-use-covariant-in-second-position.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-variance-contravariant-use-covariant-in-second-position.rs
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 // `S` is contravariant with respect to both parameters.
8 struct S<'a, 'b> {
9     f: &'a isize,
10     g: &'b isize,
11 }
12
13 fn use_<'short,'long>(c: S<'long, 'short>,
14                       s: &'short isize,
15                       l: &'long isize,
16                       _where:Option<&'short &'long ()>) {
17
18     let _: S<'long, 'short> = c; // OK
19     let _: S<'short, 'short> = c; // OK
20
21     // Test whether S<_,'short> <: S<_,'long>.  Since
22     // 'short <= 'long, this would be true if the Contravariant type were
23     // covariant with respect to its parameter 'a.
24
25     let _: S<'long, 'long> = c;
26     //~^ ERROR lifetime may not live long enough
27 }
28
29 fn main() {}