X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_hir_typeck%2Fsrc%2Fpat.rs;h=46799245222dc45599c6fbcbb71f9c9040109b15;hb=44a500c8c187b245638684748f54bd6ec67e0b25;hp=0143901f2d7a734b910815f5c56bcb7bff040e43;hpb=e94fab69d020d75517cb55fafacb2d270ad6e0ac;p=rust.git diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 0143901f2d7..46799245222 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -1,4 +1,4 @@ -use crate::FnCtxt; +use crate::{FnCtxt, RawTy}; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ @@ -553,6 +553,9 @@ fn emit_err_pat_range( (lhs, Some((true, rhs_ty, rhs_sp))) => one_side_err(rhs_sp, rhs_ty, lhs), _ => span_bug!(span, "Impossible, verified above."), } + if (lhs, rhs).references_error() { + err.downgrade_to_delayed_bug(); + } if self.tcx.sess.teach(&err.get_code().unwrap()) { err.note( "In a match expression, only numbers and characters can be matched \ @@ -758,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( @@ -839,7 +859,7 @@ fn check_pat_path( &self, pat: &Pat<'tcx>, qpath: &hir::QPath<'_>, - path_resolution: (Res, Option>, &'tcx [hir::PathSegment<'tcx>]), + path_resolution: (Res, Option>, &'tcx [hir::PathSegment<'tcx>]), expected: Ty<'tcx>, ti: TopInfo<'tcx>, ) -> Ty<'tcx> {