]> git.lizzy.rs Git - rust.git/commitdiff
typeck/pat.rs: `check_pat_top` is the entry point.
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 11:47:07 +0000 (13:47 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 17:56:56 +0000 (19:56 +0200)
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
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/pat.rs

index 8cb365d91fa7941cdc321d787637e35ce7b40e85..efc37cc04b212b1dd24f32f9418b206b901a04a5 100644 (file)
@@ -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();
             }
 
index a130d11a5e64518651f3dfc54eea943c2c5151a5..ee505b2487532929e54c8457aca48e9bb76f9f34 100644 (file)
@@ -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);
index 59244ec33ca33cdeb17842410383fcf92342a71a..fc52684b5a24c34e79233f20a2e0757bf9b81a92 100644 (file)
 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<Span>,
+    ) {
+        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>,