@@ -266,17 +266,19 @@ impl<'tcx> fmt::Display for Pattern<'tcx> {
266
266
}
267
267
}
268
268
269
- pub struct PatternContext < ' a , ' gcx : ' tcx , ' tcx : ' a > {
270
- pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
271
- pub tables : & ' a ty:: TypeckTables < ' gcx > ,
269
+ pub struct PatternContext < ' a , ' tcx : ' a > {
270
+ pub tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
271
+ pub tables : & ' a ty:: TypeckTables < ' tcx > ,
272
+ pub substs : & ' tcx Substs < ' tcx > ,
272
273
pub errors : Vec < PatternError < ' tcx > > ,
273
274
}
274
275
275
- impl < ' a , ' gcx , ' tcx > Pattern < ' tcx > {
276
- pub fn from_hir ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
277
- tables : & ' a ty:: TypeckTables < ' gcx > ,
276
+ impl < ' a , ' tcx > Pattern < ' tcx > {
277
+ pub fn from_hir ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
278
+ tables : & ' a ty:: TypeckTables < ' tcx > ,
279
+ substs : & ' tcx Substs < ' tcx > ,
278
280
pat : & hir:: Pat ) -> Self {
279
- let mut pcx = PatternContext :: new ( tcx, tables) ;
281
+ let mut pcx = PatternContext :: new ( tcx, tables, substs ) ;
280
282
let result = pcx. lower_pattern ( pat) ;
281
283
if !pcx. errors . is_empty ( ) {
282
284
span_bug ! ( pat. span, "encountered errors lowering pattern: {:?}" , pcx. errors)
@@ -286,9 +288,11 @@ impl<'a, 'gcx, 'tcx> Pattern<'tcx> {
286
288
}
287
289
}
288
290
289
- impl < ' a , ' gcx , ' tcx > PatternContext < ' a , ' gcx , ' tcx > {
290
- pub fn new ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , tables : & ' a ty:: TypeckTables < ' gcx > ) -> Self {
291
- PatternContext { tcx : tcx, tables : tables, errors : vec ! [ ] }
291
+ impl < ' a , ' tcx > PatternContext < ' a , ' tcx > {
292
+ pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
293
+ tables : & ' a ty:: TypeckTables < ' tcx > ,
294
+ substs : & ' tcx Substs < ' tcx > ) -> Self {
295
+ PatternContext { tcx, tables, substs, errors : vec ! [ ] }
292
296
}
293
297
294
298
pub fn lower_pattern ( & mut self , pat : & hir:: Pat ) -> Pattern < ' tcx > {
@@ -583,20 +587,22 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
583
587
let def = self . tables . qpath_def ( qpath, id) ;
584
588
let kind = match def {
585
589
Def :: Const ( def_id) | Def :: AssociatedConst ( def_id) => {
586
- let tcx = self . tcx . global_tcx ( ) ;
587
590
let substs = self . tables . node_substs ( id) ;
588
- match eval:: lookup_const_by_id ( tcx, def_id, substs) {
589
- Some ( ( def_id, _substs ) ) => {
590
- // Enter the inlined constant's tables temporarily.
591
+ match eval:: lookup_const_by_id ( self . tcx , def_id, substs) {
592
+ Some ( ( def_id, substs ) ) => {
593
+ // Enter the inlined constant's tables&substs temporarily.
591
594
let old_tables = self . tables ;
592
- self . tables = tcx. typeck_tables_of ( def_id) ;
593
- let body = if let Some ( id) = tcx. hir . as_local_node_id ( def_id) {
594
- tcx. hir . body ( tcx. hir . body_owned_by ( id) )
595
+ let old_substs = self . substs ;
596
+ self . tables = self . tcx . typeck_tables_of ( def_id) ;
597
+ self . substs = substs;
598
+ let body = if let Some ( id) = self . tcx . hir . as_local_node_id ( def_id) {
599
+ self . tcx . hir . body ( self . tcx . hir . body_owned_by ( id) )
595
600
} else {
596
- tcx. sess . cstore . item_body ( tcx, def_id)
601
+ self . tcx . sess . cstore . item_body ( self . tcx , def_id)
597
602
} ;
598
603
let pat = self . lower_const_expr ( & body. value , pat_id, span) ;
599
604
self . tables = old_tables;
605
+ self . substs = old_substs;
600
606
return pat;
601
607
}
602
608
None => {
@@ -616,7 +622,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
616
622
}
617
623
618
624
fn lower_lit ( & mut self , expr : & hir:: Expr ) -> PatternKind < ' tcx > {
619
- let const_cx = eval:: ConstContext :: with_tables ( self . tcx . global_tcx ( ) , self . tables ) ;
625
+ let const_cx = eval:: ConstContext :: new ( self . tcx , self . tables , self . substs ) ;
620
626
match const_cx. eval ( expr) {
621
627
Ok ( value) => {
622
628
if let ConstVal :: Variant ( def_id) = value {
0 commit comments