diff options
| author | Trevor Gross <t.gross35@gmail.com> | 2024-12-31 18:42:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-31 18:42:23 -0500 |
| commit | 3d3d898a2edbaa08c30c1c80830b1ab2e3c9e7a6 (patch) | |
| tree | ed8036083dea921d72c871bba957ef15b3fa787c /tests/codegen/patchable-function-entry | |
| parent | ecfb85b3e1f6e7674609c47bee8f5da2d08576bf (diff) | |
| parent | 04d9bb7a9a697f71abc4aac849a262f713807f29 (diff) | |
| download | rust-3d3d898a2edbaa08c30c1c80830b1ab2e3c9e7a6.tar.gz rust-3d3d898a2edbaa08c30c1c80830b1ab2e3c9e7a6.zip | |
Rollup merge of #133486 - dianne:fix-move-error-suggestion, r=estebank
borrowck diagnostics: make `add_move_error_suggestions` use the HIR rather than `SourceMap` This PR aims to fix #132806 by rewriting `add_move_error_suggestions`[^1]. Previously, it manually scanned the source text to find a leading `&`, which isn't always going to produce a correct result (see: that issue). Admittedly, the HIR visitor in this PR introduces a lot of boilerplate, but hopefully the logic at its core isn't too complicated (I go over it in the comments). I also tried a simpler version that didn't use a HIR visitor and suggested adding `ref` always, but the `&ref x` suggestions really didn't look good. As a bonus for the added complexity though, it's now able to produce nice `&`-removing suggestions in more cases. I tried to do this such that it avoids edition-dependent checks and its suggestions can be applied together with those from the match ergonomics 2024 migration lint. I haven't added tests for that since the details of match ergonomics 2024 are still being sorted out, but I can try if desired once that's finalized. [^1]: In brief, it fires on patterns where users try to bind by-value in such a way that moves out of a reference to a non-Copy type (including slice references with non-copy elements). The suggestions are to change the binding's mode to be by-reference, either by removing[^2] an enclosing `&`/`&mut` or adding `ref` to the binding. [^2]: Incidentally, I find the terminology of "consider removing the borrow" a bit confusing for a suggestion to remove a `&` pattern in order to make bindings borrow rather than move. I'm not sure what a good, concise way to explain that would be though, and that should go in a separate PR anyway.
Diffstat (limited to 'tests/codegen/patchable-function-entry')
0 files changed, 0 insertions, 0 deletions
