Commit 7ee6257
authored
Rollup merge of #151035 - issue-150693-closure-arg-suggestion, r=jieyouxu
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 would incorrectly propose `|char|` instead of something valid like `|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.
Fixes #1506932 files changed
Lines changed: 3 additions & 11 deletions
File tree
- compiler/rustc_trait_selection/src/error_reporting/traits
- tests/ui/closures
Lines changed: 3 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5323 | 5323 | | |
5324 | 5324 | | |
5325 | 5325 | | |
5326 | | - | |
5327 | | - | |
5328 | | - | |
5329 | | - | |
5330 | | - | |
5331 | | - | |
| 5326 | + | |
| 5327 | + | |
| 5328 | + | |
5332 | 5329 | | |
5333 | 5330 | | |
5334 | 5331 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | 22 | | |
28 | 23 | | |
29 | 24 | | |
| |||
0 commit comments