10
10
11
11
use hir:: def:: { self , Def } ;
12
12
use rustc:: infer:: { self , InferOk , TypeOrigin } ;
13
- use hir:: pat_util:: { PatIdMap , pat_id_map, pat_is_binding} ;
14
- use hir:: pat_util:: pat_is_resolved_const;
13
+ use hir:: pat_util:: { pat_is_binding, pat_is_resolved_const} ;
15
14
use rustc:: ty:: subst:: Substs ;
16
15
use rustc:: ty:: { self , Ty , TypeFoldable , LvaluePreference } ;
17
16
use check:: { FnCtxt , Expectation } ;
@@ -21,26 +20,13 @@ use session::Session;
21
20
22
21
use std:: cmp;
23
22
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
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
@@ -170,7 +156,7 @@ impl<'a, 'gcx, 'tcx> PatCtxt<'a, 'gcx, 'tcx> {
170
156
self . write_error ( pat. id ) ;
171
157
}
172
158
}
173
- PatKind :: Ident ( bm, ref path , ref sub)
159
+ PatKind :: Ident ( bm, _ , ref sub)
174
160
if pat_is_binding ( & tcx. def_map . borrow ( ) , pat) => {
175
161
let typ = self . local_ty ( pat. span , pat. id ) ;
176
162
match bm {
@@ -200,15 +186,19 @@ impl<'a, 'gcx, 'tcx> PatCtxt<'a, 'gcx, 'tcx> {
200
186
201
187
// if there are multiple arms, make sure they all agree on
202
188
// what the type of the binding `x` ought to be
203
- if let Some ( & canon_id) = self . map . get ( & path. node ) {
204
- if canon_id != pat. id {
205
- let ct = self . local_ty ( pat. span , canon_id) ;
206
- self . demand_eqtype ( pat. span , ct, typ) ;
189
+ match tcx. def_map . borrow ( ) [ & pat. id ] . full_def ( ) {
190
+ Def :: Err => { }
191
+ Def :: Local ( _, var_id) => {
192
+ if var_id != pat. id {
193
+ let vt = self . local_ty ( pat. span , var_id) ;
194
+ self . demand_eqtype ( pat. span , vt, typ) ;
195
+ }
207
196
}
197
+ d => bug ! ( "bad def for pattern binding `{:?}`" , d)
198
+ }
208
199
209
- if let Some ( ref p) = * sub {
210
- self . check_pat ( & p, expected) ;
211
- }
200
+ if let Some ( ref p) = * sub {
201
+ self . check_pat ( & p, expected) ;
212
202
}
213
203
}
214
204
PatKind :: Ident ( _, ref path, _) => {
@@ -486,12 +476,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
486
476
// Typecheck the patterns first, so that we get types for all the
487
477
// bindings.
488
478
for arm in arms {
489
- let pcx = PatCtxt {
490
- fcx : self ,
491
- map : pat_id_map ( & tcx. def_map , & arm. pats [ 0 ] ) ,
492
- } ;
493
479
for p in & arm. pats {
494
- pcx . check_pat ( & p, discrim_ty) ;
480
+ self . check_pat ( & p, discrim_ty) ;
495
481
}
496
482
}
497
483
@@ -576,7 +562,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
576
562
}
577
563
}
578
564
579
- impl < ' a , ' gcx , ' tcx > PatCtxt < ' a , ' gcx , ' tcx > {
565
+ impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
580
566
pub fn check_pat_struct ( & self , pat : & ' gcx hir:: Pat ,
581
567
path : & hir:: Path , fields : & ' gcx [ Spanned < hir:: FieldPat > ] ,
582
568
etc : bool , expected : Ty < ' tcx > ) {
0 commit comments