1010
1111use hir:: def:: { self , Def } ;
1212use 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} ;
1514use rustc:: ty:: subst:: Substs ;
1615use rustc:: ty:: { self , Ty , TypeFoldable , LvaluePreference } ;
1716use check:: { FnCtxt , Expectation } ;
@@ -21,26 +20,13 @@ use session::Session;
2120
2221use std:: cmp;
2322use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
24- use std:: ops:: Deref ;
2523use syntax:: ast;
2624use syntax:: codemap:: { Span , Spanned } ;
2725use syntax:: ptr:: P ;
2826
2927use rustc:: hir:: { self , PatKind } ;
3028use rustc:: hir:: print as pprust;
3129
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-
4430// This function exists due to the warning "diagnostic code E0164 already used"
4531fn bad_struct_kind_err ( sess : & Session , pat : & hir:: Pat , path : & hir:: Path , lint : bool ) {
4632 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
5541 }
5642}
5743
58- impl < ' a , ' gcx , ' tcx > PatCtxt < ' a , ' gcx , ' tcx > {
44+ impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
5945 pub fn check_pat ( & self , pat : & ' gcx hir:: Pat , expected : Ty < ' tcx > ) {
6046 let tcx = self . tcx ;
6147
@@ -170,7 +156,7 @@ impl<'a, 'gcx, 'tcx> PatCtxt<'a, 'gcx, 'tcx> {
170156 self . write_error ( pat. id ) ;
171157 }
172158 }
173- PatKind :: Ident ( bm, ref path , ref sub)
159+ PatKind :: Ident ( bm, _ , ref sub)
174160 if pat_is_binding ( & tcx. def_map . borrow ( ) , pat) => {
175161 let typ = self . local_ty ( pat. span , pat. id ) ;
176162 match bm {
@@ -200,15 +186,19 @@ impl<'a, 'gcx, 'tcx> PatCtxt<'a, 'gcx, 'tcx> {
200186
201187 // if there are multiple arms, make sure they all agree on
202188 // 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+ }
207196 }
197+ d => bug ! ( "bad def for pattern binding `{:?}`" , d)
198+ }
208199
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) ;
212202 }
213203 }
214204 PatKind :: Ident ( _, ref path, _) => {
@@ -486,12 +476,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
486476 // Typecheck the patterns first, so that we get types for all the
487477 // bindings.
488478 for arm in arms {
489- let pcx = PatCtxt {
490- fcx : self ,
491- map : pat_id_map ( & tcx. def_map , & arm. pats [ 0 ] ) ,
492- } ;
493479 for p in & arm. pats {
494- pcx . check_pat ( & p, discrim_ty) ;
480+ self . check_pat ( & p, discrim_ty) ;
495481 }
496482 }
497483
@@ -576,7 +562,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
576562 }
577563}
578564
579- impl < ' a , ' gcx , ' tcx > PatCtxt < ' a , ' gcx , ' tcx > {
565+ impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
580566 pub fn check_pat_struct ( & self , pat : & ' gcx hir:: Pat ,
581567 path : & hir:: Path , fields : & ' gcx [ Spanned < hir:: FieldPat > ] ,
582568 etc : bool , expected : Ty < ' tcx > ) {
0 commit comments