]> git.lizzy.rs Git - rust.git/blob - src/test/ui/variance/variance-covariant-arg-object.rs
Auto merge of #95315 - compiler-errors:pointee-fix, r=pnkfelix
[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 // revisions: base nll
7 // ignore-compare-mode-nll
8 //[nll] compile-flags: -Z borrowck=mir
9
10 trait Get<T> : 'static {
11     fn get(&self) -> T;
12 }
13
14 fn get_min_from_max<'min, 'max>(v: Box<dyn Get<&'max i32>>)
15                                 -> Box<dyn Get<&'min i32>>
16     where 'max : 'min
17 {
18     // Previously OK, now an error as traits are invariant.
19     v
20     //[base]~^ ERROR mismatched types
21     //[nll]~^^ ERROR lifetime may not live long enough
22 }
23
24 fn get_max_from_min<'min, 'max, G>(v: Box<dyn Get<&'min i32>>)
25                                    -> Box<dyn Get<&'max i32>>
26     where 'max : 'min
27 {
28     v
29     //[base]~^ ERROR mismatched types
30     //[nll]~^^ ERROR lifetime may not live long enough
31 }
32
33 fn main() { }