@@ -1520,6 +1520,47 @@ where
15201520```
15211521"## ,
15221522
1523+ E0495 : r##"
1524+ A lifetime cannot be determined in the given situation.
1525+
1526+ Erroneous code example:
1527+
1528+ ```compile_fail,E0495
1529+ fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
1530+ match (&t,) { // error!
1531+ ((u,),) => u,
1532+ }
1533+ }
1534+
1535+ let y = Box::new((42,));
1536+ let x = transmute_lifetime(&y);
1537+ ```
1538+
1539+ In this code, you have two ways to solve this issue:
1540+ 1. Enforce that `'a` lives at least as long as `'b`.
1541+ 2. Use the same lifetime requirement for both input and output values.
1542+
1543+ So for the first solution, you can do it by replacing `'a` with `'a: 'b`:
1544+
1545+ ```
1546+ fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
1547+ match (&t,) { // ok!
1548+ ((u,),) => u,
1549+ }
1550+ }
1551+ ```
1552+
1553+ In the second you can do it by simply removing `'b` so they both use `'a`:
1554+
1555+ ```
1556+ fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
1557+ match (&t,) { // ok!
1558+ ((u,),) => u,
1559+ }
1560+ }
1561+ ```
1562+ "## ,
1563+
15231564E0496 : r##"
15241565A lifetime name is shadowing another lifetime name. Erroneous code example:
15251566
@@ -2116,8 +2157,6 @@ rejected in your own crates.
21162157 E0488 , // lifetime of variable does not enclose its declaration
21172158 E0489 , // type/lifetime parameter not in scope here
21182159 E0490 , // a value of type `..` is borrowed for too long
2119- E0495 , // cannot infer an appropriate lifetime due to conflicting
2120- // requirements
21212160 E0623 , // lifetime mismatch where both parameters are anonymous regions
21222161 E0628 , // generators cannot have explicit parameters
21232162 E0631 , // type mismatch in closure arguments
0 commit comments