Skip to content

Commit 17951e2

Browse files
committed
Tweak output for overlapping required/captured spans
1 parent 50c422e commit 17951e2

File tree

7 files changed

+15
-72
lines changed

7 files changed

+15
-72
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7676
// | |
7777
// | this data with the anonymous lifetime `'_`...
7878
// |
79-
// note: ...is required to be `'static` by this
80-
// |
81-
// LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
82-
// | ^^^^^^^^^^^
83-
err.span_label(sup_origin.span(), "...is captured here...");
84-
err.span_note(return_sp, "...and required to be `'static` by this");
79+
err.span_label(
80+
sup_origin.span(),
81+
"...is captured here with a `'static` requirement",
82+
);
8583
} else if sup_origin.span() <= return_sp {
8684
err.span_label(sup_origin.span(), "...is captured here...");
8785
err.span_label(return_sp, "...and required to be `'static` by this");

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,10 @@ error: cannot infer an appropriate lifetime
109109
--> $DIR/must_outlive_least_region_or_bound.rs:18:50
110110
|
111111
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
112-
| ---- ^ ...is captured here...
112+
| ---- ^ ...is captured here with a `'static` requirement
113113
| |
114114
| this data with the anonymous lifetime `'_`...
115115
|
116-
note: ...and required to be `'static` by this
117-
--> $DIR/must_outlive_least_region_or_bound.rs:18:41
118-
|
119-
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
120-
| ^^^^^^^^^^^
121116
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
122117
|
123118
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
@@ -127,15 +122,10 @@ error: cannot infer an appropriate lifetime
127122
--> $DIR/must_outlive_least_region_or_bound.rs:21:59
128123
|
129124
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
130-
| ------- ^ ...is captured here...
125+
| ------- ^ ...is captured here with a `'static` requirement
131126
| |
132127
| this data with lifetime `'a`...
133128
|
134-
note: ...and required to be `'static` by this
135-
--> $DIR/must_outlive_least_region_or_bound.rs:21:50
136-
|
137-
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
138-
| ^^^^^^^^^^^
139129
help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
140130
|
141131
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
@@ -145,15 +135,10 @@ error: cannot infer an appropriate lifetime
145135
--> $DIR/must_outlive_least_region_or_bound.rs:24:60
146136
|
147137
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
148-
| ---- ^ ...is captured here...
138+
| ---- ^ ...is captured here with a `'static` requirement
149139
| |
150140
| this data with the anonymous lifetime `'_`...
151141
|
152-
note: ...and required to be `'static` by this
153-
--> $DIR/must_outlive_least_region_or_bound.rs:24:51
154-
|
155-
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
156-
| ^^^^^^^^^^^
157142
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
158143
|
159144
LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
@@ -167,13 +152,8 @@ error: cannot infer an appropriate lifetime
167152
--> $DIR/must_outlive_least_region_or_bound.rs:27:69
168153
|
169154
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
170-
| ------- this data with lifetime `'a`... ^ ...is captured here...
155+
| ------- this data with lifetime `'a`... ^ ...is captured here with a `'static` requirement
171156
|
172-
note: ...and required to be `'static` by this
173-
--> $DIR/must_outlive_least_region_or_bound.rs:27:60
174-
|
175-
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
176-
| ^^^^^^^^^^^
177157
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
178158
|
179159
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ error: cannot infer an appropriate lifetime
44
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
55
| -- this data with the anonymous lifetime `'_`...
66
LL | Box::new(value) as Box<dyn Any>
7-
| ^^^^^ ...is captured here...
7+
| ^^^^^ ...is captured here with a `'static` requirement
88
|
9-
note: ...and required to be `'static` by this
10-
--> $DIR/issue-16922.rs:4:5
11-
|
12-
LL | Box::new(value) as Box<dyn Any>
13-
| ^^^^^^^^^^^^^^^
149
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
1510
|
1611
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ error: cannot infer an appropriate lifetime
44
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
55
| ----- this data with the anonymous lifetime `'_`...
66
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
7-
| ^ ...is captured here...
7+
| ^ ...is captured here with a `'static` requirement
88
|
9-
note: ...and required to be `'static` by this
10-
--> $DIR/region-object-lifetime-in-coercion.rs:8:37
11-
|
12-
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
13-
| ^^^^^^^^^^^
149
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
1510
|
1611
LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
@@ -26,13 +21,8 @@ error: cannot infer an appropriate lifetime
2621
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
2722
| ----- this data with the anonymous lifetime `'_`...
2823
LL | Box::new(v)
29-
| ^ ...is captured here...
24+
| ^ ...is captured here with a `'static` requirement
3025
|
31-
note: ...and required to be `'static` by this
32-
--> $DIR/region-object-lifetime-in-coercion.rs:13:5
33-
|
34-
LL | Box::new(v)
35-
| ^^^^^^^^^^^
3626
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
3727
|
3828
LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
@@ -49,13 +39,8 @@ LL | fn c(v: &[u8]) -> Box<dyn Foo> {
4939
| ----- this data with the anonymous lifetime `'_`...
5040
...
5141
LL | Box::new(v)
52-
| ^ ...is captured here...
53-
|
54-
note: ...and required to be `'static` by this
55-
--> $DIR/region-object-lifetime-in-coercion.rs:19:5
42+
| ^ ...is captured here with a `'static` requirement
5643
|
57-
LL | Box::new(v)
58-
| ^^^^^^^^^^^
5944
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
6045
|
6146
LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ error: cannot infer an appropriate lifetime
44
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
55
| ------------------ this data with lifetime `'a`...
66
LL | box B(&*v) as Box<dyn X>
7-
| ^^^ ...is captured here...
7+
| ^^^ ...is captured here with a `'static` requirement
88
|
9-
note: ...and required to be `'static` by this
10-
--> $DIR/regions-close-object-into-object-2.rs:10:5
11-
|
12-
LL | box B(&*v) as Box<dyn X>
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
149
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
1510
|
1611
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'a> {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ error: cannot infer an appropriate lifetime
44
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
55
| ---------------- this data with lifetime `'a`...
66
LL | box B(&*v) as Box<dyn X>
7-
| ^^^ ...is captured here...
7+
| ^^^ ...is captured here with a `'static` requirement
88
|
9-
note: ...and required to be `'static` by this
10-
--> $DIR/regions-close-object-into-object-4.rs:10:5
11-
|
12-
LL | box B(&*v) as Box<dyn X>
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
149
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
1510
|
1611
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'a> {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
55
| ------ this data with the anonymous lifetime `'_`...
66
LL | // This is illegal, because the region bound on `proc` is 'static.
77
LL | Box::new(move || { *x })
8-
| ^^^^^^^^^^^^^^ ...is captured here...
8+
| ^^^^^^^^^^^^^^ ...is captured here with a `'static` requirement
99
|
10-
note: ...and required to be `'static` by this
11-
--> $DIR/regions-proc-bound-capture.rs:9:5
12-
|
13-
LL | Box::new(move || { *x })
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^
1510
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
1611
|
1712
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + '_> {

0 commit comments

Comments
 (0)