Skip to content

Commit bdfb9b1

Browse files
committed
Use note for requirement source span
1 parent 3cfecde commit bdfb9b1

File tree

7 files changed

+77
-43
lines changed

7 files changed

+77
-43
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7777
sup_origin.span(),
7878
"...is captured here, requiring it to live as long as `'static`",
7979
);
80-
} else if sup_origin.span() <= return_sp {
80+
} else {
8181
err.span_label(sup_origin.span(), "...is captured here...");
82-
err.span_label(
82+
err.span_note(
8383
return_sp,
8484
"...and is required to live as long as `'static` here",
8585
);
86-
} else {
87-
err.span_label(
88-
return_sp,
89-
"...is required to live as long as `'static` here...",
90-
);
91-
err.span_label(sup_origin.span(), "...and is captured here");
9286
}
9387
} else {
9488
err.span_label(

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ LL | pub async fn run_dummy_fn(&self) {
66
| |
77
| this data with an anonymous lifetime `'_`...
88
| ...is captured here...
9+
|
10+
note: ...and is required to live as long as `'static` here
11+
--> $DIR/issue-62097.rs:13:9
12+
|
913
LL | foo(|| self.bar()).await;
10-
| --- ...and is required to live as long as `'static` here
14+
| ^^^
1115

1216
error: aborting due to previous error
1317

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

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ error[E0758]: 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 }
5-
| ---- --------- ^ ...and is captured here
6-
| | |
7-
| | ...is required to live as long as `'static` here...
5+
| ---- ^ ...is captured here...
6+
| |
87
| this data with an anonymous lifetime `'_`...
98
|
9+
note: ...and is required to live as long as `'static` here
10+
--> $DIR/must_outlive_least_region_or_bound.rs:3:23
11+
|
12+
LL | fn elided(x: &i32) -> impl Copy { x }
13+
| ^^^^^^^^^
1014
help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
1115
|
1216
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
@@ -16,11 +20,15 @@ error[E0758]: cannot infer an appropriate lifetime
1620
--> $DIR/must_outlive_least_region_or_bound.rs:6:44
1721
|
1822
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
19-
| ------- --------- ^ ...and is captured here
20-
| | |
21-
| | ...is required to live as long as `'static` here...
23+
| ------- ^ ...is captured here...
24+
| |
2225
| this data with lifetime `'a`...
2326
|
27+
note: ...and is required to live as long as `'static` here
28+
--> $DIR/must_outlive_least_region_or_bound.rs:6:32
29+
|
30+
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
31+
| ^^^^^^^^^
2432
help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'a` lifetime bound
2533
|
2634
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
@@ -30,11 +38,15 @@ error[E0758]: cannot infer an appropriate lifetime
3038
--> $DIR/must_outlive_least_region_or_bound.rs:9:46
3139
|
3240
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
33-
| ---- ------------------- ^ ...and is captured here
34-
| | |
35-
| | ...is required to live as long as `'static` here...
41+
| ---- ^ ...is captured here...
42+
| |
3643
| this data with an anonymous lifetime `'_`...
3744
|
45+
note: ...and is required to live as long as `'static` here
46+
--> $DIR/must_outlive_least_region_or_bound.rs:9:24
47+
|
48+
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
49+
| ^^^^^^^^^^^^^^^^^^^
3850
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
3951
|
4052
LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
@@ -48,11 +60,15 @@ error[E0758]: cannot infer an appropriate lifetime
4860
--> $DIR/must_outlive_least_region_or_bound.rs:12:55
4961
|
5062
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
51-
| ------- ------------------- ^ ...and is captured here
52-
| | |
53-
| | ...is required to live as long as `'static` here...
63+
| ------- ^ ...is captured here...
64+
| |
5465
| this data with lifetime `'a`...
5566
|
67+
note: ...and is required to live as long as `'static` here
68+
--> $DIR/must_outlive_least_region_or_bound.rs:12:33
69+
|
70+
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
71+
| ^^^^^^^^^^^^^^^^^^^
5672
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
5773
|
5874
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
@@ -74,11 +90,13 @@ error[E0758]: cannot infer an appropriate lifetime
7490
--> $DIR/must_outlive_least_region_or_bound.rs:33:69
7591
|
7692
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
77-
| ------- -------------------------------- ^ ...and is captured here
78-
| | |
79-
| | ...is required to live as long as `'static` here...
80-
| this data with lifetime `'a`...
93+
| ------- this data with lifetime `'a`... ^ ...is captured here...
94+
|
95+
note: ...and is required to live as long as `'static` here
96+
--> $DIR/must_outlive_least_region_or_bound.rs:33:34
8197
|
98+
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82100
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
83101
|
84102
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ error[E0758]: 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> {
5-
| ----- ----------------------- ...is required to live as long as `'static` here...
6-
| |
7-
| this data with an anonymous lifetime `'_`...
5+
| ----- this data with an anonymous lifetime `'_`...
86
LL | self.x.iter().map(|a| a.0)
97
| ------ ^^^^
108
| |
11-
| ...and is captured here
9+
| ...is captured here...
1210
|
11+
note: ...and is required to live as long as `'static` here
12+
--> $DIR/static-return-lifetime-infered.rs:6:35
13+
|
14+
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
15+
| ^^^^^^^^^^^^^^^^^^^^^^^
1316
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
1417
|
1518
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
@@ -19,14 +22,17 @@ error[E0758]: cannot infer an appropriate lifetime
1922
--> $DIR/static-return-lifetime-infered.rs:11:16
2023
|
2124
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
22-
| -------- ----------------------- ...is required to live as long as `'static` here...
23-
| |
24-
| this data with lifetime `'a`...
25+
| -------- this data with lifetime `'a`...
2526
LL | self.x.iter().map(|a| a.0)
2627
| ------ ^^^^
2728
| |
28-
| ...and is captured here
29+
| ...is captured here...
2930
|
31+
note: ...and is required to live as long as `'static` here
32+
--> $DIR/static-return-lifetime-infered.rs:10:37
33+
|
34+
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
35+
| ^^^^^^^^^^^^^^^^^^^^^^^
3036
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound
3137
|
3238
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ error[E0758]: 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 }
5-
| ^^^^ ---------- ---------- ...and is required to live as long as `'static` here
6-
| | |
7-
| | this data with an anonymous lifetime `'_`...
5+
| ^^^^ ---------- this data with an anonymous lifetime `'_`...
6+
| |
87
| ...is captured here...
8+
|
9+
note: ...and is required to live as long as `'static` here
10+
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37
11+
|
12+
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
13+
| ^^^^^^^^^^
914

1015
error: aborting due to previous error
1116

src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ error[E0758]: 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 }
5-
| ---------- ---------- ^^^^ ...and is captured here
6-
| | |
7-
| | ...is required to live as long as `'static` here...
5+
| ---------- ^^^^ ...is captured here...
6+
| |
87
| this data with an anonymous lifetime `'_`...
98
|
9+
note: ...and is required to live as long as `'static` here
10+
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31
11+
|
12+
LL | fn f(self: Pin<&Self>) -> impl Clone { self }
13+
| ^^^^^^^^^^
1014
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
1115
|
1216
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ error[E0758]: 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()
13-
| ------ ------------- ...is required to live as long as `'static` here...
14-
| |
15-
| this data with an anonymous lifetime `'_`...
13+
| ------ this data with an anonymous lifetime `'_`...
1614
...
1715
LL | / move || {
1816
LL | | *dest = g.get();
1917
LL | | }
20-
| |_____^ ...and is captured here
18+
| |_____^ ...is captured here...
2119
|
20+
note: ...and is required to live as long as `'static` here
21+
--> $DIR/missing-lifetimes-in-signature.rs:15:37
22+
|
23+
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
24+
| ^^^^^^^^^^^^^
2225
help: to declare that the `impl Trait` captures data from argument `dest`, you can add an explicit `'_` lifetime bound
2326
|
2427
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_

0 commit comments

Comments
 (0)