1
1
use crate :: check:: FnCtxt ;
2
2
use crate :: util:: nodemap:: FxHashMap ;
3
3
use errors:: { Applicability , DiagnosticBuilder } ;
4
- use rustc:: hir:: { self , PatKind , Pat } ;
4
+ use rustc:: hir:: { self , PatKind , Pat , HirId } ;
5
5
use rustc:: hir:: def:: { Res , DefKind , CtorKind } ;
6
6
use rustc:: hir:: pat_util:: EnumerateAndAdjustIterator ;
7
7
use rustc:: hir:: ptr:: P ;
8
8
use rustc:: infer;
9
9
use rustc:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
10
- use rustc:: ty:: { self , Ty , TypeFoldable } ;
10
+ use rustc:: ty:: { self , Ty , BindingMode , TypeFoldable } ;
11
11
use rustc:: ty:: subst:: Kind ;
12
12
use syntax:: ast;
13
13
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
29
29
https://doc.rust-lang.org/reference/types.html#trait-objects";
30
30
31
31
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 ) ;
39
34
self . check_pat ( pat, expected, def_bm, discrim_span) ;
40
35
}
41
36
@@ -57,9 +52,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
57
52
/// ```
58
53
fn check_pat (
59
54
& self ,
60
- pat : & ' tcx hir :: Pat ,
55
+ pat : & ' tcx Pat ,
61
56
expected : Ty < ' tcx > ,
62
- def_bm : ty :: BindingMode ,
57
+ def_bm : BindingMode ,
63
58
discrim_span : Option < Span > ,
64
59
) {
65
60
debug ! ( "check_pat(pat={:?},expected={:?},def_bm={:?})" , pat, expected, def_bm) ;
@@ -179,11 +174,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
179
174
/// as well as the pattern form we are currently checking.
180
175
fn calc_default_binding_mode (
181
176
& self ,
182
- pat : & ' tcx hir :: Pat ,
177
+ pat : & ' tcx Pat ,
183
178
expected : Ty < ' tcx > ,
184
- def_bm : ty :: BindingMode ,
179
+ def_bm : BindingMode ,
185
180
is_non_ref_pat : bool ,
186
- ) -> ( Ty < ' tcx > , ty :: BindingMode ) {
181
+ ) -> ( Ty < ' tcx > , BindingMode ) {
187
182
if is_non_ref_pat {
188
183
debug ! ( "pattern is non reference pattern" ) ;
189
184
self . peel_off_references ( pat, expected, def_bm)
@@ -209,7 +204,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
209
204
210
205
/// Is the pattern a "non reference pattern"?
211
206
/// 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 {
213
208
match pat. node {
214
209
PatKind :: Struct ( ..) |
215
210
PatKind :: TupleStruct ( ..) |
@@ -242,10 +237,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
242
237
/// The adjustments vector, if non-empty is stored in a table.
243
238
fn peel_off_references (
244
239
& self ,
245
- pat : & ' tcx hir :: Pat ,
240
+ pat : & ' tcx Pat ,
246
241
expected : Ty < ' tcx > ,
247
- mut def_bm : ty :: BindingMode ,
248
- ) -> ( Ty < ' tcx > , ty :: BindingMode ) {
242
+ mut def_bm : BindingMode ,
243
+ ) -> ( Ty < ' tcx > , BindingMode ) {
249
244
let mut expected = self . resolve_type_vars_with_obligations ( & expected) ;
250
245
251
246
// Peel off as many `&` or `&mut` from the scrutinee type as possible. For example,
@@ -403,18 +398,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
403
398
404
399
fn check_pat_ident (
405
400
& self ,
406
- pat : & hir :: Pat ,
401
+ pat : & Pat ,
407
402
ba : hir:: BindingAnnotation ,
408
- var_id : hir :: HirId ,
409
- sub : Option < & ' tcx hir :: Pat > ,
403
+ var_id : HirId ,
404
+ sub : Option < & ' tcx Pat > ,
410
405
expected : Ty < ' tcx > ,
411
- def_bm : ty :: BindingMode ,
406
+ def_bm : BindingMode ,
412
407
discrim_span : Option < Span > ,
413
408
) -> Ty < ' tcx > {
414
409
// Determine the binding mode...
415
410
let bm = match ba {
416
411
hir:: BindingAnnotation :: Unannotated => def_bm,
417
- _ => ty :: BindingMode :: convert ( ba) ,
412
+ _ => BindingMode :: convert ( ba) ,
418
413
} ;
419
414
// ...and store it in a side table:
420
415
self . inh
@@ -502,7 +497,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
502
497
}
503
498
}
504
499
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 {
506
501
if let PatKind :: Binding ( ..) = inner. node {
507
502
if let Some ( mt) = self . shallow_resolve ( expected) . builtin_deref ( true ) {
508
503
if let ty:: Dynamic ( ..) = mt. ty . sty {
@@ -530,12 +525,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530
525
531
526
fn check_pat_struct (
532
527
& self ,
533
- pat : & ' tcx hir :: Pat ,
528
+ pat : & ' tcx Pat ,
534
529
qpath : & hir:: QPath ,
535
530
fields : & ' tcx [ hir:: FieldPat ] ,
536
531
etc : bool ,
537
532
expected : Ty < ' tcx > ,
538
- def_bm : ty :: BindingMode ,
533
+ def_bm : BindingMode ,
539
534
discrim_span : Option < Span > ,
540
535
) -> Ty < ' tcx > {
541
536
// Resolve the path and check the definition for errors.
@@ -563,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563
558
564
559
fn check_pat_path (
565
560
& self ,
566
- pat : & hir :: Pat ,
561
+ pat : & Pat ,
567
562
path_resolution : ( Res , Option < Ty < ' tcx > > , & ' b [ hir:: PathSegment ] ) ,
568
563
qpath : & hir:: QPath ,
569
564
expected : Ty < ' tcx > ,
@@ -596,12 +591,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
596
591
597
592
fn check_pat_tuple_struct (
598
593
& self ,
599
- pat : & hir :: Pat ,
594
+ pat : & Pat ,
600
595
qpath : & hir:: QPath ,
601
- subpats : & ' tcx [ P < hir :: Pat > ] ,
596
+ subpats : & ' tcx [ P < Pat > ] ,
602
597
ddpos : Option < usize > ,
603
598
expected : Ty < ' tcx > ,
604
- def_bm : ty :: BindingMode ,
599
+ def_bm : BindingMode ,
605
600
match_arm_pat_span : Option < Span > ,
606
601
) -> Ty < ' tcx > {
607
602
let tcx = self . tcx ;
@@ -700,10 +695,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
700
695
fn check_pat_tuple (
701
696
& self ,
702
697
span : Span ,
703
- elements : & ' tcx [ P < hir :: Pat > ] ,
698
+ elements : & ' tcx [ P < Pat > ] ,
704
699
ddpos : Option < usize > ,
705
700
expected : Ty < ' tcx > ,
706
- def_bm : ty :: BindingMode ,
701
+ def_bm : BindingMode ,
707
702
discrim_span : Option < Span > ,
708
703
) -> Ty < ' tcx > {
709
704
let tcx = self . tcx ;
@@ -748,12 +743,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
748
743
fn check_struct_pat_fields (
749
744
& self ,
750
745
adt_ty : Ty < ' tcx > ,
751
- pat_id : hir :: HirId ,
746
+ pat_id : HirId ,
752
747
span : Span ,
753
748
variant : & ' tcx ty:: VariantDef ,
754
749
fields : & ' tcx [ hir:: FieldPat ] ,
755
750
etc : bool ,
756
- def_bm : ty :: BindingMode ,
751
+ def_bm : BindingMode ,
757
752
) -> bool {
758
753
let tcx = self . tcx ;
759
754
@@ -922,9 +917,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
922
917
fn check_pat_box (
923
918
& self ,
924
919
span : Span ,
925
- inner : & ' tcx hir :: Pat ,
920
+ inner : & ' tcx Pat ,
926
921
expected : Ty < ' tcx > ,
927
- def_bm : ty :: BindingMode ,
922
+ def_bm : BindingMode ,
928
923
discrim_span : Option < Span > ,
929
924
) -> Ty < ' tcx > {
930
925
let tcx = self . tcx ;
@@ -948,11 +943,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
948
943
949
944
fn check_pat_ref (
950
945
& self ,
951
- pat : & hir :: Pat ,
952
- inner : & ' tcx hir :: Pat ,
946
+ pat : & Pat ,
947
+ inner : & ' tcx Pat ,
953
948
mutbl : hir:: Mutability ,
954
949
expected : Ty < ' tcx > ,
955
- def_bm : ty :: BindingMode ,
950
+ def_bm : BindingMode ,
956
951
discrim_span : Option < Span > ,
957
952
) -> Ty < ' tcx > {
958
953
let tcx = self . tcx ;
@@ -1003,11 +998,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1003
998
fn check_pat_slice (
1004
999
& self ,
1005
1000
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 > ] ,
1009
1004
expected : Ty < ' tcx > ,
1010
- def_bm : ty :: BindingMode ,
1005
+ def_bm : BindingMode ,
1011
1006
discrim_span : Option < Span > ,
1012
1007
) -> Ty < ' tcx > {
1013
1008
let tcx = self . tcx ;
0 commit comments