]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir_typeck/src/pat.rs
Modify existing bounds if they exist
[rust.git] / compiler / rustc_hir_typeck / src / pat.rs
index 1075378a1595549b4fcef2d7f208406ebd576633..46799245222dc45599c6fbcbb71f9c9040109b15 100644 (file)
@@ -761,6 +761,23 @@ fn borrow_pat_suggestion(&self, err: &mut Diagnostic, pat: &Pat<'_>) {
                         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(