]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0495.md
New upstream version 1.42.0+dfsg0+pve1
[rustc.git] / src / librustc_error_codes / error_codes / E0495.md
CommitLineData
d9bb1a4e
FG
1A lifetime cannot be determined in the given situation.
2
3Erroneous code example:
4
5```compile_fail,E0495
6fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
7 match (&t,) { // error!
8 ((u,),) => u,
9 }
10}
11
12let y = Box::new((42,));
13let x = transmute_lifetime(&y);
14```
15
16In this code, you have two ways to solve this issue:
17 1. Enforce that `'a` lives at least as long as `'b`.
18 2. Use the same lifetime requirement for both input and output values.
19
20So for the first solution, you can do it by replacing `'a` with `'a: 'b`:
21
22```
23fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
24 match (&t,) { // ok!
25 ((u,),) => u,
26 }
27}
28```
29
30In the second you can do it by simply removing `'b` so they both use `'a`:
31
32```
33fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
34 match (&t,) { // ok!
35 ((u,),) => u,
36 }
37}
38```