10
10
11
11
use hir:: def:: Def ;
12
12
use rustc:: infer:: { self , InferOk , TypeOrigin } ;
13
- use hir:: pat_util:: { PatIdMap , pat_id_map} ;
14
13
use hir:: pat_util:: { EnumerateAndAdjustIterator , pat_is_resolved_const} ;
15
14
use rustc:: ty:: subst:: Substs ;
16
15
use rustc:: ty:: { self , Ty , TypeFoldable , LvaluePreference } ;
@@ -21,26 +20,13 @@ use session::Session;
21
20
22
21
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
23
22
use std:: cmp;
24
- use std:: ops:: Deref ;
25
23
use syntax:: ast;
26
24
use syntax:: codemap:: { Span , Spanned } ;
27
25
use syntax:: ptr:: P ;
28
26
29
27
use rustc:: hir:: { self , PatKind } ;
30
28
use rustc:: hir:: print as pprust;
31
29
32
- pub struct PatCtxt < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
33
- pub fcx : & ' a FnCtxt < ' a , ' gcx , ' tcx > ,
34
- pub map : PatIdMap ,
35
- }
36
-
37
- impl < ' a , ' gcx , ' tcx > Deref for PatCtxt < ' a , ' gcx , ' tcx > {
38
- type Target = FnCtxt < ' a , ' gcx , ' tcx > ;
39
- fn deref ( & self ) -> & Self :: Target {
40
- self . fcx
41
- }
42
- }
43
-
44
30
// This function exists due to the warning "diagnostic code E0164 already used"
45
31
fn bad_struct_kind_err ( sess : & Session , pat : & hir:: Pat , path : & hir:: Path , lint : bool ) {
46
32
let name = pprust:: path_to_string ( path) ;
@@ -55,7 +41,7 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
55
41
}
56
42
}
57
43
58
- impl < ' a , ' gcx , ' tcx > PatCtxt < ' a , ' gcx , ' tcx > {
44
+ impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
59
45
pub fn check_pat ( & self , pat : & ' gcx hir:: Pat , expected : Ty < ' tcx > ) {
60
46
let tcx = self . tcx ;
61
47
@@ -194,15 +180,19 @@ impl<'a, 'gcx, 'tcx> PatCtxt<'a, 'gcx, 'tcx> {
194
180
195
181
// if there are multiple arms, make sure they all agree on
196
182
// what the type of the binding `x` ought to be
197
- if let Some ( & canon_id) = self . map . get ( & path. node ) {
198
- if canon_id != pat. id {
199
- let ct = self . local_ty ( pat. span , canon_id) ;
200
- self . demand_eqtype ( pat. span , ct, typ) ;
183
+ match tcx. def_map . borrow ( ) [ & pat. id ] . full_def ( ) {
184
+ Def :: Err => { }
185
+ Def :: Local ( _, var_id) => {
186
+ if var_id != pat. id {
187
+ let vt = self . local_ty ( pat. span , var_id) ;
188
+ self . demand_eqtype ( pat. span , vt, typ) ;
189
+ }
201
190
}
191
+ d => bug ! ( "bad def for pattern binding `{:?}`" , d)
192
+ }
202
193
203
- if let Some ( ref p) = * sub {
204
- self . check_pat ( & p, expected) ;
205
- }
194
+ if let Some ( ref p) = * sub {
195
+ self . check_pat ( & p, expected) ;
206
196
}
207
197
}
208
198
PatKind :: TupleStruct ( ref path, ref subpats, ddpos) => {
@@ -476,12 +466,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
476
466
// Typecheck the patterns first, so that we get types for all the
477
467
// bindings.
478
468
for arm in arms {
479
- let pcx = PatCtxt {
480
- fcx : self ,
481
- map : pat_id_map ( & arm. pats [ 0 ] ) ,
482
- } ;
483
469
for p in & arm. pats {
484
- pcx . check_pat ( & p, discrim_ty) ;
470
+ self . check_pat ( & p, discrim_ty) ;
485
471
}
486
472
}
487
473
@@ -566,7 +552,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
566
552
}
567
553
}
568
554
569
- impl < ' a , ' gcx , ' tcx > PatCtxt < ' a , ' gcx , ' tcx > {
555
+ impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
570
556
pub fn check_pat_struct ( & self , pat : & ' gcx hir:: Pat ,
571
557
path : & hir:: Path , fields : & ' gcx [ Spanned < hir:: FieldPat > ] ,
572
558
etc : bool , expected : Ty < ' tcx > ) {
0 commit comments