]>
Commit | Line | Data |
---|---|---|
ff7c6d11 XL |
1 | // Copyright 2016 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 | // compile-flags:-Znll -Zborrowck=mir -Zverbose | |
12 | ||
13 | #![allow(warnings)] | |
14 | #![feature(dyn_trait)] | |
15 | #![feature(rustc_attrs)] | |
16 | ||
17 | use std::fmt::Debug; | |
18 | ||
19 | fn with_signature<'a, T, F>(x: Box<T>, op: F) -> Box<dyn Debug + 'a> | |
20 | where F: FnOnce(Box<T>) -> Box<dyn Debug + 'a> | |
21 | { | |
22 | op(x) | |
23 | } | |
24 | ||
25 | #[rustc_regions] | |
26 | fn no_region<'a, T>(x: Box<T>) -> Box<dyn Debug + 'a> | |
27 | where | |
28 | T: Debug, | |
29 | { | |
30 | // Here, the closure winds up being required to prove that `T: | |
31 | // 'a`. In principle, it could know that, except that it is | |
32 | // type-checked in a fully generic way, and hence it winds up with | |
33 | // a propagated requirement that `T: '_#2`, where `'_#2` appears | |
34 | // in the return type. The caller makes the mapping from `'_#2` to | |
35 | // `'a` (and subsequently reports an error). | |
36 | ||
37 | with_signature(x, |y| y) | |
38 | //~^ WARNING not reporting region error due to -Znll | |
39 | //~| ERROR the parameter type `T` may not live long enough | |
40 | } | |
41 | ||
42 | fn correct_region<'a, T>(x: Box<T>) -> Box<Debug + 'a> | |
43 | where | |
44 | T: 'a + Debug, | |
45 | { | |
46 | x | |
47 | } | |
48 | ||
49 | fn wrong_region<'a, 'b, T>(x: Box<T>) -> Box<Debug + 'a> | |
50 | where | |
51 | T: 'b + Debug, | |
52 | { | |
53 | x | |
54 | //~^ WARNING not reporting region error due to -Znll | |
55 | //~| ERROR the parameter type `T` may not live long enough | |
56 | } | |
57 | ||
58 | fn outlives_region<'a, 'b, T>(x: Box<T>) -> Box<Debug + 'a> | |
59 | where | |
60 | T: 'b + Debug, | |
61 | 'b: 'a, | |
62 | { | |
63 | x | |
64 | } | |
65 | ||
66 | fn main() {} |