]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Check that RPITs constrained by a recursive call in a closure are compatible
[rust.git] / src / test / ui / impl-trait / must_outlive_least_region_or_bound.stderr
1 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
2   --> $DIR/must_outlive_least_region_or_bound.rs:3:35
3    |
4 LL | fn elided(x: &i32) -> impl Copy { x }
5    |              ----                 ^
6    |              |
7    |              hidden type `&i32` captures the anonymous lifetime defined here
8    |
9 help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
10    |
11 LL | fn elided(x: &i32) -> impl Copy + '_ { x }
12    |                                 ++++
13
14 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
15   --> $DIR/must_outlive_least_region_or_bound.rs:6:44
16    |
17 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
18    |             --                             ^
19    |             |
20    |             hidden type `&'a i32` captures the lifetime `'a` as defined here
21    |
22 help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound
23    |
24 LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
25    |                                          ++++
26
27 error: lifetime may not live long enough
28   --> $DIR/must_outlive_least_region_or_bound.rs:9:46
29    |
30 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
31    |               -                              ^ returning this value requires that `'1` must outlive `'static`
32    |               |
33    |               let's call the lifetime of this reference `'1`
34    |
35 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
36    |
37 LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
38    |                                    ~~
39 help: alternatively, add an explicit `'static` bound to this reference
40    |
41 LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
42    |               ~~~~~~~~~~~~
43
44 error: lifetime may not live long enough
45   --> $DIR/must_outlive_least_region_or_bound.rs:12:55
46    |
47 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
48    |              -- lifetime `'a` defined here            ^ returning this value requires that `'a` must outlive `'static`
49    |
50 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
51    |
52 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
53    |                                             ~~
54 help: alternatively, add an explicit `'static` bound to this reference
55    |
56 LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x }
57    |                     ~~~~~~~~~~~~
58
59 error[E0621]: explicit lifetime required in the type of `x`
60   --> $DIR/must_outlive_least_region_or_bound.rs:15:41
61    |
62 LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
63    |               ----                      ^ lifetime `'a` required
64    |               |
65    |               help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
66
67 error: lifetime may not live long enough
68   --> $DIR/must_outlive_least_region_or_bound.rs:26:55
69    |
70 LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
71    |               -                                       ^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
72    |               |
73    |               let's call the lifetime of this reference `'1`
74    |
75 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
76    |
77 LL | fn elided5(x: &i32) -> (Box<dyn Debug + '_>, impl Debug) { (Box::new(x), x) }
78    |                                       ++++
79 help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
80    |
81 LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
82    |                                                    ++++
83
84 error: lifetime may not live long enough
85   --> $DIR/must_outlive_least_region_or_bound.rs:32:69
86    |
87 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
88    |               -- lifetime `'a` defined here                         ^ returning this value requires that `'a` must outlive `'static`
89    |
90 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
91    |
92 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
93    |                                                           ~~
94 help: alternatively, add an explicit `'static` bound to this reference
95    |
96 LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x }
97    |                      ~~~~~~~~~~~~
98
99 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
100   --> $DIR/must_outlive_least_region_or_bound.rs:38:5
101    |
102 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
103    |                              -- hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:38:5: 38:13]` captures the lifetime `'b` as defined here
104 LL |     move |_| println!("{}", y)
105    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
106    |
107 help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
108    |
109 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
110    |                                                                              ++++
111
112 error[E0310]: the parameter type `T` may not live long enough
113   --> $DIR/must_outlive_least_region_or_bound.rs:43:5
114    |
115 LL |     x
116    |     ^ ...so that the type `T` will meet its required lifetime bounds
117    |
118 help: consider adding an explicit lifetime bound...
119    |
120 LL | fn ty_param_wont_outlive_static<T:Debug + 'static>(x: T) -> impl Debug + 'static {
121    |                                         +++++++++
122
123 error: aborting due to 9 previous errors
124
125 Some errors have detailed explanations: E0310, E0621, E0700.
126 For more information about an error, try `rustc --explain E0310`.