Skip to content

Commit 65deeae

Browse files
committed
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.
1 parent 9d69783 commit 65deeae

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::check::coercion::CoerceMany;
33
use rustc::hir::{self, ExprKind};
44
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
55
use rustc::traits::{ObligationCause, ObligationCauseCode};
6-
use rustc::ty::{self, Ty};
6+
use rustc::ty::Ty;
77
use syntax_pos::Span;
88

99
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -59,8 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5959
let mut all_pats_diverge = Diverges::WarnedAlways;
6060
for p in &arm.pats {
6161
self.diverges.set(Diverges::Maybe);
62-
let binding_mode = ty::BindingMode::BindByValue(hir::Mutability::MutImmutable);
63-
self.check_pat_walk(&p, discrim_ty, binding_mode, Some(discrim.span));
62+
self.check_pat_top(&p, discrim_ty, Some(discrim.span));
6463
all_pats_diverge &= self.diverges.get();
6564
}
6665

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,7 @@ fn check_fn<'a, 'tcx>(
11041104
// Add formal parameters.
11051105
for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) {
11061106
// Check the pattern.
1107-
let binding_mode = ty::BindingMode::BindByValue(hir::Mutability::MutImmutable);
1108-
fcx.check_pat_walk(&arg.pat, arg_ty, binding_mode, None);
1107+
fcx.check_pat_top(&arg.pat, arg_ty, None);
11091108

11101109
// Check that argument is Sized.
11111110
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
@@ -3631,12 +3630,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36313630
}
36323631
}
36333632

3634-
self.check_pat_walk(
3635-
&local.pat,
3636-
t,
3637-
ty::BindingMode::BindByValue(hir::Mutability::MutImmutable),
3638-
None,
3639-
);
3633+
self.check_pat_top(&local.pat, t, None);
36403634
let pat_ty = self.node_ty(local.pat.hir_id);
36413635
if pat_ty.references_error() {
36423636
self.write_ty(local.hir_id, pat_ty);

src/librustc_typeck/check/pat.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ You can read more about trait objects in the Trait Objects section of the Refere
2929
https://doc.rust-lang.org/reference/types.html#trait-objects";
3030

3131
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32+
pub fn check_pat_top(
33+
&self,
34+
pat: &'tcx hir::Pat,
35+
expected: Ty<'tcx>,
36+
discrim_span: Option<Span>,
37+
) {
38+
let def_bm = ty::BindingMode::BindByValue(hir::Mutability::MutImmutable);
39+
self.check_pat_walk(pat, expected, def_bm, discrim_span);
40+
}
41+
3242
/// `discrim_span` argument having a `Span` indicates that this pattern is part of a match
3343
/// expression arm guard, and it points to the match discriminant to add context in type errors.
3444
/// In the following example, `discrim_span` corresponds to the `a + b` expression:
@@ -45,7 +55,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4555
/// = note: expected type `usize`
4656
/// found type `std::result::Result<_, _>`
4757
/// ```
48-
pub fn check_pat_walk(
58+
fn check_pat_walk(
4959
&self,
5060
pat: &'tcx hir::Pat,
5161
expected: Ty<'tcx>,

0 commit comments

Comments
 (0)