Skip to content

Commit

Permalink
Change E0758 to E0759 to avoid conflict with rust-lang#72912
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 10, 2020
1 parent 187e105 commit 6145918
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
;
// E0006, // merged with E0005
Expand Down
67 changes: 67 additions & 0 deletions src/librustc_error_codes/error_codes/E0759.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
A `'static` requirement in a return type involving a trait is not fulfilled.

Erroneous code examples:

```compile_fail,E0759
use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug {
x
}
```

```compile_fail,E0759
# use std::fmt::Debug;
fn bar(x: &i32) -> Box<dyn Debug> {
Box::new(x)
}
```

These examples have the same semantics as the following:

```compile_fail,E0759
# use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug + 'static {
x
}
```

```compile_fail,E0759
# use std::fmt::Debug;
fn bar(x: &i32) -> Box<dyn Debug + 'static> {
Box::new(x)
}
```

Both [`dyn Trait`] and [`impl Trait`] in return types have a an implicit
`'static` requirement, meaning that the value implementing them that is being
returned has to be either a `'static` borrow or an owned value.

In order to change the requirement from `'static` to be a lifetime derived from
its arguments, you can add an explicit bound, either to an anonymous lifetime
`'_` or some appropriate named lifetime.

```
# use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug + '_ {
x
}
fn bar(x: &i32) -> Box<dyn Debug + '_> {
Box::new(x)
}
```

These are equivalent to the following explicit lifetime annotations:

```
# use std::fmt::Debug;
fn foo<'a>(x: &'a i32) -> impl Debug + 'a {
x
}
fn bar<'a>(x: &'a i32) -> Box<dyn Debug + 'a> {
Box::new(x)
}
```

[`dyn Trait`]: https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types
[`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let mut err = struct_span_err!(
self.tcx().sess,
sp,
E0758,
E0759,
"cannot infer an appropriate lifetime"
);
err.span_label(
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issues/issue-62097.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/issue-62097.rs:12:31
|
LL | pub async fn run_dummy_fn(&self) {
Expand All @@ -11,4 +11,4 @@ LL | foo(|| self.bar()).await;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
20 changes: 10 additions & 10 deletions src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:3:35
|
LL | fn elided(x: &i32) -> impl Copy { x }
Expand All @@ -16,7 +16,7 @@ help: to declare that the `impl Trait` captures data from argument `x`, you can
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:6:44
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
Expand All @@ -34,7 +34,7 @@ help: to declare that the `impl Trait` captures data from argument `x`, you can
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:9:46
|
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
Expand All @@ -56,7 +56,7 @@ help: alternatively, add an explicit `'static` bound to this reference
LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
| ^^^^^^^^^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:12:55
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
Expand Down Expand Up @@ -86,7 +86,7 @@ LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
| |
| help: add explicit lifetime `'a` to the type of `x`: `&'a i32`

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:33:69
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
Expand Down Expand Up @@ -123,7 +123,7 @@ LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
| |
| help: consider adding an explicit lifetime bound...: `T: 'static +`

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:18:50
|
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
Expand All @@ -136,7 +136,7 @@ help: to declare that the trait object captures data from argument `x`, you can
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
| ^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:21:59
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
Expand All @@ -149,7 +149,7 @@ help: to declare that the trait object captures data from argument `x`, you can
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
| ^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:24:60
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
Expand All @@ -166,7 +166,7 @@ help: alternatively, add an explicit `'static` bound to this reference
LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ^^^^^^^^^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:27:69
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
Expand All @@ -183,5 +183,5 @@ LL | fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x)

error: aborting due to 12 previous errors

Some errors have detailed explanations: E0310, E0621, E0623, E0758.
Some errors have detailed explanations: E0310, E0621, E0623, E0759.
For more information about an error, try `rustc --explain E0310`.
6 changes: 3 additions & 3 deletions src/test/ui/impl-trait/static-return-lifetime-infered.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/static-return-lifetime-infered.rs:7:16
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
Expand All @@ -18,7 +18,7 @@ help: to declare that the `impl Trait` captures data from argument `self`, you c
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/static-return-lifetime-infered.rs:11:16
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
Expand All @@ -40,4 +40,4 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-16922.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/issue-16922.rs:4:14
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
Expand All @@ -13,4 +13,4 @@ LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
|
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
Expand All @@ -23,5 +23,5 @@ LL | ss.r = b;

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0621, E0758.
Some errors have detailed explanations: E0621, E0759.
For more information about an error, try `rustc --explain E0621`.
8 changes: 4 additions & 4 deletions src/test/ui/regions/region-object-lifetime-in-coercion.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:8:46
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
Expand All @@ -15,7 +15,7 @@ help: alternatively, add an explicit `'static` bound to this reference
LL | fn a(v: &'static [u8]) -> Box<dyn Foo + 'static> {
| ^^^^^^^^^^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:13:14
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
Expand All @@ -32,7 +32,7 @@ help: alternatively, add an explicit `'static` bound to this reference
LL | fn b(v: &'static [u8]) -> Box<dyn Foo + 'static> {
| ^^^^^^^^^^^^^

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:19:14
|
LL | fn c(v: &[u8]) -> Box<dyn Foo> {
Expand Down Expand Up @@ -79,5 +79,5 @@ LL | Box::new(v)

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0495, E0758.
Some errors have detailed explanations: E0495, E0759.
For more information about an error, try `rustc --explain E0495`.
4 changes: 2 additions & 2 deletions src/test/ui/regions/regions-close-object-into-object-2.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/regions-close-object-into-object-2.rs:10:11
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
Expand All @@ -17,4 +17,4 @@ LL | fn g<'a, T: 'static>(v: std::boxed::Box<(dyn A<T> + 'static)>) -> Box<dyn X

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
4 changes: 2 additions & 2 deletions src/test/ui/regions/regions-close-object-into-object-4.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/regions-close-object-into-object-4.rs:10:11
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
Expand All @@ -17,4 +17,4 @@ LL | fn i<'a, T, U>(v: std::boxed::Box<(dyn A<U> + 'static)>) -> Box<dyn X + 'st

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
4 changes: 2 additions & 2 deletions src/test/ui/regions/regions-proc-bound-capture.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/regions-proc-bound-capture.rs:9:14
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
Expand All @@ -18,4 +18,4 @@ LL | fn static_proc(x: &'static isize) -> Box<dyn FnMut() -> (isize) + 'static>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:16
|
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
Expand All @@ -9,4 +9,4 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self }

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:44
|
LL | fn f(self: Pin<&Self>) -> impl Clone { self }
Expand All @@ -18,4 +18,4 @@ LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
| |
| help: consider introducing lifetime `'a` here: `'a,`

error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/missing-lifetimes-in-signature.rs:19:5
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
Expand Down Expand Up @@ -125,5 +125,5 @@ LL | fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0261, E0309, E0621, E0758.
Some errors have detailed explanations: E0261, E0309, E0621, E0759.
For more information about an error, try `rustc --explain E0261`.
4 changes: 2 additions & 2 deletions src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0758]: cannot infer an appropriate lifetime
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/dyn-trait-underscore.rs:8:20
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
Expand All @@ -14,4 +14,4 @@ LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T> + '_> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0758`.
For more information about this error, try `rustc --explain E0759`.

0 comments on commit 6145918

Please sign in to comment.