Change E0758 to E0759 to avoid conflict with #72912

This commit is contained in:
Esteban Küber 2020-06-03 11:34:04 -07:00
parent e31367de6b
commit f7a1f97307
16 changed files with 106 additions and 38 deletions

View File

@ -439,6 +439,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"),
E0761: include_str!("./error_codes/E0761.md"),
E0762: include_str!("./error_codes/E0762.md"),

View File

@ -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

View File

@ -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(

View File

@ -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) {
@ -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`.

View File

@ -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 }
@ -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 }
@ -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 }
@ -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 }
@ -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 }
@ -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) }
@ -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) }
@ -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) }
@ -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) }
@ -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`.

View File

@ -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> {
@ -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> {
@ -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`.

View File

@ -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> {
@ -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`.

View File

@ -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> {
@ -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`.

View File

@ -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> {
@ -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> {
@ -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> {
@ -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`.

View File

@ -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> {
@ -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`.

View File

@ -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> {
@ -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`.

View File

@ -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> {
@ -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`.

View File

@ -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 }
@ -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`.

View File

@ -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 }
@ -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`.

View File

@ -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()
@ -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`.

View File

@ -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>> {
@ -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`.