]> git.lizzy.rs Git - rust.git/blob - src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.stderr
2fab02fd1be45f520fa2e015f07e350b70543a8a
[rust.git] / src / test / ui / suggestions / impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.stderr
1 error[E0597]: `val` does not live long enough
2   --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:22:9
3    |
4 LL |     fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
5    |               -- lifetime `'a` defined here                  ------------------- opaque type requires that `val` is borrowed for `'a`
6 LL |         val.use_self()
7    |         ^^^ borrowed value does not live long enough
8 LL |     }
9    |     - `val` dropped here while still borrowed
10    |
11 help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
12    |
13 LL |     fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
14    |                                                                                  ^^^^
15
16 error[E0515]: cannot return value referencing function parameter `val`
17   --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:44:9
18    |
19 LL |         val.use_self()
20    |         ---^^^^^^^^^^^
21    |         |
22    |         returns a value referencing data owned by the current function
23    |         `val` is borrowed here
24
25 error[E0515]: cannot return value referencing function parameter `val`
26   --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:110:9
27    |
28 LL |         val.use_self()
29    |         ---^^^^^^^^^^^
30    |         |
31    |         returns a value referencing data owned by the current function
32    |         `val` is borrowed here
33
34 error[E0767]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
35   --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:67:13
36    |
37 LL |     fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
38    |                        -------------------------------------- this data with lifetime `'a`...
39 LL |         val.use_self()
40    |             ^^^^^^^^ ...is captured and required to live as long as `'static` here
41    |
42 note: the used `impl` has a `'static` requirement
43   --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:61:30
44    |
45 LL |     impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
46    |                              ^^^^^^^^^^^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
47 LL |         fn use_self(&self) -> &() { panic!() }
48    |            -------- calling this method introduces the `impl`'s 'static` requirement
49 help: consider relaxing the implicit `'static` requirement
50    |
51 LL |     impl MyTrait for Box<dyn ObjectTrait<Assoc = i32> + '_> {
52    |                                                       ^^^^
53
54 error: aborting due to 4 previous errors
55
56 Some errors have detailed explanations: E0515, E0597.
57 For more information about an error, try `rustc --explain E0515`.