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> {
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();
}
// 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
}
}
- 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);
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:
/// = 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>,