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