From 65deeae76dfcb8d0aeb389bbe12ef9990caf2f6f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 24 Aug 2019 13:47:07 +0200 Subject: [PATCH] typeck/pat.rs: `check_pat_top` is the entry point. This clarifies the fact that type checking patterns unconditionally starts with `BindByValue` as the default binding mode making the notion of a default binding mode internal to type checking patterns. --- src/librustc_typeck/check/_match.rs | 5 ++--- src/librustc_typeck/check/mod.rs | 10 ++-------- src/librustc_typeck/check/pat.rs | 12 +++++++++++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 8cb365d91fa..efc37cc04b2 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -3,7 +3,7 @@ use rustc::hir::{self, ExprKind}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::{ObligationCause, ObligationCauseCode}; -use rustc::ty::{self, Ty}; +use rustc::ty::Ty; use syntax_pos::Span; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { @@ -59,8 +59,7 @@ pub fn check_match( let mut all_pats_diverge = Diverges::WarnedAlways; for p in &arm.pats { self.diverges.set(Diverges::Maybe); - let binding_mode = ty::BindingMode::BindByValue(hir::Mutability::MutImmutable); - self.check_pat_walk(&p, discrim_ty, binding_mode, Some(discrim.span)); + self.check_pat_top(&p, discrim_ty, Some(discrim.span)); all_pats_diverge &= self.diverges.get(); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a130d11a5e6..ee505b24875 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1104,8 +1104,7 @@ fn check_fn<'a, 'tcx>( // Add formal parameters. for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) { // Check the pattern. - let binding_mode = ty::BindingMode::BindByValue(hir::Mutability::MutImmutable); - fcx.check_pat_walk(&arg.pat, arg_ty, binding_mode, None); + fcx.check_pat_top(&arg.pat, arg_ty, None); // Check that argument is Sized. // The check for a non-trivial pattern is a hack to avoid duplicate warnings @@ -3631,12 +3630,7 @@ pub fn check_decl_local(&self, local: &'tcx hir::Local) { } } - self.check_pat_walk( - &local.pat, - t, - ty::BindingMode::BindByValue(hir::Mutability::MutImmutable), - None, - ); + self.check_pat_top(&local.pat, t, None); let pat_ty = self.node_ty(local.pat.hir_id); if pat_ty.references_error() { self.write_ty(local.hir_id, pat_ty); diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 59244ec33ca..fc52684b5a2 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -29,6 +29,16 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { + pub fn check_pat_top( + &self, + pat: &'tcx hir::Pat, + expected: Ty<'tcx>, + discrim_span: Option, + ) { + let def_bm = ty::BindingMode::BindByValue(hir::Mutability::MutImmutable); + self.check_pat_walk(pat, expected, def_bm, discrim_span); + } + /// `discrim_span` argument having a `Span` indicates that this pattern is part of a match /// expression arm guard, and it points to the match discriminant to add context in type errors. /// In the following example, `discrim_span` corresponds to the `a + b` expression: @@ -45,7 +55,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// = note: expected type `usize` /// found type `std::result::Result<_, _>` /// ``` - pub fn check_pat_walk( + fn check_pat_walk( &self, pat: &'tcx hir::Pat, expected: Ty<'tcx>,