]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/region-object-lifetime-in-coercion.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / regions / region-object-lifetime-in-coercion.rs
1 // Test that attempts to implicitly coerce a value into an
2 // object respect the lifetime bound on the object type.
3
4 trait Foo {}
5 impl<'a> Foo for &'a [u8] {}
6
7 fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
8 let x: Box<dyn Foo + 'static> = Box::new(v);
9 //~^ ERROR lifetime may not live long enough
10 x
11 }
12
13 fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
14 Box::new(v)
15 //~^ ERROR lifetime may not live long enough
16 }
17
18 fn c(v: &[u8]) -> Box<dyn Foo> {
19 // same as previous case due to RFC 599
20
21 Box::new(v)
22 //~^ ERROR lifetime may not live long enough
23 }
24
25 fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
26 Box::new(v)
27 //~^ ERROR lifetime may not live long enough
28 }
29
30 fn e<'a:'b,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
31 Box::new(v) // OK, thanks to 'a:'b
32 }
33
34 fn main() { }