]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/impl-trait/must_outlive_least_region_or_bound.rs
Fix impl Trait Lifetime Handling
[rust.git] / src / test / compile-fail / impl-trait / must_outlive_least_region_or_bound.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(conservative_impl_trait)]
12
13 use std::fmt::Debug;
14
15 fn elided(x: &i32) -> impl Copy { x }
16 //~^ ERROR cannot infer an appropriate lifetime
17
18 fn explicit<'a>(x: &'a i32) -> impl Copy { x }
19 //~^ ERROR cannot infer an appropriate lifetime
20
21 trait LifetimeTrait<'a> {}
22 impl<'a> LifetimeTrait<'a> for &'a i32 {}
23
24 fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
25 //~^ ERROR cannot infer an appropriate lifetime
26
27 // Tests that a closure type contianing 'b cannot be returned from a type where
28 // only 'a was expected.
29 fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
30     //~^ ERROR lifetime mismatch
31     move |_| println!("{}", y)
32 }
33
34 fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
35     //~^ ERROR the parameter type `T` may not live long enough
36     x
37 }
38
39 fn main() {}