mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Don't suggest replacing closure parameter with type name
When a closure has an inferred parameter type like `|ch|` and the expected type differs in borrowing (e.g., `char` vs `&char`), the suggestion code would incorrectly suggest `|char|` instead of the valid `|ch: char|`. This happened because the code couldn't walk explicit `&` references in the HIR when the type is inferred, and fell back to replacing the entire parameter span with the expected type name. Fix by only emitting the suggestion when we can properly identify the `&` syntax to remove.
This commit is contained in:
@@ -5323,12 +5323,9 @@ fn hint_missing_borrow<'tcx>(
|
||||
ty = mut_ty.ty;
|
||||
left -= 1;
|
||||
}
|
||||
let sugg = if left == 0 {
|
||||
(span, String::new())
|
||||
} else {
|
||||
(arg.span, expected_arg.to_string())
|
||||
};
|
||||
remove_borrow.push(sugg);
|
||||
if left == 0 {
|
||||
remove_borrow.push((span, String::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,6 @@ note: required by a bound in `foo`
|
||||
|
|
||||
LL | fn foo<F: Fn(&char) -> bool + Fn(char) -> bool>(f: F) {
|
||||
| ^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
||||
help: consider adjusting the signature so it does not borrow its argument
|
||||
|
|
||||
LL - foo(move |x| v);
|
||||
LL + foo(move |char| v);
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user