Tweak wording
This commit is contained in:
parent
13c1daeb2f
commit
1f43fc0209
13 changed files with 61 additions and 34 deletions
|
@ -1034,6 +1034,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
lifetime_names: &FxHashSet<ast::Ident>,
|
||||
params: &[ElisionFailureInfo],
|
||||
) {
|
||||
let snippet = self.tcx.sess.source_map().span_to_snippet(span).ok();
|
||||
|
||||
err.span_label(
|
||||
span,
|
||||
&format!(
|
||||
|
@ -1043,11 +1045,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
),
|
||||
);
|
||||
|
||||
let snippet = self.tcx.sess.source_map().span_to_snippet(span).ok();
|
||||
let suggest_existing = |err: &mut DiagnosticBuilder<'_>, sugg| {
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
"consider using the named lifetime",
|
||||
&format!("consider using the `{}` lifetime", lifetime_names.iter().next().unwrap()),
|
||||
sugg,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -1137,6 +1138,20 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
(0, _, Some(snippet)) if !snippet.ends_with('>') && count == 1 => {
|
||||
suggest_new(err, &format!("{}<'a>", snippet));
|
||||
}
|
||||
(n, ..) if n > 1 => {
|
||||
let spans: Vec<Span> = lifetime_names.iter().map(|lt| lt.span).collect();
|
||||
err.span_note(spans, "these named lifetimes are available to use");
|
||||
if Some("") == snippet.as_deref() {
|
||||
// This happens when we have `Foo<T>` where we point at the space before `T`,
|
||||
// but this can be confusing so we give a suggestion with placeholders.
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
"consider using one of the available lifetimes here",
|
||||
"'lifetime, ".repeat(count),
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | fn elision<T: Fn() -> &i32>() {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn elision<T: Fn() -> &'static i32>() {
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | fn elision(_: fn() -> &i32) {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn elision(_: fn() -> &'static i32) {
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | ) -> &dyn Foo
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `foo` or `bar`
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | ) -> &'a dyn Foo
|
||||
| ^^^
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | ) -> &usize {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | ) -> &'static usize {
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | pub fn f() -> &u8;
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | pub fn f() -> &'static u8;
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -9,6 +9,18 @@ error[E0106]: missing lifetime specifier
|
|||
|
|
||||
LL | fn foo<'b, L: X<&'b Nested<K>>>();
|
||||
| ^ expected named lifetime parameter
|
||||
|
|
||||
note: these named lifetimes are available to use
|
||||
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:12
|
||||
|
|
||||
LL | trait X<'a, K: 'a> {
|
||||
| ^^
|
||||
LL | fn foo<'b, L: X<&'b Nested<K>>>();
|
||||
| ^^
|
||||
help: consider using one of the available lifetimes here
|
||||
|
|
||||
LL | fn foo<'b, L: X<'lifetime, &'b Nested<K>>>();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:13:17
|
||||
|
@ -16,7 +28,7 @@ error[E0106]: missing lifetime specifier
|
|||
LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
|
||||
| ^ expected named lifetime parameter
|
||||
|
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'b` lifetime
|
||||
|
|
||||
LL | fn bar<'b, L: X<'b, &'b Nested<i32>>>(){}
|
||||
| ^^^
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | &str
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | &'static str
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -17,7 +17,7 @@ LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &'static str { iter() }
|
||||
| ^^^^^^^^
|
||||
|
@ -29,7 +29,7 @@ LL | fn parse_type_3() -> &str { unimplemented!() }
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn parse_type_3() -> &'static str { unimplemented!() }
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | fn f() -> &isize {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn f() -> &'static isize {
|
||||
| ^^^^^^^^
|
||||
|
@ -41,7 +41,7 @@ LL | fn i(_x: isize) -> &isize {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn i(_x: isize) -> &'static isize {
|
||||
| ^^^^^^^^
|
||||
|
@ -53,7 +53,7 @@ LL | fn j(_x: StaticStr) -> &isize {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn j(_x: StaticStr) -> &'static isize {
|
||||
| ^^^^^^^^
|
||||
|
@ -65,7 +65,7 @@ LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &'a isize {
|
||||
| ^^^
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::
|
|||
| ^^^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static a: RefCell<HashMap<i32, Vec<Vec<Foo<'static, 'static>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -17,7 +17,7 @@ LL | static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::
|
|||
| ^^^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static a: RefCell<HashMap<i32, Vec<Vec<Foo<'static, 'static>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -29,7 +29,7 @@ LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap:
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static b: RefCell<HashMap<i32, Vec<Vec<&'static Bar>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^
|
||||
|
@ -41,7 +41,7 @@ LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap:
|
|||
| ^^^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar<'static, 'static>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -53,7 +53,7 @@ LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap:
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static b: RefCell<HashMap<i32, Vec<Vec<&'static Bar>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^
|
||||
|
@ -65,7 +65,7 @@ LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap:
|
|||
| ^^^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar<'static, 'static>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -77,7 +77,7 @@ LL | static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(Hash
|
|||
| ^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static c: RefCell<HashMap<i32, Vec<Vec<Qux<'static, 'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -89,7 +89,7 @@ LL | static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(Hash
|
|||
| ^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static c: RefCell<HashMap<i32, Vec<Vec<Qux<'static, 'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -101,7 +101,7 @@ LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(Has
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static d: RefCell<HashMap<i32, Vec<Vec<&'static Tar<i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^
|
||||
|
@ -113,7 +113,7 @@ LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(Has
|
|||
| ^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, 'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -125,7 +125,7 @@ LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(Has
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static d: RefCell<HashMap<i32, Vec<Vec<&'static Tar<i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^
|
||||
|
@ -137,7 +137,7 @@ LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(Has
|
|||
| ^ expected 2 lifetime parameters
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, 'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -149,7 +149,7 @@ LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static f: RefCell<HashMap<i32, Vec<Vec<&'static Tar<'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^
|
||||
|
@ -161,7 +161,7 @@ LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell
|
|||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | static f: RefCell<HashMap<i32, Vec<Vec<&'static Tar<'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -4,7 +4,7 @@ error[E0106]: missing lifetime specifier
|
|||
LL | struct Foo<'a>(&usize);
|
||||
| ^ expected named lifetime parameter
|
||||
|
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | struct Foo<'a>(&'a usize);
|
||||
| ^^^
|
||||
|
@ -16,7 +16,7 @@ LL | fn func1<'a>(_arg: &'a Thing) -> &() { unimplemented!() }
|
|||
| --------- ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but the signature does not say which one of `_arg`'s 2 lifetimes it is borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | fn func1<'a>(_arg: &'a Thing) -> &'a () { unimplemented!() }
|
||||
| ^^^
|
||||
|
@ -28,7 +28,7 @@ LL | fn func2<'a>(_arg: &Thing<'a>) -> &() { unimplemented!() }
|
|||
| ---------- ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but the signature does not say which one of `_arg`'s 2 lifetimes it is borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | fn func2<'a>(_arg: &Thing<'a>) -> &'a () { unimplemented!() }
|
||||
| ^^^
|
||||
|
|
|
@ -16,7 +16,7 @@ error[E0106]: missing lifetime specifier
|
|||
LL | struct Baz<'a>(&'_ &'a u8);
|
||||
| ^^ expected named lifetime parameter
|
||||
|
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | struct Baz<'a>(&'a &'a u8);
|
||||
| ^^
|
||||
|
@ -28,7 +28,7 @@ LL | fn meh() -> Box<dyn for<'_> Meh<'_>>
|
|||
| ^^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the named lifetime
|
||||
help: consider using the `'static` lifetime
|
||||
|
|
||||
LL | fn meh() -> Box<dyn for<'_> Meh<'static>>
|
||||
| ^^^^^^^
|
||||
|
|
Loading…
Add table
Reference in a new issue