Skip to content

Commit fd6212a

Browse files
authored
Rollup merge of rust-lang#64404 - GuillaumeGomez:err-E0495, r=cramertj
Add long error explanation for E0495 Part of rust-lang#61137.
2 parents 185f8a9 + be89e52 commit fd6212a

File tree

44 files changed

+88
-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.

44 files changed

+88
-9
lines changed

src/librustc/error_codes.rs

+41-2
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,47 @@ where
15801580
```
15811581
"##,
15821582

1583+
E0495: r##"
1584+
A lifetime cannot be determined in the given situation.
1585+
1586+
Erroneous code example:
1587+
1588+
```compile_fail,E0495
1589+
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
1590+
match (&t,) { // error!
1591+
((u,),) => u,
1592+
}
1593+
}
1594+
1595+
let y = Box::new((42,));
1596+
let x = transmute_lifetime(&y);
1597+
```
1598+
1599+
In this code, you have two ways to solve this issue:
1600+
1. Enforce that `'a` lives at least as long as `'b`.
1601+
2. Use the same lifetime requirement for both input and output values.
1602+
1603+
So for the first solution, you can do it by replacing `'a` with `'a: 'b`:
1604+
1605+
```
1606+
fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
1607+
match (&t,) { // ok!
1608+
((u,),) => u,
1609+
}
1610+
}
1611+
```
1612+
1613+
In the second you can do it by simply removing `'b` so they both use `'a`:
1614+
1615+
```
1616+
fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
1617+
match (&t,) { // ok!
1618+
((u,),) => u,
1619+
}
1620+
}
1621+
```
1622+
"##,
1623+
15831624
E0496: r##"
15841625
A lifetime name is shadowing another lifetime name. Erroneous code example:
15851626
@@ -2275,8 +2316,6 @@ rejected in your own crates.
22752316
E0488, // lifetime of variable does not enclose its declaration
22762317
E0489, // type/lifetime parameter not in scope here
22772318
E0490, // a value of type `..` is borrowed for too long
2278-
E0495, // cannot infer an appropriate lifetime due to conflicting
2279-
// requirements
22802319
E0566, // conflicting representation hints
22812320
E0623, // lifetime mismatch where both parameters are anonymous regions
22822321
E0628, // generators cannot have explicit parameters

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

+1
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

+1
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

+2-1
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

+1
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

+1
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

+1
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.stderr

+1
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

+1
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`.

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

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ LL | trait Foo<'a> {
2828

2929
error: aborting due to previous error
3030

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

src/test/ui/issues/issue-20831-debruijn.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ LL | impl<'a> Publisher<'a> for MyStruct<'a> {
9494

9595
error: aborting due to 3 previous errors
9696

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ LL | ((u,),) => u,
2525

2626
error: aborting due to previous error
2727

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ LL | Box::new(self.in_edges(u).map(|e| e.target()))
4242

4343
error: aborting due to 2 previous errors
4444

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

src/test/ui/nll/issue-55394.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | impl Foo<'_> {
2727

2828
error: aborting due to previous error
2929

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

src/test/ui/nll/normalization-bounds-error.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {}
2020

2121
error: aborting due to previous error
2222

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

src/test/ui/nll/type-alias-free-regions.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ LL | impl<'a> FromTuple<'a> for C<'a> {
5050

5151
error: aborting due to 2 previous errors
5252

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

src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ LL | <Foo<'a>>::C
2121

2222
error: aborting due to previous error
2323

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

src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ LL | T::C
2121

2222
error: aborting due to previous error
2323

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

src/test/ui/object-lifetime/object-lifetime-default-elision.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
5050

5151
error: aborting due to 2 previous errors
5252

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

src/test/ui/regions/region-object-lifetime-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | x.borrowed()
2727

2828
error: aborting due to previous error
2929

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

src/test/ui/regions/region-object-lifetime-4.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | x.borrowed()
2727

2828
error: aborting due to previous error
2929

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

src/test/ui/regions/region-object-lifetime-in-coercion.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
4848

4949
error: aborting due to 4 previous errors
5050

51-
For more information about this error, try `rustc --explain E0621`.
51+
Some errors have detailed explanations: E0495, E0621.
52+
For more information about an error, try `rustc --explain E0495`.

src/test/ui/regions/regions-addr-of-self.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ LL | let p: &'static mut usize = &mut self.cats_chased;
2626

2727
error: aborting due to previous error
2828

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

src/test/ui/regions/regions-addr-of-upvar-self.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ LL | let p: &'static mut usize = &mut self.food;
2323

2424
error: aborting due to previous error
2525

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

src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ LL | impl<'a,'b> Foo<'b> for &'a i64 {
4646

4747
error: aborting due to 2 previous errors
4848

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

src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ LL | impl<'a> Foo for &'a i32 {
2121

2222
error: aborting due to previous error
2323

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

src/test/ui/regions/regions-close-object-into-object-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ LL | box B(&*v) as Box<dyn X>
2121

2222
error: aborting due to previous error
2323

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

src/test/ui/regions/regions-close-object-into-object-4.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ LL | box B(&*v) as Box<dyn X>
2121

2222
error: aborting due to previous error
2323

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

src/test/ui/regions/regions-close-over-type-parameter-multiple.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ LL | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait +
2525

2626
error: aborting due to previous error
2727

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

src/test/ui/regions/regions-creating-enums4.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ LL | fn mk_add_bad2<'a,'b>(x: &'a Ast<'a>, y: &'a Ast<'a>, z: &Ast) -> Ast<'b> {
2323

2424
error: aborting due to previous error
2525

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

src/test/ui/regions/regions-escape-method.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ LL | s.f(|p| p)
2525

2626
error: aborting due to previous error
2727

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

src/test/ui/regions/regions-escape-via-trait-or-not.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ LL | with(|o| o)
2525

2626
error: aborting due to previous error
2727

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

src/test/ui/regions/regions-free-region-ordering-incorrect.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ LL | | }
3030

3131
error: aborting due to previous error
3232

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

src/test/ui/regions/regions-infer-call-3.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | let z = with(|y| { select(x, y) });
2727

2828
error: aborting due to previous error
2929

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

src/test/ui/regions/regions-nested-fns.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ LL | fn nested<'x>(x: &'x isize) {
5757

5858
error: aborting due to 2 previous errors
5959

60-
For more information about this error, try `rustc --explain E0312`.
60+
Some errors have detailed explanations: E0312, E0495.
61+
For more information about an error, try `rustc --explain E0312`.

src/test/ui/regions/regions-normalize-in-where-clause-list.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ LL | fn bar<'a, 'b>()
2323

2424
error: aborting due to previous error
2525

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

src/test/ui/regions/regions-ret-borrowed-1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ LL | with(|o| o)
2525

2626
error: aborting due to previous error
2727

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

src/test/ui/regions/regions-ret-borrowed.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ LL | with(|o| o)
2525

2626
error: aborting due to previous error
2727

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

src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | let y = f();
2727

2828
error: aborting due to previous error
2929

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

src/test/ui/regions/regions-trait-object-subtyping.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ LL | fn foo4<'a:'b,'b>(x: Wrapper<&'a mut dyn Dummy>) -> Wrapper<&'b mut dyn Dum
6161

6262
error: aborting due to 3 previous errors
6363

64-
Some errors have detailed explanations: E0308, E0478.
64+
Some errors have detailed explanations: E0308, E0478, E0495.
6565
For more information about an error, try `rustc --explain E0308`.

src/test/ui/reject-specialized-drops-8142.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
111111

112112
error: aborting due to 8 previous errors
113113

114-
Some errors have detailed explanations: E0308, E0366, E0367.
114+
Some errors have detailed explanations: E0308, E0366, E0367, E0495.
115115
For more information about an error, try `rustc --explain E0308`.

src/test/ui/traits/trait-impl-of-supertrait-has-wrong-lifetime-parameters.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
2020

2121
error: aborting due to previous error
2222

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

src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LL | Box::new(items.iter())
2424

2525
error: aborting due to previous error
2626

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

src/test/ui/wf/wf-static-method.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,5 @@ LL | <IndirectEvil>::static_evil(b)
105105

106106
error: aborting due to 5 previous errors
107107

108-
Some errors have detailed explanations: E0312, E0478.
108+
Some errors have detailed explanations: E0312, E0478, E0495.
109109
For more information about an error, try `rustc --explain E0312`.

0 commit comments

Comments
 (0)