Skip to content

Commit

Permalink
Rollup merge of rust-lang#64404 - GuillaumeGomez:err-E0495, r=cramertj
Browse files Browse the repository at this point in the history
Add long error explanation for E0495

Part of rust-lang#61137.
  • Loading branch information
Centril committed Oct 1, 2019
2 parents 185f8a9 + be89e52 commit fd6212a
Show file tree
Hide file tree
Showing 44 changed files with 88 additions and 9 deletions.
43 changes: 41 additions & 2 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,47 @@ where
```
"##,

E0495: r##"
A lifetime cannot be determined in the given situation.
Erroneous code example:
```compile_fail,E0495
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { // error!
((u,),) => u,
}
}
let y = Box::new((42,));
let x = transmute_lifetime(&y);
```
In this code, you have two ways to solve this issue:
1. Enforce that `'a` lives at least as long as `'b`.
2. Use the same lifetime requirement for both input and output values.
So for the first solution, you can do it by replacing `'a` with `'a: 'b`:
```
fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { // ok!
((u,),) => u,
}
}
```
In the second you can do it by simply removing `'b` so they both use `'a`:
```
fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
match (&t,) { // ok!
((u,),) => u,
}
}
```
"##,

E0496: r##"
A lifetime name is shadowing another lifetime name. Erroneous code example:
Expand Down Expand Up @@ -2275,8 +2316,6 @@ rejected in your own crates.
E0488, // lifetime of variable does not enclose its declaration
E0489, // type/lifetime parameter not in scope here
E0490, // a value of type `..` is borrowed for too long
E0495, // cannot infer an appropriate lifetime due to conflicting
// requirements
E0566, // conflicting representation hints
E0623, // lifetime mismatch where both parameters are anonymous regions
E0628, // generators cannot have explicit parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | bar(foo, x)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
3 changes: 2 additions & 1 deletion src/test/ui/c-variadic/variadic-ffi-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ LL | | }

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0308, E0495.
For more information about an error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | invoke(&x, |a, b| if a > b { a } else { b });

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/impl-header-lifetime-elision/dyn-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | | }

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ LL | x

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-16683.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | trait T<'a> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-17758.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ LL | trait Foo<'a> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-20831-debruijn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ LL | impl<'a> Publisher<'a> for MyStruct<'a> {

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0308, E0495.
For more information about an error, try `rustc --explain E0308`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-52213.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | ((u,),) => u,

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-55796.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ LL | Box::new(self.in_edges(u).map(|e| e.target()))

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/nll/issue-55394.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | impl Foo<'_> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/nll/normalization-bounds-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {}

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/nll/type-alias-free-regions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ LL | impl<'a> FromTuple<'a> for C<'a> {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | <Foo<'a>>::C

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | T::C

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/region-object-lifetime-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | x.borrowed()

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/region-object-lifetime-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | x.borrowed()

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0621`.
Some errors have detailed explanations: E0495, E0621.
For more information about an error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-addr-of-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ LL | let p: &'static mut usize = &mut self.cats_chased;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-addr-of-upvar-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | let p: &'static mut usize = &mut self.food;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ LL | impl<'a,'b> Foo<'b> for &'a i64 {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | impl<'a> Foo for &'a i32 {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | box B(&*v) as Box<dyn X>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | box B(&*v) as Box<dyn X>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-creating-enums4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | fn mk_add_bad2<'a,'b>(x: &'a Ast<'a>, y: &'a Ast<'a>, z: &Ast) -> Ast<'b> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-escape-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | s.f(|p| p)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-escape-via-trait-or-not.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | with(|o| o)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ LL | | }

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-infer-call-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | let z = with(|y| { select(x, y) });

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
3 changes: 2 additions & 1 deletion src/test/ui/regions/regions-nested-fns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ LL | fn nested<'x>(x: &'x isize) {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0312`.
Some errors have detailed explanations: E0312, E0495.
For more information about an error, try `rustc --explain E0312`.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | fn bar<'a, 'b>()

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-ret-borrowed-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | with(|o| o)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-ret-borrowed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | with(|o| o)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | let y = f();

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
2 changes: 1 addition & 1 deletion src/test/ui/regions/regions-trait-object-subtyping.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ LL | fn foo4<'a:'b,'b>(x: Wrapper<&'a mut dyn Dummy>) -> Wrapper<&'b mut dyn Dum

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0478.
Some errors have detailed explanations: E0308, E0478, E0495.
For more information about an error, try `rustc --explain E0308`.
2 changes: 1 addition & 1 deletion src/test/ui/reject-specialized-drops-8142.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }

error: aborting due to 8 previous errors

Some errors have detailed explanations: E0308, E0366, E0367.
Some errors have detailed explanations: E0308, E0366, E0367, E0495.
For more information about an error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ LL | Box::new(items.iter())

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
2 changes: 1 addition & 1 deletion src/test/ui/wf/wf-static-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ LL | <IndirectEvil>::static_evil(b)

error: aborting due to 5 previous errors

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

0 comments on commit fd6212a

Please sign in to comment.