diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-24 13:47:07 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-24 19:56:56 +0200 |
| commit | 65deeae76dfcb8d0aeb389bbe12ef9990caf2f6f (patch) | |
| tree | ad70ac00d70716a9b2c8a8f48548adc800c919ae | |
| parent | 9d69783a46a9f6096b8c2f284876d6a68e2b6455 (diff) | |
| download | rust-65deeae76dfcb8d0aeb389bbe12ef9990caf2f6f.tar.gz rust-65deeae76dfcb8d0aeb389bbe12ef9990caf2f6f.zip | |
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.
| -rw-r--r-- | src/librustc_typeck/check/_match.rs | 5 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 10 | ||||
| -rw-r--r-- | 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 crate::check::coercion::CoerceMany; 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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { 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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - 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 @@ You can read more about trait objects in the Trait Objects section of the Refere 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>, |
