mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
![]() 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. |
||
---|---|---|
.. | ||
auxiliary | ||
postfix-match | ||
ref_pat_eat_one_layer_2024 | ||
const_non_normal_zst_ref_pattern.rs | ||
dont-highlight-diverging-arms.rs | ||
dont-highlight-diverging-arms.stderr | ||
expr_before_ident_pat.rs | ||
expr_before_ident_pat.stderr | ||
expr-match-panic-fn.rs | ||
expr-match-panic.rs | ||
guards-parenthesized-and.rs | ||
guards.rs | ||
intended-binding-pattern-is-const.rs | ||
intended-binding-pattern-is-const.stderr | ||
issue-5530.rs | ||
issue-11319.rs | ||
issue-11319.stderr | ||
issue-11940.rs | ||
issue-12552.rs | ||
issue-12552.stderr | ||
issue-18060.rs | ||
issue-26251.rs | ||
issue-26996.rs | ||
issue-27021.rs | ||
issue-33498.rs | ||
issue-36401.rs | ||
issue-37598.rs | ||
issue-42679.rs | ||
issue-46920-byte-array-patterns.rs | ||
issue-56685.rs | ||
issue-56685.stderr | ||
issue-70972-dyn-trait.rs | ||
issue-70972-dyn-trait.stderr | ||
issue-72680.rs | ||
issue-72896-non-partial-eq-const.rs | ||
issue-72896-non-partial-eq-const.stderr | ||
issue-74050-end-span.rs | ||
issue-74050-end-span.stderr | ||
issue-82392.rs | ||
issue-82392.stdout | ||
issue-82866.rs | ||
issue-82866.stderr | ||
issue-84434.rs | ||
issue-91058.rs | ||
issue-91058.stderr | ||
issue-92100.rs | ||
issue-92100.stderr | ||
issue-112438.rs | ||
issue-113012.rs | ||
issue-114691.rs | ||
issue-115681.rs | ||
match_non_exhaustive.rs | ||
match_non_exhaustive.stderr | ||
match-arm-resolving-to-never.rs | ||
match-arm-resolving-to-never.stderr | ||
match-bot-panic.rs | ||
match-disc-bot.rs | ||
match-float.rs | ||
match-fn-call.rs | ||
match-fn-call.stderr | ||
match-ill-type2.rs | ||
match-ill-type2.stderr | ||
match-incompat-type-semi.rs | ||
match-incompat-type-semi.stderr | ||
match-join.rs | ||
match-join.stderr | ||
match-no-arms-unreachable-after.rs | ||
match-no-arms-unreachable-after.stderr | ||
match-on-negative-integer-ranges.rs | ||
match-pattern-field-mismatch-2.rs | ||
match-pattern-field-mismatch-2.stderr | ||
match-pattern-field-mismatch.rs | ||
match-pattern-field-mismatch.stderr | ||
match-range-fail-2.rs | ||
match-range-fail-2.stderr | ||
match-range-fail.rs | ||
match-range-fail.stderr | ||
match-ref-mut-invariance.rs | ||
match-ref-mut-invariance.stderr | ||
match-ref-mut-let-invariance.rs | ||
match-ref-mut-let-invariance.stderr | ||
match-ref-mut-stability.rs | ||
match-struct.rs | ||
match-struct.stderr | ||
match-tag-nullary.rs | ||
match-tag-nullary.stderr | ||
match-tag-unary.rs | ||
match-tag-unary.stderr | ||
match-tail-expr-never-type-error.rs | ||
match-tail-expr-never-type-error.stderr | ||
match-type-err-first-arm.rs | ||
match-type-err-first-arm.stderr | ||
match-unresolved-one-arm.rs | ||
match-unresolved-one-arm.stderr | ||
match-vec-mismatch-2.rs | ||
match-vec-mismatch-2.stderr | ||
match-wildcards.rs | ||
non-first-arm-doesnt-match-expected-return-type.rs | ||
non-first-arm-doesnt-match-expected-return-type.stderr | ||
pattern-deref-miscompile.rs | ||
single-line.rs | ||
single-line.stderr | ||
validate-range-endpoints.rs | ||
validate-range-endpoints.stderr |