]> git.lizzy.rs Git - rust.git/blob - src/test/ui/variance/variance-covariant-arg-object.rs
Rollup merge of #97957 - estebank:spancito, r=compiler-errors
[rust.git] / src / test / ui / variance / variance-covariant-arg-object.rs
1 #![allow(dead_code)]
2
3 // Test that even when `T` is only used in covariant position, it
4 // is treated as invariant.
5
6 trait Get<T> : 'static {
7     fn get(&self) -> T;
8 }
9
10 fn get_min_from_max<'min, 'max>(v: Box<dyn Get<&'max i32>>)
11                                 -> Box<dyn Get<&'min i32>>
12     where 'max : 'min
13 {
14     // Previously OK, now an error as traits are invariant.
15     v
16     //~^ ERROR lifetime may not live long enough
17 }
18
19 fn get_max_from_min<'min, 'max, G>(v: Box<dyn Get<&'min i32>>)
20                                    -> Box<dyn Get<&'max i32>>
21     where 'max : 'min
22 {
23     v
24     //~^ ERROR lifetime may not live long enough
25 }
26
27 fn main() { }