]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-infer-covariance-due-to-decl.rs
Rollup merge of #106043 - c410-f3r:moar-errors, r=petrochenkov
[rust.git] / src / test / ui / regions / regions-infer-covariance-due-to-decl.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 use std::marker;
8
9 struct Covariant<'a> {
10     marker: marker::PhantomData<fn(&'a ())>
11 }
12
13 fn use_<'short,'long>(c: Covariant<'long>,
14                       s: &'short isize,
15                       l: &'long isize,
16                       _where:Option<&'short &'long ()>) {
17
18     // Test whether Covariant<'long> <: Covariant<'short>.  Since
19     // 'short <= 'long, this would be true if the Covariant type were
20     // contravariant with respect to its parameter 'a.
21
22     let _: Covariant<'short> = c;
23     //~^ ERROR lifetime may not live long enough
24 }
25
26 fn main() {}