Skip to content

Commit c816430

Browse files
committed
Tweak binding lifetime suggestion text
We already have a structured suggestion, but the wording made it seem like that wasn't the case. Fix #65286. r? @varkor
1 parent a643ee8 commit c816430

23 files changed

+62
-61
lines changed

src/librustc_infer/infer/error_reporting/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1781,28 +1781,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17811781
bound_kind: GenericKind<'tcx>,
17821782
sub: S,
17831783
) {
1784-
let consider = format!(
1785-
"consider adding an explicit lifetime bound {}",
1786-
if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) {
1787-
format!(" `{}` to `{}`...", sub, bound_kind)
1788-
} else {
1789-
format!("`{}: {}`...", bound_kind, sub)
1790-
},
1791-
);
1784+
let msg = "consider adding an explicit lifetime bound";
17921785
if let Some((sp, has_lifetimes, is_impl_trait)) = type_param_span {
17931786
let suggestion = if is_impl_trait {
17941787
format!("{} + {}", bound_kind, sub)
17951788
} else {
17961789
let tail = if has_lifetimes { " + " } else { "" };
17971790
format!("{}: {}{}", bound_kind, sub, tail)
17981791
};
1799-
err.span_suggestion_short(
1792+
err.span_suggestion(
18001793
sp,
1801-
&consider,
1794+
&format!("{}...", msg),
18021795
suggestion,
18031796
Applicability::MaybeIncorrect, // Issue #41966
18041797
);
18051798
} else {
1799+
let consider = format!(
1800+
"{} {}...",
1801+
msg,
1802+
if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) {
1803+
format!(" `{}` to `{}`", sub, bound_kind)
1804+
} else {
1805+
format!("`{}: {}`", bound_kind, sub)
1806+
},
1807+
);
18061808
err.help(&consider);
18071809
}
18081810
}

src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0310]: the parameter type `T` may not live long enough
44
LL | impl <T: Sync> Foo for T { }
55
| -- ^^^
66
| |
7-
| help: consider adding an explicit lifetime bound `T: 'static`...
7+
| help: consider adding an explicit lifetime bound...: `T: 'static +`
88
|
99
note: ...so that the type `T` will meet its required lifetime bounds
1010
--> $DIR/builtin-superkinds-self-type.rs:10:16

src/test/ui/feature-gates/feature-gate-infer_static_outlives_requirements.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `U` may not live long enough
22
--> $DIR/feature-gate-infer_static_outlives_requirements.rs:5:5
33
|
44
LL | struct Foo<U> {
5-
| - help: consider adding an explicit lifetime bound `U: 'static`...
5+
| - help: consider adding an explicit lifetime bound...: `U: 'static`
66
LL | bar: Bar<U>
77
| ^^^^^^^^^^^
88
|

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ error[E0310]: the parameter type `T` may not live long enough
6767
LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
6868
| -- ^^^^^^^^^^^^^^^^^^^^
6969
| |
70-
| help: consider adding an explicit lifetime bound `T: 'static`...
70+
| help: consider adding an explicit lifetime bound...: `T: 'static +`
7171
|
7272
note: ...so that the type `T` will meet its required lifetime bounds
7373
--> $DIR/must_outlive_least_region_or_bound.rs:22:51

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0310]: the parameter type `T` may not live long enough
44
LL | fn foo<T>(x: T) -> impl Any + 'static {
55
| - ^^^^^^^^^^^^^^^^^^
66
| |
7-
| help: consider adding an explicit lifetime bound `T: 'static`...
7+
| help: consider adding an explicit lifetime bound...: `T: 'static`
88
|
99
note: ...so that the type `T` will meet its required lifetime bounds
1010
--> $DIR/type_parameters_captured.rs:7:20

src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough
22
--> $DIR/lifetime-doesnt-live-long-enough.rs:19:5
33
|
44
LL | struct Foo<T> {
5-
| - help: consider adding an explicit lifetime bound `T: 'static`...
5+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
66
LL | foo: &'static T
77
| ^^^^^^^^^^^^^^^
88
|
@@ -16,7 +16,7 @@ error[E0309]: the parameter type `K` may not live long enough
1616
--> $DIR/lifetime-doesnt-live-long-enough.rs:24:19
1717
|
1818
LL | trait X<K>: Sized {
19-
| - help: consider adding an explicit lifetime bound `K: 'a`...
19+
| - help: consider adding an explicit lifetime bound...: `K: 'a`
2020
LL | fn foo<'a, L: X<&'a Nested<K>>>();
2121
| ^^^^^^^^^^^^^^^^
2222
|
@@ -45,7 +45,7 @@ error[E0309]: the parameter type `L` may not live long enough
4545
LL | fn baz<'a, L, M: X<&'a Nested<L>>>() {
4646
| - ^^^^^^^^^^^^^^^^
4747
| |
48-
| help: consider adding an explicit lifetime bound `L: 'a`...
48+
| help: consider adding an explicit lifetime bound...: `L: 'a`
4949
|
5050
note: ...so that the reference type `&'a Nested<L>` does not outlive the data it points at
5151
--> $DIR/lifetime-doesnt-live-long-enough.rs:32:22
@@ -57,7 +57,7 @@ error[E0309]: the parameter type `K` may not live long enough
5757
--> $DIR/lifetime-doesnt-live-long-enough.rs:41:33
5858
|
5959
LL | impl<K> Nested<K> {
60-
| - help: consider adding an explicit lifetime bound `K: 'a`...
60+
| - help: consider adding an explicit lifetime bound...: `K: 'a`
6161
LL | fn generic_in_parent<'a, L: X<&'a Nested<K>>>() {
6262
| ^^^^^^^^^^^^^^^^
6363
|
@@ -71,7 +71,7 @@ error[E0309]: the parameter type `M` may not live long enough
7171
--> $DIR/lifetime-doesnt-live-long-enough.rs:44:36
7272
|
7373
LL | fn generic_in_child<'a, 'b, L: X<&'a Nested<M>>, M: 'b>() {
74-
| ^^^^^^^^^^^^^^^^ -- help: consider adding an explicit lifetime bound `M: 'a`...
74+
| ^^^^^^^^^^^^^^^^ -- help: consider adding an explicit lifetime bound...: `M: 'a +`
7575
|
7676
note: ...so that the reference type `&'a Nested<M>` does not outlive the data it points at
7777
--> $DIR/lifetime-doesnt-live-long-enough.rs:44:36

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough
22
--> $DIR/regions-close-object-into-object-5.rs:17:5
33
|
44
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
5-
| - help: consider adding an explicit lifetime bound `T: 'static`...
5+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
66
LL | // oh dear!
77
LL | box B(&*v) as Box<X>
88
| ^^^^^^^^^^
@@ -17,7 +17,7 @@ error[E0310]: the parameter type `T` may not live long enough
1717
--> $DIR/regions-close-object-into-object-5.rs:17:5
1818
|
1919
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
20-
| - help: consider adding an explicit lifetime bound `T: 'static`...
20+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
2121
LL | // oh dear!
2222
LL | box B(&*v) as Box<X>
2323
| ^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +32,7 @@ error[E0310]: the parameter type `T` may not live long enough
3232
--> $DIR/regions-close-object-into-object-5.rs:17:9
3333
|
3434
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
35-
| - help: consider adding an explicit lifetime bound `T: 'static`...
35+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
3636
LL | // oh dear!
3737
LL | box B(&*v) as Box<X>
3838
| ^
@@ -47,7 +47,7 @@ error[E0310]: the parameter type `T` may not live long enough
4747
--> $DIR/regions-close-object-into-object-5.rs:17:9
4848
|
4949
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
50-
| - help: consider adding an explicit lifetime bound `T: 'static`...
50+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
5151
LL | // oh dear!
5252
LL | box B(&*v) as Box<X>
5353
| ^^^^^^
@@ -62,7 +62,7 @@ error[E0310]: the parameter type `T` may not live long enough
6262
--> $DIR/regions-close-object-into-object-5.rs:17:11
6363
|
6464
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
65-
| - help: consider adding an explicit lifetime bound `T: 'static`...
65+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
6666
LL | // oh dear!
6767
LL | box B(&*v) as Box<X>
6868
| ^^^
@@ -77,7 +77,7 @@ error[E0310]: the parameter type `T` may not live long enough
7777
--> $DIR/regions-close-object-into-object-5.rs:17:11
7878
|
7979
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
80-
| - help: consider adding an explicit lifetime bound `T: 'static`...
80+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
8181
LL | // oh dear!
8282
LL | box B(&*v) as Box<X>
8383
| ^^^
@@ -92,7 +92,7 @@ error[E0310]: the parameter type `T` may not live long enough
9292
--> $DIR/regions-close-object-into-object-5.rs:17:11
9393
|
9494
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
95-
| - help: consider adding an explicit lifetime bound `T: 'static`...
95+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
9696
LL | // oh dear!
9797
LL | box B(&*v) as Box<X>
9898
| ^^^

src/test/ui/regions/regions-close-over-type-parameter-1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `A` may not live long enough
22
--> $DIR/regions-close-over-type-parameter-1.rs:10:5
33
|
44
LL | fn make_object1<A:SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
5-
| -- help: consider adding an explicit lifetime bound `A: 'static`...
5+
| -- help: consider adding an explicit lifetime bound...: `A: 'static +`
66
LL | box v as Box<dyn SomeTrait + 'static>
77
| ^^^^^
88
|
@@ -16,7 +16,7 @@ error[E0310]: the parameter type `A` may not live long enough
1616
--> $DIR/regions-close-over-type-parameter-1.rs:10:5
1717
|
1818
LL | fn make_object1<A:SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
19-
| -- help: consider adding an explicit lifetime bound `A: 'static`...
19+
| -- help: consider adding an explicit lifetime bound...: `A: 'static +`
2020
LL | box v as Box<dyn SomeTrait + 'static>
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222
|
@@ -30,7 +30,7 @@ error[E0309]: the parameter type `A` may not live long enough
3030
--> $DIR/regions-close-over-type-parameter-1.rs:20:5
3131
|
3232
LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<dyn SomeTrait + 'b> {
33-
| -- help: consider adding an explicit lifetime bound `A: 'b`...
33+
| -- help: consider adding an explicit lifetime bound...: `A: 'b +`
3434
LL | box v as Box<dyn SomeTrait + 'b>
3535
| ^^^^^
3636
|
@@ -44,7 +44,7 @@ error[E0309]: the parameter type `A` may not live long enough
4444
--> $DIR/regions-close-over-type-parameter-1.rs:20:5
4545
|
4646
LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<dyn SomeTrait + 'b> {
47-
| -- help: consider adding an explicit lifetime bound `A: 'b`...
47+
| -- help: consider adding an explicit lifetime bound...: `A: 'b +`
4848
LL | box v as Box<dyn SomeTrait + 'b>
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050
|

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough
22
--> $DIR/regions-close-param-into-object.rs:6:5
33
|
44
LL | fn p1<T>(v: T) -> Box<dyn X + 'static>
5-
| - help: consider adding an explicit lifetime bound `T: 'static`...
5+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
66
...
77
LL | Box::new(v)
88
| ^^^^^^^^^^^
@@ -17,7 +17,7 @@ error[E0310]: the parameter type `T` may not live long enough
1717
--> $DIR/regions-close-param-into-object.rs:12:5
1818
|
1919
LL | fn p2<T>(v: Box<T>) -> Box<dyn X + 'static>
20-
| - help: consider adding an explicit lifetime bound `T: 'static`...
20+
| - help: consider adding an explicit lifetime bound...: `T: 'static`
2121
...
2222
LL | Box::new(v)
2323
| ^^^^^^^^^^^
@@ -32,7 +32,7 @@ error[E0309]: the parameter type `T` may not live long enough
3232
--> $DIR/regions-close-param-into-object.rs:18:5
3333
|
3434
LL | fn p3<'a,T>(v: T) -> Box<dyn X + 'a>
35-
| - help: consider adding an explicit lifetime bound `T: 'a`...
35+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
3636
...
3737
LL | Box::new(v)
3838
| ^^^^^^^^^^^
@@ -47,7 +47,7 @@ error[E0309]: the parameter type `T` may not live long enough
4747
--> $DIR/regions-close-param-into-object.rs:24:5
4848
|
4949
LL | fn p4<'a,T>(v: Box<T>) -> Box<dyn X + 'a>
50-
| - help: consider adding an explicit lifetime bound `T: 'a`...
50+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
5151
...
5252
LL | Box::new(v)
5353
| ^^^^^^^^^^^

src/test/ui/regions/regions-enum-not-wf.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough
22
--> $DIR/regions-enum-not-wf.rs:18:18
33
|
44
LL | enum Ref1<'a, T> {
5-
| - help: consider adding an explicit lifetime bound `T: 'a`...
5+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
66
LL | Ref1Variant1(RequireOutlives<'a, T>)
77
| ^^^^^^^^^^^^^^^^^^^^^^
88
|
@@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough
1616
--> $DIR/regions-enum-not-wf.rs:23:25
1717
|
1818
LL | enum Ref2<'a, T> {
19-
| - help: consider adding an explicit lifetime bound `T: 'a`...
19+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
2020
LL | Ref2Variant1,
2121
LL | Ref2Variant2(isize, RequireOutlives<'a, T>),
2222
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -31,7 +31,7 @@ error[E0309]: the parameter type `T` may not live long enough
3131
--> $DIR/regions-enum-not-wf.rs:35:1
3232
|
3333
LL | enum RefDouble<'a, 'b, T> {
34-
| ^ - help: consider adding an explicit lifetime bound `T: 'b`...
34+
| ^ - help: consider adding an explicit lifetime bound...: `T: 'b`
3535
| _|
3636
| |
3737
LL | | RefDoubleVariant1(&'a RequireOutlives<'b, T>)
@@ -52,7 +52,7 @@ error[E0309]: the parameter type `T` may not live long enough
5252
--> $DIR/regions-enum-not-wf.rs:36:23
5353
|
5454
LL | enum RefDouble<'a, 'b, T> {
55-
| - help: consider adding an explicit lifetime bound `T: 'b`...
55+
| - help: consider adding an explicit lifetime bound...: `T: 'b`
5656
LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>)
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5858
|

src/test/ui/regions/regions-implied-bounds-projection-gap-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough
22
--> $DIR/regions-implied-bounds-projection-gap-1.rs:16:10
33
|
44
LL | fn func<'x, T:Trait1<'x>>(t: &'x T::Foo)
5-
| -- help: consider adding an explicit lifetime bound `T: 'x`...
5+
| -- help: consider adding an explicit lifetime bound...: `T: 'x +`
66
LL | {
77
LL | wf::<&'x T>();
88
| ^^^^^

src/test/ui/regions/regions-infer-bound-from-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0309]: the parameter type `A` may not live long enough
22
--> $DIR/regions-infer-bound-from-trait.rs:33:5
33
|
44
LL | fn bar1<'a,A>(x: Inv<'a>, a: A) {
5-
| - help: consider adding an explicit lifetime bound `A: 'a`...
5+
| - help: consider adding an explicit lifetime bound...: `A: 'a`
66
LL | check_bound(x, a)
77
| ^^^^^^^^^^^
88
|
@@ -16,7 +16,7 @@ error[E0309]: the parameter type `A` may not live long enough
1616
--> $DIR/regions-infer-bound-from-trait.rs:37:5
1717
|
1818
LL | fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) {
19-
| -- help: consider adding an explicit lifetime bound `A: 'a`...
19+
| -- help: consider adding an explicit lifetime bound...: `A: 'a +`
2020
LL | check_bound(x, a)
2121
| ^^^^^^^^^^^
2222
|

src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0310]: the parameter type `U` may not live long enough
22
--> $DIR/dont-infer-static.rs:8:5
33
|
44
LL | struct Foo<U> {
5-
| - help: consider adding an explicit lifetime bound `U: 'static`...
5+
| - help: consider adding an explicit lifetime bound...: `U: 'static`
66
LL | bar: Bar<U>
77
| ^^^^^^^^^^^
88
|

src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough
22
--> $DIR/regions-enum-not-wf.rs:18:18
33
|
44
LL | enum Ref1<'a, T> {
5-
| - help: consider adding an explicit lifetime bound `T: 'a`...
5+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
66
LL | Ref1Variant1(RequireOutlives<'a, T>)
77
| ^^^^^^^^^^^^^^^^^^^^^^
88
|
@@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough
1616
--> $DIR/regions-enum-not-wf.rs:23:25
1717
|
1818
LL | enum Ref2<'a, T> {
19-
| - help: consider adding an explicit lifetime bound `T: 'a`...
19+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
2020
LL | Ref2Variant1,
2121
LL | Ref2Variant2(isize, RequireOutlives<'a, T>),
2222
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -31,7 +31,7 @@ error[E0309]: the parameter type `T` may not live long enough
3131
--> $DIR/regions-enum-not-wf.rs:35:1
3232
|
3333
LL | enum RefDouble<'a, 'b, T> {
34-
| ^ - help: consider adding an explicit lifetime bound `T: 'b`...
34+
| ^ - help: consider adding an explicit lifetime bound...: `T: 'b`
3535
| _|
3636
| |
3737
LL | | RefDoubleVariant1(&'a RequireOutlives<'b, T>)
@@ -52,7 +52,7 @@ error[E0309]: the parameter type `T` may not live long enough
5252
--> $DIR/regions-enum-not-wf.rs:36:23
5353
|
5454
LL | enum RefDouble<'a, 'b, T> {
55-
| - help: consider adding an explicit lifetime bound `T: 'b`...
55+
| - help: consider adding an explicit lifetime bound...: `T: 'b`
5656
LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>)
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5858
|

src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough
22
--> $DIR/regions-struct-not-wf.rs:13:5
33
|
44
LL | impl<'a, T> Trait<'a, T> for usize {
5-
| - help: consider adding an explicit lifetime bound `T: 'a`...
5+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
66
LL | type Out = &'a T;
77
| ^^^^^^^^^^^^^^^^^
88
|
@@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough
1616
--> $DIR/regions-struct-not-wf.rs:21:5
1717
|
1818
LL | impl<'a, T> Trait<'a, T> for u32 {
19-
| - help: consider adding an explicit lifetime bound `T: 'a`...
19+
| - help: consider adding an explicit lifetime bound...: `T: 'a`
2020
LL | type Out = RefOk<'a, T>;
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^
2222
|

src/test/ui/suggestions/suggest-impl-trait-lifetime.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fmt::Debug;
44

55
fn foo(d: impl Debug + 'static) {
6-
//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug`
6+
//~^ HELP consider adding an explicit lifetime bound...
77
bar(d);
88
//~^ ERROR the parameter type `impl Debug` may not live long enough
99
//~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds

0 commit comments

Comments
 (0)