Skip to content

Rollup of 6 pull requests #73289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5837518
`-Zunpretty=everybody_loops` only works after expansion
ecstatic-morse Jun 7, 2020
d684855
Helper method for whether `ast::Ty` contains `impl Trait`
ecstatic-morse Jun 7, 2020
b5fdbbe
Use correct names for things in `ReplaceBodyWithLoops`
ecstatic-morse Jun 7, 2020
d8c99f3
Preserve expressions that get a `DefId`
ecstatic-morse Jun 7, 2020
1a30042
Remove unnecessary `opt_local_def_id_to_hir_id`
ecstatic-morse Jun 7, 2020
e319f20
Add `rustdoc` tests from #72088
ecstatic-morse Jun 7, 2020
687767a
Suggest substituting `'static` lifetime in impl/dyn `Trait + 'static`…
estebank May 29, 2020
c91320f
When `'static` is explicit, suggest constraining argument with it
estebank May 30, 2020
abf74b9
Reduce verbosity of suggestion message and mention lifetime in label
estebank May 30, 2020
50c422e
Move overlapping span to a note
estebank May 30, 2020
17951e2
Tweak output for overlapping required/captured spans
estebank May 30, 2020
19bb589
Tweak wording and add error code
estebank May 30, 2020
3cfecde
review comments: wording
estebank Jun 1, 2020
bdfb9b1
Use note for requirement source span
estebank Jun 2, 2020
215de3b
Register new eror code
estebank Jun 2, 2020
187e105
small tweaks
estebank Jun 2, 2020
6145918
Change E0758 to E0759 to avoid conflict with #72912
estebank Jun 3, 2020
c29b3fa
On recursive ADT, provide indirection structured suggestion
estebank May 29, 2020
7cde07e
review comments: only suggest one substitution
estebank May 31, 2020
03552ec
fix rebase
estebank Jun 10, 2020
57b54c4
Use the built cargo for cargotest.
ehuss Jun 12, 2020
b4bd180
fix caller_location intrinsic for Miri
RalfJung Jun 12, 2020
bd4bd59
Helper method for whether type has structural equality
ecstatic-morse May 13, 2020
1dd4561
Use "reflexive equality" in docs
ecstatic-morse Jun 12, 2020
2801761
Make `type_marked_structural` private
ecstatic-morse Jun 12, 2020
c30ca41
Rollup merge of #72740 - estebank:recursive-indirection, r=matthewjasper
Dylan-DPC Jun 12, 2020
f27f659
Rollup merge of #72804 - estebank:opaque-missing-lts-in-fn-2, r=nikom…
Dylan-DPC Jun 12, 2020
aeb8dd7
Rollup merge of #73066 - ecstatic-morse:query-structural-eq2, r=pnkfelix
Dylan-DPC Jun 12, 2020
e7a17c5
Rollup merge of #73103 - ecstatic-morse:replace-body-with-loop, r=pnk…
Dylan-DPC Jun 12, 2020
77404e5
Rollup merge of #73267 - ehuss:cargotest-this-cargo, r=Mark-Simulacrum
Dylan-DPC Jun 12, 2020
f6bb405
Rollup merge of #73277 - RalfJung:miri-caller-location, r=oli-obk
Dylan-DPC Jun 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change E0758 to E0759 to avoid conflict with #72912
  • Loading branch information
estebank committed Jun 10, 2020
commit 6145918c83d10e9679805b8feff0286ce9e58afc
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`.