Detect when a lifetime is being reused in suggestion
This commit is contained in:
parent
1775e7b93d
commit
cf5702ee91
10 changed files with 13 additions and 9 deletions
|
@ -164,7 +164,10 @@ infer_label_bad = {$bad_kind ->
|
|||
infer_lf_bound_not_satisfied = lifetime bound not satisfied
|
||||
infer_lifetime_mismatch = lifetime mismatch
|
||||
|
||||
infer_lifetime_param_suggestion = consider introducing a named lifetime parameter{$is_impl ->
|
||||
infer_lifetime_param_suggestion = consider {$is_reuse ->
|
||||
[true] reusing
|
||||
*[false] introducing
|
||||
} a named lifetime parameter{$is_impl ->
|
||||
[true] {" "}and update trait if needed
|
||||
*[false] {""}
|
||||
}
|
||||
|
|
|
@ -517,6 +517,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
|
|||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
diag.arg("is_impl", is_impl);
|
||||
diag.arg("is_reuse", !introduce_new);
|
||||
|
||||
true
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); }
|
|||
| | let's call the lifetime of this reference `'1`
|
||||
| let's call the lifetime of this reference `'2`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter
|
||||
help: consider reusing a named lifetime parameter
|
||||
|
|
||||
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
|
||||
| ++ ++
|
||||
|
|
|
@ -9,7 +9,7 @@ LL |
|
|||
LL | if x > y { x } else { y }
|
||||
| ^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
|
||||
| ++
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | fn foo<'a>(&self, x: &'a i32) -> &i32 {
|
|||
LL | x
|
||||
| ^ method was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
|
||||
| ++
|
||||
|
|
|
@ -9,7 +9,7 @@ LL |
|
|||
LL | if true { x } else { self }
|
||||
| ^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | fn foo<'a>(&'a self, x: &'a Foo) -> &'a Foo {
|
||||
| ++
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | fn foo<'a>(&self, x: &i32) -> &i32 {
|
|||
LL | x
|
||||
| ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
|
||||
| ++ ++
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | fn foo<'a>(&self, x: &Foo) -> &Foo {
|
|||
LL | if true { x } else { self }
|
||||
| ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
|
||||
| ++ ++
|
||||
|
|
|
@ -35,7 +35,7 @@ LL | async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg }
|
|||
| | let's call the lifetime of this reference `'1`
|
||||
| lifetime `'a` defined here
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | async fn bar<'a>(self: Alias<&'a Self>, arg: &'a ()) -> &() { arg }
|
||||
| ++
|
||||
|
|
|
@ -38,7 +38,7 @@ LL | fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() {
|
|||
LL | arg
|
||||
| ^^^ method was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a`
|
||||
|
|
||||
help: consider introducing a named lifetime parameter and update trait if needed
|
||||
help: consider reusing a named lifetime parameter and update trait if needed
|
||||
|
|
||||
LL | fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &'a () {
|
||||
| ++
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue