Skip to content

Commit 6145918

Browse files
committed
Change E0758 to E0759 to avoid conflict with rust-lang#72912
1 parent 187e105 commit 6145918

16 files changed

+106
-38
lines changed

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ E0752: include_str!("./error_codes/E0752.md"),
438438
E0753: include_str!("./error_codes/E0753.md"),
439439
E0754: include_str!("./error_codes/E0754.md"),
440440
E0758: include_str!("./error_codes/E0758.md"),
441+
E0759: include_str!("./error_codes/E0759.md"),
441442
E0760: include_str!("./error_codes/E0760.md"),
442443
;
443444
// E0006, // merged with E0005
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
A `'static` requirement in a return type involving a trait is not fulfilled.
2+
3+
Erroneous code examples:
4+
5+
```compile_fail,E0759
6+
use std::fmt::Debug;
7+
8+
fn foo(x: &i32) -> impl Debug {
9+
x
10+
}
11+
```
12+
13+
```compile_fail,E0759
14+
# use std::fmt::Debug;
15+
fn bar(x: &i32) -> Box<dyn Debug> {
16+
Box::new(x)
17+
}
18+
```
19+
20+
These examples have the same semantics as the following:
21+
22+
```compile_fail,E0759
23+
# use std::fmt::Debug;
24+
fn foo(x: &i32) -> impl Debug + 'static {
25+
x
26+
}
27+
```
28+
29+
```compile_fail,E0759
30+
# use std::fmt::Debug;
31+
fn bar(x: &i32) -> Box<dyn Debug + 'static> {
32+
Box::new(x)
33+
}
34+
```
35+
36+
Both [`dyn Trait`] and [`impl Trait`] in return types have a an implicit
37+
`'static` requirement, meaning that the value implementing them that is being
38+
returned has to be either a `'static` borrow or an owned value.
39+
40+
In order to change the requirement from `'static` to be a lifetime derived from
41+
its arguments, you can add an explicit bound, either to an anonymous lifetime
42+
`'_` or some appropriate named lifetime.
43+
44+
```
45+
# use std::fmt::Debug;
46+
fn foo(x: &i32) -> impl Debug + '_ {
47+
x
48+
}
49+
fn bar(x: &i32) -> Box<dyn Debug + '_> {
50+
Box::new(x)
51+
}
52+
```
53+
54+
These are equivalent to the following explicit lifetime annotations:
55+
56+
```
57+
# use std::fmt::Debug;
58+
fn foo<'a>(x: &'a i32) -> impl Debug + 'a {
59+
x
60+
}
61+
fn bar<'a>(x: &'a i32) -> Box<dyn Debug + 'a> {
62+
Box::new(x)
63+
}
64+
```
65+
66+
[`dyn Trait`]: https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types
67+
[`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits

src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4040
let mut err = struct_span_err!(
4141
self.tcx().sess,
4242
sp,
43-
E0758,
43+
E0759,
4444
"cannot infer an appropriate lifetime"
4545
);
4646
err.span_label(

src/test/ui/async-await/issues/issue-62097.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/issue-62097.rs:12:31
33
|
44
LL | pub async fn run_dummy_fn(&self) {
@@ -11,4 +11,4 @@ LL | foo(|| self.bar()).await;
1111

1212
error: aborting due to previous error
1313

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

src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/must_outlive_least_region_or_bound.rs:3:35
33
|
44
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
1616
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
1717
| ^^^^
1818

19-
error[E0758]: cannot infer an appropriate lifetime
19+
error[E0759]: cannot infer an appropriate lifetime
2020
--> $DIR/must_outlive_least_region_or_bound.rs:6:44
2121
|
2222
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
3434
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
3535
| ^^^^
3636

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

59-
error[E0758]: cannot infer an appropriate lifetime
59+
error[E0759]: cannot infer an appropriate lifetime
6060
--> $DIR/must_outlive_least_region_or_bound.rs:12:55
6161
|
6262
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 }
8686
| |
8787
| help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
8888

89-
error[E0758]: cannot infer an appropriate lifetime
89+
error[E0759]: cannot infer an appropriate lifetime
9090
--> $DIR/must_outlive_least_region_or_bound.rs:33:69
9191
|
9292
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 {
123123
| |
124124
| help: consider adding an explicit lifetime bound...: `T: 'static +`
125125

126-
error[E0758]: cannot infer an appropriate lifetime
126+
error[E0759]: cannot infer an appropriate lifetime
127127
--> $DIR/must_outlive_least_region_or_bound.rs:18:50
128128
|
129129
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
136136
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
137137
| ^^^^
138138

139-
error[E0758]: cannot infer an appropriate lifetime
139+
error[E0759]: cannot infer an appropriate lifetime
140140
--> $DIR/must_outlive_least_region_or_bound.rs:21:59
141141
|
142142
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
149149
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
150150
| ^^^^
151151

152-
error[E0758]: cannot infer an appropriate lifetime
152+
error[E0759]: cannot infer an appropriate lifetime
153153
--> $DIR/must_outlive_least_region_or_bound.rs:24:60
154154
|
155155
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
166166
LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
167167
| ^^^^^^^^^^^^
168168

169-
error[E0758]: cannot infer an appropriate lifetime
169+
error[E0759]: cannot infer an appropriate lifetime
170170
--> $DIR/must_outlive_least_region_or_bound.rs:27:69
171171
|
172172
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)
183183

184184
error: aborting due to 12 previous errors
185185

186-
Some errors have detailed explanations: E0310, E0621, E0623, E0758.
186+
Some errors have detailed explanations: E0310, E0621, E0623, E0759.
187187
For more information about an error, try `rustc --explain E0310`.

src/test/ui/impl-trait/static-return-lifetime-infered.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/static-return-lifetime-infered.rs:7:16
33
|
44
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
1818
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
1919
| ^^^^
2020

21-
error[E0758]: cannot infer an appropriate lifetime
21+
error[E0759]: cannot infer an appropriate lifetime
2222
--> $DIR/static-return-lifetime-infered.rs:11:16
2323
|
2424
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 {
4040

4141
error: aborting due to 2 previous errors
4242

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/issue-16922.rs:4:14
33
|
44
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
@@ -13,4 +13,4 @@ LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
1313

1414
error: aborting due to previous error
1515

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

src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
33
|
44
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
@@ -23,5 +23,5 @@ LL | ss.r = b;
2323

2424
error: aborting due to 2 previous errors
2525

26-
Some errors have detailed explanations: E0621, E0758.
26+
Some errors have detailed explanations: E0621, E0759.
2727
For more information about an error, try `rustc --explain E0621`.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/region-object-lifetime-in-coercion.rs:8:46
33
|
44
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
@@ -15,7 +15,7 @@ help: alternatively, add an explicit `'static` bound to this reference
1515
LL | fn a(v: &'static [u8]) -> Box<dyn Foo + 'static> {
1616
| ^^^^^^^^^^^^^
1717

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

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

8080
error: aborting due to 4 previous errors
8181

82-
Some errors have detailed explanations: E0495, E0758.
82+
Some errors have detailed explanations: E0495, E0759.
8383
For more information about an error, try `rustc --explain E0495`.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/regions-close-object-into-object-2.rs:10:11
33
|
44
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
1717

1818
error: aborting due to previous error
1919

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/regions-close-object-into-object-4.rs:10:11
33
|
44
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
1717

1818
error: aborting due to previous error
1919

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

src/test/ui/regions/regions-proc-bound-capture.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/regions-proc-bound-capture.rs:9:14
33
|
44
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>
1818

1919
error: aborting due to previous error
2020

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

src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:16
33
|
44
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
@@ -9,4 +9,4 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
99

1010
error: aborting due to previous error
1111

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

src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:44
33
|
44
LL | fn f(self: Pin<&Self>) -> impl Clone { self }
@@ -18,4 +18,4 @@ LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
1818

1919
error: aborting due to previous error
2020

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

src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
66
| |
77
| help: consider introducing lifetime `'a` here: `'a,`
88

9-
error[E0758]: cannot infer an appropriate lifetime
9+
error[E0759]: cannot infer an appropriate lifetime
1010
--> $DIR/missing-lifetimes-in-signature.rs:19:5
1111
|
1212
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
125125

126126
error: aborting due to 7 previous errors
127127

128-
Some errors have detailed explanations: E0261, E0309, E0621, E0758.
128+
Some errors have detailed explanations: E0261, E0309, E0621, E0759.
129129
For more information about an error, try `rustc --explain E0261`.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0758]: cannot infer an appropriate lifetime
1+
error[E0759]: cannot infer an appropriate lifetime
22
--> $DIR/dyn-trait-underscore.rs:8:20
33
|
44
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> + '_> {
1414

1515
error: aborting due to previous error
1616

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

0 commit comments

Comments
 (0)