]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/regions-trait-object-subtyping.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / test / ui / regions / regions-trait-object-subtyping.rs
1 // revisions: base nll
2 // ignore-compare-mode-nll
3 //[nll] compile-flags: -Z borrowck=mir
4
5 trait Dummy { fn dummy(&self); }
6
7 fn foo1<'a:'b,'b>(x: &'a mut (dyn Dummy+'a)) -> &'b mut (dyn Dummy+'b) {
8 // Here, we are able to coerce
9 x
10 }
11
12 fn foo2<'a:'b,'b>(x: &'b mut (dyn Dummy+'a)) -> &'b mut (dyn Dummy+'b) {
13 // Here, we are able to coerce
14 x
15 }
16
17 fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy {
18 // Without knowing 'a:'b, we can't coerce
19 x
20 //[base]~^ ERROR lifetime bound not satisfied
21 //[base]~| ERROR cannot infer an appropriate lifetime
22 //[nll]~^^^ ERROR lifetime may not live long enough
23 }
24
25 struct Wrapper<T>(T);
26 fn foo4<'a:'b,'b>(x: Wrapper<&'a mut dyn Dummy>) -> Wrapper<&'b mut dyn Dummy> {
27 // We can't coerce because it is packed in `Wrapper`
28 x
29 //[base]~^ ERROR mismatched types
30 //[nll]~^^ ERROR lifetime may not live long enough
31 }
32
33 fn main() {}