mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-03 05:27:36 +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 | ||
bindings-after-at | ||
deref-patterns | ||
move-ref-patterns | ||
rfc-3627-match-ergonomics-2024 | ||
rfc-3637-guard-patterns | ||
usefulness | ||
at-in-struct-patterns.rs | ||
at-in-struct-patterns.stderr | ||
box-pattern-type-mismatch.rs | ||
box-pattern-type-mismatch.stderr | ||
by-move-pattern-binding.rs | ||
by-move-pattern-binding.stderr | ||
byte-string-inference.rs | ||
complexity_limit.rs | ||
complexity_limit.stderr | ||
fn-in-pat.rs | ||
fn-in-pat.stderr | ||
for-loop-bad-item.rs | ||
for-loop-bad-item.stderr | ||
ignore-all-the-things.rs | ||
inc-range-pat.rs | ||
incorrect-placement-of-pattern-modifiers.fixed | ||
incorrect-placement-of-pattern-modifiers.rs | ||
incorrect-placement-of-pattern-modifiers.stderr | ||
integer-range-binding.rs | ||
issue-6449.rs | ||
issue-8351-1.rs | ||
issue-8351-2.rs | ||
issue-10392.rs | ||
issue-11577.rs | ||
issue-12582.rs | ||
issue-14221.rs | ||
issue-14221.stderr | ||
issue-15080.rs | ||
issue-17718-patterns.rs | ||
issue-17718-patterns.stderr | ||
issue-22546.rs | ||
issue-22546.stderr | ||
issue-27320.rs | ||
issue-28992-empty.rs | ||
issue-28992-empty.stderr | ||
issue-52240.rs | ||
issue-52240.stderr | ||
issue-66270-pat-struct-parser-recovery.rs | ||
issue-66270-pat-struct-parser-recovery.stderr | ||
issue-67037-pat-tup-scrut-ty-diff-less-fields.rs | ||
issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr | ||
issue-67776-match-same-name-enum-variant-refs.rs | ||
issue-67776-match-same-name-enum-variant-refs.stderr | ||
issue-72565.rs | ||
issue-72565.stderr | ||
issue-72574-1.rs | ||
issue-72574-1.stderr | ||
issue-72574-2.rs | ||
issue-72574-2.stderr | ||
issue-74539.rs | ||
issue-74539.stderr | ||
issue-74702.rs | ||
issue-74702.stderr | ||
issue-74954.rs | ||
issue-80186-mut-binding-help-suggestion.rs | ||
issue-80186-mut-binding-help-suggestion.stderr | ||
issue-88074-pat-range-type-inference-err.rs | ||
issue-88074-pat-range-type-inference-err.stderr | ||
issue-88074-pat-range-type-inference.rs | ||
issue-92074-macro-ice.rs | ||
issue-92074-macro-ice.stderr | ||
issue-94866.rs | ||
issue-94866.stderr | ||
issue-95878.rs | ||
issue-95878.stderr | ||
issue-106552.rs | ||
issue-106552.stderr | ||
issue-106862.fixed | ||
issue-106862.rs | ||
issue-106862.stderr | ||
issue-110508.rs | ||
issue-115599.rs | ||
issue-115599.stderr | ||
issue-117626.rs | ||
missing_lifetime.rs | ||
missing_lifetime.stderr | ||
mut_preserve_binding_mode_2021.rs | ||
mut_preserve_binding_mode_2021.stderr | ||
mut_preserve_binding_mode_2024.rs | ||
mut-ref-mut-2021.rs | ||
mut-ref-mut-2021.stderr | ||
no_ref_mut_behind_and.rs | ||
no-match-tuple-variant-self-ctor.rs | ||
no-match-tuple-variant-self-ctor.struct_.stderr | ||
no-match-tuple-variant-self-ctor.tuple.stderr | ||
no-patterns-in-args-2.rs | ||
no-patterns-in-args-2.stderr | ||
no-patterns-in-args.rs | ||
no-patterns-in-args.stderr | ||
non-constant-in-const-path.rs | ||
non-constant-in-const-path.stderr | ||
non-structural-match-types.rs | ||
non-structural-match-types.stderr | ||
pat-shadow-in-nested-binding.rs | ||
pat-shadow-in-nested-binding.stderr | ||
pat-struct-field-expr-has-type.rs | ||
pat-struct-field-expr-has-type.stderr | ||
pat-tuple-bad-type.rs | ||
pat-tuple-bad-type.stderr | ||
pat-tuple-field-count-cross.rs | ||
pat-tuple-field-count-cross.stderr | ||
pat-tuple-overfield.rs | ||
pat-tuple-overfield.stderr | ||
pat-tuple-underfield.rs | ||
pat-tuple-underfield.stderr | ||
pat-type-err-formal-param.rs | ||
pat-type-err-formal-param.stderr | ||
pat-type-err-let-stmt.rs | ||
pat-type-err-let-stmt.stderr | ||
patkind-litrange-no-expr.rs | ||
patkind-litrange-no-expr.stderr | ||
patkind-ref-binding-issue-114896.fixed | ||
patkind-ref-binding-issue-114896.rs | ||
patkind-ref-binding-issue-114896.stderr | ||
patkind-ref-binding-issue-122415.fixed | ||
patkind-ref-binding-issue-122415.rs | ||
patkind-ref-binding-issue-122415.stderr | ||
pattern-bad-ref-box-order.fixed | ||
pattern-bad-ref-box-order.rs | ||
pattern-bad-ref-box-order.stderr | ||
pattern-binding-disambiguation.rs | ||
pattern-binding-disambiguation.stderr | ||
pattern-error-continue.rs | ||
pattern-error-continue.stderr | ||
pattern-ident-path-generics.rs | ||
pattern-ident-path-generics.stderr | ||
pattern-tyvar-2.rs | ||
pattern-tyvar-2.stderr | ||
pattern-tyvar.rs | ||
pattern-tyvar.stderr | ||
patterns-dont-match-nt-statement.rs | ||
range-pattern-meant-to-be-slice-rest-pattern.rs | ||
range-pattern-meant-to-be-slice-rest-pattern.stderr | ||
rest-pat-semantic-disallowed.rs | ||
rest-pat-semantic-disallowed.stderr | ||
rest-pat-syntactic.rs | ||
rest-pat-syntactic.stderr | ||
self-ctor-133272.rs | ||
self-ctor-133272.stderr | ||
size-and-align.rs | ||
skipped-ref-pats-issue-125058.rs | ||
skipped-ref-pats-issue-125058.stderr | ||
slice-array-infer.rs | ||
slice-pattern-refutable.rs | ||
slice-pattern-refutable.stderr | ||
slice-patterns-ambiguity.rs | ||
slice-patterns-ambiguity.stderr | ||
slice-patterns-irrefutable.rs | ||
slice-patterns-irrefutable.stderr | ||
slice-patterns-nested.rs | ||
struct-parser-recovery-issue-126344.rs | ||
struct-parser-recovery-issue-126344.stderr | ||
struct-pattern-with-missing-fields-resolve-error.rs | ||
struct-pattern-with-missing-fields-resolve-error.stderr | ||
suggest-adding-appropriate-missing-pattern-excluding-comments.fixed | ||
suggest-adding-appropriate-missing-pattern-excluding-comments.rs | ||
suggest-adding-appropriate-missing-pattern-excluding-comments.stderr | ||
type_mismatch.rs | ||
type_mismatch.stderr |