about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/src/pat.rs17
-rw-r--r--src/test/ui/mismatched_types/ref-pat-suggestions.stderr5
2 files changed, 19 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index d3e88b1b80a..837286cfd11 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -758,6 +758,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         err.span_note(sp, format!("{msg}: `{sugg}`"));
                     }
                 }
+                hir::Node::Pat(pt) if let PatKind::TupleStruct(_, pat_arr, _) = pt.kind => {
+                    for i in pat_arr.iter() {
+                        if let PatKind::Ref(the_ref, _) = i.kind
+                        && let PatKind::Binding(mt, _, ident, _) = the_ref.kind {
+                            let hir::BindingAnnotation(_, mtblty) = mt;
+                            err.span_suggestion_verbose(
+                                i.span,
+                                format!("consider removing `&{mutability}` from the pattern"),
+                                mtblty.prefix_str().to_string() + &ident.name.to_string(),
+                                Applicability::MaybeIncorrect,
+                            );
+                        }
+                    }
+                    if let Some((sp, msg, sugg)) = mut_var_suggestion {
+                        err.span_note(sp, format!("{msg}: `{sugg}`"));
+                    }
+                }
                 hir::Node::Param(_) | hir::Node::Arm(_) | hir::Node::Pat(_) => {
                     // rely on match ergonomics or it might be nested `&&pat`
                     err.span_suggestion_verbose(
diff --git a/src/test/ui/mismatched_types/ref-pat-suggestions.stderr b/src/test/ui/mismatched_types/ref-pat-suggestions.stderr
index d9501a9bbc6..63eaa3930b1 100644
--- a/src/test/ui/mismatched_types/ref-pat-suggestions.stderr
+++ b/src/test/ui/mismatched_types/ref-pat-suggestions.stderr
@@ -336,9 +336,8 @@ LL |         let S(&mut _b) = S(0);
    |               ^^^^^^^
 help: consider removing `&mut` from the pattern
    |
-LL -         let S(&mut _b) = S(0);
-LL +         let S(_b) = S(0);
-   |
+LL |         let S(_b) = S(0);
+   |               ~~
 
 error[E0308]: mismatched types
   --> $DIR/ref-pat-suggestions.rs:31:14