Skip to content

Commit 71b6f77

Browse files
authored
Rollup merge of rust-lang#64404 - GuillaumeGomez:err-E0495, r=Dylan-DPC
Add long error explanation for E0495 Part of rust-lang#61137.
2 parents 1e1f25e + 96efaad commit 71b6f77

File tree

45 files changed

+89
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+89
-9
lines changed

src/librustc/error_codes.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
15231564
E0496: r##"
15241565
A 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

src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ LL | bar(foo, x)
2323

2424
error: aborting due to previous error
2525

26+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
1919

2020
error: aborting due to previous error
2121

22+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/c-variadic/variadic-ffi-4.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,5 @@ LL | | }
209209

210210
error: aborting due to 8 previous errors
211211

212-
For more information about this error, try `rustc --explain E0308`.
212+
Some errors have detailed explanations: E0308, E0495.
213+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/error-codes/E0621-does-not-trigger-for-closures.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | invoke(&x, |a, b| if a > b { a } else { b });
2727

2828
error: aborting due to previous error
2929

30+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/impl-header-lifetime-elision/dyn-trait.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
1919

2020
error: aborting due to previous error
2121

22+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/in-band-lifetimes/mismatched_trait_impl-2.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ LL | | }
1818

1919
error: aborting due to previous error
2020

21+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/in-band-lifetimes/mismatched_trait_impl.nll.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
2222

2323
error: aborting due to previous error
2424

25+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ LL | x
3232

3333
error: aborting due to 2 previous errors
3434

35+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/issues/issue-16683.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | trait T<'a> {
2727

2828
error: aborting due to previous error
2929

30+
For more information about this error, try `rustc --explain E0495`.

0 commit comments

Comments
 (0)