Skip to content

Commit 97986b5

Browse files
committed
typeck/pat.rs: some common imports.
1 parent 41e8aed commit 97986b5

File tree

1 file changed

+38
-43
lines changed
  • src/librustc_typeck/check

1 file changed

+38
-43
lines changed

src/librustc_typeck/check/pat.rs

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::check::FnCtxt;
22
use crate::util::nodemap::FxHashMap;
33
use errors::{Applicability, DiagnosticBuilder};
4-
use rustc::hir::{self, PatKind, Pat};
4+
use rustc::hir::{self, PatKind, Pat, HirId};
55
use rustc::hir::def::{Res, DefKind, CtorKind};
66
use rustc::hir::pat_util::EnumerateAndAdjustIterator;
77
use rustc::hir::ptr::P;
88
use rustc::infer;
99
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
10-
use rustc::ty::{self, Ty, TypeFoldable};
10+
use rustc::ty::{self, Ty, BindingMode, TypeFoldable};
1111
use rustc::ty::subst::Kind;
1212
use syntax::ast;
1313
use syntax::util::lev_distance::find_best_match_for_name;
@@ -29,13 +29,8 @@ 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);
32+
pub fn check_pat_top(&self, pat: &'tcx Pat, expected: Ty<'tcx>, discrim_span: Option<Span>) {
33+
let def_bm = BindingMode::BindByValue(hir::Mutability::MutImmutable);
3934
self.check_pat(pat, expected, def_bm, discrim_span);
4035
}
4136

@@ -57,9 +52,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5752
/// ```
5853
fn check_pat(
5954
&self,
60-
pat: &'tcx hir::Pat,
55+
pat: &'tcx Pat,
6156
expected: Ty<'tcx>,
62-
def_bm: ty::BindingMode,
57+
def_bm: BindingMode,
6358
discrim_span: Option<Span>,
6459
) {
6560
debug!("check_pat(pat={:?},expected={:?},def_bm={:?})", pat, expected, def_bm);
@@ -179,11 +174,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
179174
/// as well as the pattern form we are currently checking.
180175
fn calc_default_binding_mode(
181176
&self,
182-
pat: &'tcx hir::Pat,
177+
pat: &'tcx Pat,
183178
expected: Ty<'tcx>,
184-
def_bm: ty::BindingMode,
179+
def_bm: BindingMode,
185180
is_non_ref_pat: bool,
186-
) -> (Ty<'tcx>, ty::BindingMode) {
181+
) -> (Ty<'tcx>, BindingMode) {
187182
if is_non_ref_pat {
188183
debug!("pattern is non reference pattern");
189184
self.peel_off_references(pat, expected, def_bm)
@@ -209,7 +204,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
209204

210205
/// Is the pattern a "non reference pattern"?
211206
/// When the pattern is a path pattern, `opt_path_res` must be `Some(res)`.
212-
fn is_non_ref_pat(&self, pat: &'tcx hir::Pat, opt_path_res: Option<Res>) -> bool {
207+
fn is_non_ref_pat(&self, pat: &'tcx Pat, opt_path_res: Option<Res>) -> bool {
213208
match pat.node {
214209
PatKind::Struct(..) |
215210
PatKind::TupleStruct(..) |
@@ -242,10 +237,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
242237
/// The adjustments vector, if non-empty is stored in a table.
243238
fn peel_off_references(
244239
&self,
245-
pat: &'tcx hir::Pat,
240+
pat: &'tcx Pat,
246241
expected: Ty<'tcx>,
247-
mut def_bm: ty::BindingMode,
248-
) -> (Ty<'tcx>, ty::BindingMode) {
242+
mut def_bm: BindingMode,
243+
) -> (Ty<'tcx>, BindingMode) {
249244
let mut expected = self.resolve_type_vars_with_obligations(&expected);
250245

251246
// Peel off as many `&` or `&mut` from the scrutinee type as possible. For example,
@@ -403,18 +398,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
403398

404399
fn check_pat_ident(
405400
&self,
406-
pat: &hir::Pat,
401+
pat: &Pat,
407402
ba: hir::BindingAnnotation,
408-
var_id: hir::HirId,
409-
sub: Option<&'tcx hir::Pat>,
403+
var_id: HirId,
404+
sub: Option<&'tcx Pat>,
410405
expected: Ty<'tcx>,
411-
def_bm: ty::BindingMode,
406+
def_bm: BindingMode,
412407
discrim_span: Option<Span>,
413408
) -> Ty<'tcx> {
414409
// Determine the binding mode...
415410
let bm = match ba {
416411
hir::BindingAnnotation::Unannotated => def_bm,
417-
_ => ty::BindingMode::convert(ba),
412+
_ => BindingMode::convert(ba),
418413
};
419414
// ...and store it in a side table:
420415
self.inh
@@ -502,7 +497,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
502497
}
503498
}
504499

505-
pub fn check_dereferencable(&self, span: Span, expected: Ty<'tcx>, inner: &hir::Pat) -> bool {
500+
pub fn check_dereferencable(&self, span: Span, expected: Ty<'tcx>, inner: &Pat) -> bool {
506501
if let PatKind::Binding(..) = inner.node {
507502
if let Some(mt) = self.shallow_resolve(expected).builtin_deref(true) {
508503
if let ty::Dynamic(..) = mt.ty.sty {
@@ -530,12 +525,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530525

531526
fn check_pat_struct(
532527
&self,
533-
pat: &'tcx hir::Pat,
528+
pat: &'tcx Pat,
534529
qpath: &hir::QPath,
535530
fields: &'tcx [hir::FieldPat],
536531
etc: bool,
537532
expected: Ty<'tcx>,
538-
def_bm: ty::BindingMode,
533+
def_bm: BindingMode,
539534
discrim_span: Option<Span>,
540535
) -> Ty<'tcx> {
541536
// Resolve the path and check the definition for errors.
@@ -563,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563558

564559
fn check_pat_path(
565560
&self,
566-
pat: &hir::Pat,
561+
pat: &Pat,
567562
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment]),
568563
qpath: &hir::QPath,
569564
expected: Ty<'tcx>,
@@ -596,12 +591,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
596591

597592
fn check_pat_tuple_struct(
598593
&self,
599-
pat: &hir::Pat,
594+
pat: &Pat,
600595
qpath: &hir::QPath,
601-
subpats: &'tcx [P<hir::Pat>],
596+
subpats: &'tcx [P<Pat>],
602597
ddpos: Option<usize>,
603598
expected: Ty<'tcx>,
604-
def_bm: ty::BindingMode,
599+
def_bm: BindingMode,
605600
match_arm_pat_span: Option<Span>,
606601
) -> Ty<'tcx> {
607602
let tcx = self.tcx;
@@ -700,10 +695,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
700695
fn check_pat_tuple(
701696
&self,
702697
span: Span,
703-
elements: &'tcx [P<hir::Pat>],
698+
elements: &'tcx [P<Pat>],
704699
ddpos: Option<usize>,
705700
expected: Ty<'tcx>,
706-
def_bm: ty::BindingMode,
701+
def_bm: BindingMode,
707702
discrim_span: Option<Span>,
708703
) -> Ty<'tcx> {
709704
let tcx = self.tcx;
@@ -748,12 +743,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
748743
fn check_struct_pat_fields(
749744
&self,
750745
adt_ty: Ty<'tcx>,
751-
pat_id: hir::HirId,
746+
pat_id: HirId,
752747
span: Span,
753748
variant: &'tcx ty::VariantDef,
754749
fields: &'tcx [hir::FieldPat],
755750
etc: bool,
756-
def_bm: ty::BindingMode,
751+
def_bm: BindingMode,
757752
) -> bool {
758753
let tcx = self.tcx;
759754

@@ -922,9 +917,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
922917
fn check_pat_box(
923918
&self,
924919
span: Span,
925-
inner: &'tcx hir::Pat,
920+
inner: &'tcx Pat,
926921
expected: Ty<'tcx>,
927-
def_bm: ty::BindingMode,
922+
def_bm: BindingMode,
928923
discrim_span: Option<Span>,
929924
) -> Ty<'tcx> {
930925
let tcx = self.tcx;
@@ -948,11 +943,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
948943

949944
fn check_pat_ref(
950945
&self,
951-
pat: &hir::Pat,
952-
inner: &'tcx hir::Pat,
946+
pat: &Pat,
947+
inner: &'tcx Pat,
953948
mutbl: hir::Mutability,
954949
expected: Ty<'tcx>,
955-
def_bm: ty::BindingMode,
950+
def_bm: BindingMode,
956951
discrim_span: Option<Span>,
957952
) -> Ty<'tcx> {
958953
let tcx = self.tcx;
@@ -1003,11 +998,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1003998
fn check_pat_slice(
1004999
&self,
10051000
span: Span,
1006-
before: &'tcx [P<hir::Pat>],
1007-
slice: Option<&'tcx hir::Pat>,
1008-
after: &'tcx [P<hir::Pat>],
1001+
before: &'tcx [P<Pat>],
1002+
slice: Option<&'tcx Pat>,
1003+
after: &'tcx [P<Pat>],
10091004
expected: Ty<'tcx>,
1010-
def_bm: ty::BindingMode,
1005+
def_bm: BindingMode,
10111006
discrim_span: Option<Span>,
10121007
) -> Ty<'tcx> {
10131008
let tcx = self.tcx;

0 commit comments

Comments
 (0)