]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/region-object-lifetime-in-coercion.rs
Apply suggestions from code review
[rust.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); //~ ERROR E0759
9     x
10 }
11
12 fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
13     Box::new(v) //~ ERROR E0759
14 }
15
16 fn c(v: &[u8]) -> Box<dyn Foo> {
17     // same as previous case due to RFC 599
18
19     Box::new(v) //~ ERROR E0759
20 }
21
22 fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
23     Box::new(v) //~ ERROR cannot infer an appropriate lifetime due to conflicting
24 }
25
26 fn e<'a:'b,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
27     Box::new(v) // OK, thanks to 'a:'b
28 }
29
30 fn main() { }