Use note for requirement source span

This commit is contained in:
Esteban Küber 2020-06-01 17:51:12 -07:00
parent 31ea589a06
commit 10d9bf1767
7 changed files with 77 additions and 43 deletions

View file

@ -77,18 +77,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
sup_origin.span(),
"...is captured here, requiring it to live as long as `'static`",
);
} else if sup_origin.span() <= return_sp {
} else {
err.span_label(sup_origin.span(), "...is captured here...");
err.span_label(
err.span_note(
return_sp,
"...and is required to live as long as `'static` here",
);
} else {
err.span_label(
return_sp,
"...is required to live as long as `'static` here...",
);
err.span_label(sup_origin.span(), "...and is captured here");
}
} else {
err.span_label(

View file

@ -6,8 +6,12 @@ LL | pub async fn run_dummy_fn(&self) {
| |
| this data with an anonymous lifetime `'_`...
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/issue-62097.rs:13:9
|
LL | foo(|| self.bar()).await;
| --- ...and is required to live as long as `'static` here
| ^^^
error: aborting due to previous error

View file

@ -2,11 +2,15 @@ error[E0758]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:3:35
|
LL | fn elided(x: &i32) -> impl Copy { x }
| ---- --------- ^ ...and is captured here
| | |
| | ...is required to live as long as `'static` here...
| ---- ^ ...is captured here...
| |
| this data with an anonymous lifetime `'_`...
|
note: ...and is required to live as long as `'static` here
--> $DIR/must_outlive_least_region_or_bound.rs:3:23
|
LL | fn elided(x: &i32) -> impl Copy { x }
| ^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
@ -16,11 +20,15 @@ error[E0758]: 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 }
| ------- --------- ^ ...and is captured here
| | |
| | ...is required to live as long as `'static` here...
| ------- ^ ...is captured here...
| |
| this data with lifetime `'a`...
|
note: ...and is required to live as long as `'static` here
--> $DIR/must_outlive_least_region_or_bound.rs:6:32
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| ^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'a` lifetime bound
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
@ -30,11 +38,15 @@ error[E0758]: cannot infer an appropriate lifetime
--> $DIR/must_outlive_least_region_or_bound.rs:9:46
|
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| ---- ------------------- ^ ...and is captured here
| | |
| | ...is required to live as long as `'static` here...
| ---- ^ ...is captured here...
| |
| this data with an anonymous lifetime `'_`...
|
note: ...and is required to live as long as `'static` here
--> $DIR/must_outlive_least_region_or_bound.rs:9:24
|
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| ^^^^^^^^^^^^^^^^^^^
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
|
LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
@ -48,11 +60,15 @@ error[E0758]: 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 }
| ------- ------------------- ^ ...and is captured here
| | |
| | ...is required to live as long as `'static` here...
| ------- ^ ...is captured here...
| |
| this data with lifetime `'a`...
|
note: ...and is required to live as long as `'static` here
--> $DIR/must_outlive_least_region_or_bound.rs:12:33
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| ^^^^^^^^^^^^^^^^^^^
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
@ -74,11 +90,13 @@ error[E0758]: 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 }
| ------- -------------------------------- ^ ...and is captured here
| | |
| | ...is required to live as long as `'static` here...
| this data with lifetime `'a`...
| ------- this data with lifetime `'a`... ^ ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/must_outlive_least_region_or_bound.rs:33:34
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }

View file

@ -2,14 +2,17 @@ error[E0758]: cannot infer an appropriate lifetime
--> $DIR/static-return-lifetime-infered.rs:7:16
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
| ----- ----------------------- ...is required to live as long as `'static` here...
| |
| this data with an anonymous lifetime `'_`...
| ----- this data with an anonymous lifetime `'_`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
| ...and is captured here
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/static-return-lifetime-infered.rs:6:35
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
@ -19,14 +22,17 @@ error[E0758]: cannot infer an appropriate lifetime
--> $DIR/static-return-lifetime-infered.rs:11:16
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| -------- ----------------------- ...is required to live as long as `'static` here...
| |
| this data with lifetime `'a`...
| -------- this data with lifetime `'a`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
| ...and is captured here
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/static-return-lifetime-infered.rs:10:37
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {

View file

@ -2,10 +2,15 @@ error[E0758]: 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 }
| ^^^^ ---------- ---------- ...and is required to live as long as `'static` here
| | |
| | this data with an anonymous lifetime `'_`...
| ^^^^ ---------- this data with an anonymous lifetime `'_`...
| |
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37
|
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
| ^^^^^^^^^^
error: aborting due to previous error

View file

@ -2,11 +2,15 @@ error[E0758]: 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 }
| ---------- ---------- ^^^^ ...and is captured here
| | |
| | ...is required to live as long as `'static` here...
| ---------- ^^^^ ...is captured here...
| |
| this data with an anonymous lifetime `'_`...
|
note: ...and is required to live as long as `'static` here
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31
|
LL | fn f(self: Pin<&Self>) -> impl Clone { self }
| ^^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
|
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }

View file

@ -10,15 +10,18 @@ error[E0758]: 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()
| ------ ------------- ...is required to live as long as `'static` here...
| |
| this data with an anonymous lifetime `'_`...
| ------ this data with an anonymous lifetime `'_`...
...
LL | / move || {
LL | | *dest = g.get();
LL | | }
| |_____^ ...and is captured here
| |_____^ ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/missing-lifetimes-in-signature.rs:15:37
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
| ^^^^^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `dest`, you can add an explicit `'_` lifetime bound
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_