Skip to content

Commit ac2fb7a

Browse files
committed
Tweak wording
1 parent de67990 commit ac2fb7a

13 files changed

+61
-34
lines changed

src/librustc_resolve/late/diagnostics.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10351035
lifetime_names: &FxHashSet<ast::Ident>,
10361036
params: &[ElisionFailureInfo],
10371037
) {
1038+
let snippet = self.tcx.sess.source_map().span_to_snippet(span).ok();
1039+
10381040
err.span_label(
10391041
span,
10401042
&format!(
@@ -1044,11 +1046,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10441046
),
10451047
);
10461048

1047-
let snippet = self.tcx.sess.source_map().span_to_snippet(span).ok();
10481049
let suggest_existing = |err: &mut DiagnosticBuilder<'_>, sugg| {
10491050
err.span_suggestion_verbose(
10501051
span,
1051-
"consider using the named lifetime",
1052+
&format!("consider using the `{}` lifetime", lifetime_names.iter().next().unwrap()),
10521053
sugg,
10531054
Applicability::MaybeIncorrect,
10541055
);
@@ -1138,6 +1139,20 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
11381139
(0, _, Some(snippet)) if !snippet.ends_with('>') && count == 1 => {
11391140
suggest_new(err, &format!("{}<'a>", snippet));
11401141
}
1142+
(n, ..) if n > 1 => {
1143+
let spans: Vec<Span> = lifetime_names.iter().map(|lt| lt.span).collect();
1144+
err.span_note(spans, "these named lifetimes are available to use");
1145+
if Some("") == snippet.as_deref() {
1146+
// This happens when we have `Foo<T>` where we point at the space before `T`,
1147+
// but this can be confusing so we give a suggestion with placeholders.
1148+
err.span_suggestion_verbose(
1149+
span,
1150+
"consider using one of the available lifetimes here",
1151+
"'lifetime, ".repeat(count),
1152+
Applicability::HasPlaceholders,
1153+
);
1154+
}
1155+
}
11411156
_ => {}
11421157
}
11431158
}

src/test/ui/associated-types/bound-lifetime-in-binding-only.elision.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn elision<T: Fn() -> &i32>() {
55
| ^ expected named lifetime parameter
66
|
77
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
8-
help: consider using the named lifetime
8+
help: consider using the `'static` lifetime
99
|
1010
LL | fn elision<T: Fn() -> &'static i32>() {
1111
| ^^^^^^^^

src/test/ui/associated-types/bound-lifetime-in-return-only.elision.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn elision(_: fn() -> &i32) {
55
| ^ expected named lifetime parameter
66
|
77
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
8-
help: consider using the named lifetime
8+
help: consider using the `'static` lifetime
99
|
1010
LL | fn elision(_: fn() -> &'static i32) {
1111
| ^^^^^^^^

src/test/ui/async-await/issues/issue-63388-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | ) -> &dyn Foo
77
| ^ expected named lifetime parameter
88
|
99
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `foo` or `bar`
10-
help: consider using the named lifetime
10+
help: consider using the `'a` lifetime
1111
|
1212
LL | ) -> &'a dyn Foo
1313
| ^^^

src/test/ui/c-variadic/variadic-ffi-6.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | ) -> &usize {
55
| ^ expected named lifetime parameter
66
|
77
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
8-
help: consider using the named lifetime
8+
help: consider using the `'static` lifetime
99
|
1010
LL | ) -> &'static usize {
1111
| ^^^^^^^^

src/test/ui/foreign-fn-return-lifetime.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | pub fn f() -> &u8;
55
| ^ expected named lifetime parameter
66
|
77
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
8-
help: consider using the named lifetime
8+
help: consider using the `'static` lifetime
99
|
1010
LL | pub fn f() -> &'static u8;
1111
| ^^^^^^^^

src/test/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ error[E0106]: missing lifetime specifier
99
|
1010
LL | fn foo<'b, L: X<&'b Nested<K>>>();
1111
| ^ expected named lifetime parameter
12+
|
13+
note: these named lifetimes are available to use
14+
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:12
15+
|
16+
LL | trait X<'a, K: 'a> {
17+
| ^^
18+
LL | fn foo<'b, L: X<&'b Nested<K>>>();
19+
| ^^
20+
help: consider using one of the available lifetimes here
21+
|
22+
LL | fn foo<'b, L: X<'lifetime, &'b Nested<K>>>();
23+
| ^^^^^^^^^^
1224

1325
error[E0106]: missing lifetime specifier
1426
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:13:17
1527
|
1628
LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
1729
| ^ expected named lifetime parameter
1830
|
19-
help: consider using the named lifetime
31+
help: consider using the `'b` lifetime
2032
|
2133
LL | fn bar<'b, L: X<'b, &'b Nested<i32>>>(){}
2234
| ^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | &str
55
| ^ expected named lifetime parameter
66
|
77
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
8-
help: consider using the named lifetime
8+
help: consider using the `'static` lifetime
99
|
1010
LL | &'static str
1111
| ^^^^^^^^

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
1717
| ^ expected named lifetime parameter
1818
|
1919
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
20-
help: consider using the named lifetime
20+
help: consider using the `'static` lifetime
2121
|
2222
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &'static str { iter() }
2323
| ^^^^^^^^
@@ -29,7 +29,7 @@ LL | fn parse_type_3() -> &str { unimplemented!() }
2929
| ^ expected named lifetime parameter
3030
|
3131
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
32-
help: consider using the named lifetime
32+
help: consider using the `'static` lifetime
3333
|
3434
LL | fn parse_type_3() -> &'static str { unimplemented!() }
3535
| ^^^^^^^^

src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn f() -> &isize {
55
| ^ expected named lifetime parameter
66
|
77
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
8-
help: consider using the named lifetime
8+
help: consider using the `'static` lifetime
99
|
1010
LL | fn f() -> &'static isize {
1111
| ^^^^^^^^
@@ -41,7 +41,7 @@ LL | fn i(_x: isize) -> &isize {
4141
| ^ expected named lifetime parameter
4242
|
4343
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
44-
help: consider using the named lifetime
44+
help: consider using the `'static` lifetime
4545
|
4646
LL | fn i(_x: isize) -> &'static isize {
4747
| ^^^^^^^^
@@ -53,7 +53,7 @@ LL | fn j(_x: StaticStr) -> &isize {
5353
| ^ expected named lifetime parameter
5454
|
5555
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
56-
help: consider using the named lifetime
56+
help: consider using the `'static` lifetime
5757
|
5858
LL | fn j(_x: StaticStr) -> &'static isize {
5959
| ^^^^^^^^
@@ -65,7 +65,7 @@ LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
6565
| ^ expected named lifetime parameter
6666
|
6767
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
68-
help: consider using the named lifetime
68+
help: consider using the `'a` lifetime
6969
|
7070
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &'a isize {
7171
| ^^^

0 commit comments

Comments
 (0)