]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/region-object-lifetime-in-coercion.rs
Remove licenses
[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<Foo + 'static> {
8     let x: Box<Foo + 'static> = Box::new(v);
9     //~^ ERROR explicit lifetime required in the type of `v` [E0621]
10     x
11 }
12
13 fn b(v: &[u8]) -> Box<Foo + 'static> {
14     Box::new(v)
15         //~^ ERROR explicit lifetime required in the type of `v` [E0621]
16 }
17
18 fn c(v: &[u8]) -> Box<Foo> {
19     // same as previous case due to RFC 599
20
21     Box::new(v)
22         //~^ ERROR explicit lifetime required in the type of `v` [E0621]
23 }
24
25 fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
26     Box::new(v)
27         //~^ ERROR cannot infer an appropriate lifetime due to conflicting
28 }
29
30 fn e<'a:'b,'b>(v: &'a [u8]) -> Box<Foo+'b> {
31     Box::new(v) // OK, thanks to 'a:'b
32 }
33
34 fn main() { }