1
- use rustc:: infer;
2
1
use rustc:: middle:: const_val;
3
2
use rustc:: hir:: def_id:: DefId ;
4
3
use rustc:: mir:: mir_map:: MirMap ;
@@ -25,7 +24,7 @@ const TRACE_EXECUTION: bool = true;
25
24
26
25
struct GlobalEvalContext < ' a , ' tcx : ' a > {
27
26
/// The results of the type checker, from rustc.
28
- tcx : & ' a TyCtxt < ' tcx > ,
27
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
29
28
30
29
/// A mapping from NodeIds to Mir, from rustc. Only contains MIR for crate-local items.
31
30
mir_map : & ' a MirMap < ' tcx > ,
@@ -124,7 +123,7 @@ enum TerminatorTarget {
124
123
}
125
124
126
125
impl < ' a , ' tcx > GlobalEvalContext < ' a , ' tcx > {
127
- fn new ( tcx : & ' a TyCtxt < ' tcx > , mir_map : & ' a MirMap < ' tcx > ) -> Self {
126
+ fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , mir_map : & ' a MirMap < ' tcx > ) -> Self {
128
127
GlobalEvalContext {
129
128
tcx : tcx,
130
129
mir_map : mir_map,
@@ -367,7 +366,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
367
366
let last_ty = self . operand_ty ( last_arg) ;
368
367
let last_layout = self . type_layout ( last_ty) ;
369
368
match ( & last_ty. sty , last_layout) {
370
- ( & ty:: TyTuple ( ref fields) ,
369
+ ( & ty:: TyTuple ( fields) ,
371
370
& Layout :: Univariant { ref variant, .. } ) => {
372
371
let offsets = iter:: once ( 0 )
373
372
. chain ( variant. offset_after_field . iter ( )
@@ -1063,7 +1062,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
1063
1062
1064
1063
fn monomorphize ( & self , ty : ty:: Ty < ' tcx > ) -> ty:: Ty < ' tcx > {
1065
1064
let substituted = ty. subst ( self . tcx , self . substs ( ) ) ;
1066
- infer :: normalize_associated_type ( self . tcx , & substituted)
1065
+ self . tcx . normalize_associated_type ( & substituted)
1067
1066
}
1068
1067
1069
1068
fn type_needs_drop ( & self , ty : ty:: Ty < ' tcx > ) -> bool {
@@ -1080,7 +1079,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
1080
1079
}
1081
1080
1082
1081
fn type_is_sized ( & self , ty : ty:: Ty < ' tcx > ) -> bool {
1083
- ty. is_sized ( & self . tcx . empty_parameter_environment ( ) , DUMMY_SP )
1082
+ ty. is_sized ( self . tcx , & self . tcx . empty_parameter_environment ( ) , DUMMY_SP )
1084
1083
}
1085
1084
1086
1085
fn type_size ( & self , ty : ty:: Ty < ' tcx > ) -> usize {
@@ -1091,10 +1090,10 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
1091
1090
// TODO(solson): Is this inefficient? Needs investigation.
1092
1091
let ty = self . monomorphize ( ty) ;
1093
1092
1094
- let infcx = infer :: normalizing_infer_ctxt ( self . tcx , & self . tcx . tables , ProjectionMode :: Any ) ;
1095
-
1096
- // TODO(solson): Report this error properly.
1097
- ty . layout ( & infcx ) . unwrap ( )
1093
+ self . tcx . normalizing_infer_ctxt ( ProjectionMode :: Any ) . enter ( |infcx| {
1094
+ // TODO(solson): Report this error properly.
1095
+ ty . layout ( & infcx ) . unwrap ( )
1096
+ } )
1098
1097
}
1099
1098
1100
1099
pub fn read_primval ( & mut self , ptr : Pointer , ty : ty:: Ty < ' tcx > ) -> EvalResult < PrimVal > {
@@ -1173,30 +1172,31 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
1173
1172
fn fulfill_obligation ( & self , trait_ref : ty:: PolyTraitRef < ' tcx > ) -> traits:: Vtable < ' tcx , ( ) > {
1174
1173
// Do the initial selection for the obligation. This yields the shallow result we are
1175
1174
// looking for -- that is, what specific impl.
1176
- let infcx = infer:: normalizing_infer_ctxt ( self . tcx , & self . tcx . tables , ProjectionMode :: Any ) ;
1177
- let mut selcx = traits:: SelectionContext :: new ( & infcx) ;
1178
-
1179
- let obligation = traits:: Obligation :: new (
1180
- traits:: ObligationCause :: misc ( DUMMY_SP , ast:: DUMMY_NODE_ID ) ,
1181
- trait_ref. to_poly_trait_predicate ( ) ,
1182
- ) ;
1183
- let selection = selcx. select ( & obligation) . unwrap ( ) . unwrap ( ) ;
1184
-
1185
- // Currently, we use a fulfillment context to completely resolve all nested obligations.
1186
- // This is because they can inform the inference of the impl's type parameters.
1187
- let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
1188
- let vtable = selection. map ( |predicate| {
1189
- fulfill_cx. register_predicate_obligation ( & infcx, predicate) ;
1190
- } ) ;
1191
- infer:: drain_fulfillment_cx_or_panic (
1192
- DUMMY_SP , & infcx, & mut fulfill_cx, & vtable
1193
- )
1175
+ self . tcx . normalizing_infer_ctxt ( ProjectionMode :: Any ) . enter ( |infcx| {
1176
+ let mut selcx = traits:: SelectionContext :: new ( & infcx) ;
1177
+
1178
+ let obligation = traits:: Obligation :: new (
1179
+ traits:: ObligationCause :: misc ( DUMMY_SP , ast:: DUMMY_NODE_ID ) ,
1180
+ trait_ref. to_poly_trait_predicate ( ) ,
1181
+ ) ;
1182
+ let selection = selcx. select ( & obligation) . unwrap ( ) . unwrap ( ) ;
1183
+
1184
+ // Currently, we use a fulfillment context to completely resolve all nested obligations.
1185
+ // This is because they can inform the inference of the impl's type parameters.
1186
+ let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
1187
+ let vtable = selection. map ( |predicate| {
1188
+ fulfill_cx. register_predicate_obligation ( & infcx, predicate) ;
1189
+ } ) ;
1190
+ infcx. drain_fulfillment_cx_or_panic ( DUMMY_SP , & mut fulfill_cx, & vtable)
1191
+ } )
1194
1192
}
1195
1193
1196
1194
/// Trait method, which has to be resolved to an impl method.
1197
- pub fn trait_method ( & self , def_id : DefId , substs : & ' tcx Substs < ' tcx > )
1198
- -> ( DefId , & ' tcx Substs < ' tcx > )
1199
- {
1195
+ pub fn trait_method (
1196
+ & self ,
1197
+ def_id : DefId ,
1198
+ substs : & ' tcx Substs < ' tcx >
1199
+ ) -> ( DefId , & ' tcx Substs < ' tcx > ) {
1200
1200
let method_item = self . tcx . impl_or_trait_item ( def_id) ;
1201
1201
let trait_id = method_item. container ( ) . id ( ) ;
1202
1202
let trait_ref = ty:: Binder ( substs. to_trait_ref ( self . tcx , trait_id) ) ;
@@ -1279,8 +1279,8 @@ pub struct ImplMethod<'tcx> {
1279
1279
}
1280
1280
1281
1281
/// Locates the applicable definition of a method, given its name.
1282
- pub fn get_impl_method < ' tcx > (
1283
- tcx : & TyCtxt < ' tcx > ,
1282
+ pub fn get_impl_method < ' a , ' tcx > (
1283
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1284
1284
impl_def_id : DefId ,
1285
1285
substs : & ' tcx Substs < ' tcx > ,
1286
1286
name : ast:: Name ,
@@ -1289,23 +1289,34 @@ pub fn get_impl_method<'tcx>(
1289
1289
1290
1290
let trait_def_id = tcx. trait_id_of_impl ( impl_def_id) . unwrap ( ) ;
1291
1291
let trait_def = tcx. lookup_trait_def ( trait_def_id) ;
1292
- let infcx = infer:: normalizing_infer_ctxt ( tcx, & tcx. tables , ProjectionMode :: Any ) ;
1293
1292
1294
1293
match trait_def. ancestors ( impl_def_id) . fn_defs ( tcx, name) . next ( ) {
1295
1294
Some ( node_item) => {
1295
+ let substs = tcx. normalizing_infer_ctxt ( ProjectionMode :: Any ) . enter ( |infcx| {
1296
+ let substs = traits:: translate_substs ( & infcx, impl_def_id,
1297
+ substs, node_item. node ) ;
1298
+ tcx. lift ( & substs) . unwrap_or_else ( || {
1299
+ bug ! ( "trans::meth::get_impl_method: translate_substs \
1300
+ returned {:?} which contains inference types/regions",
1301
+ substs) ;
1302
+ } )
1303
+ } ) ;
1296
1304
ImplMethod {
1297
1305
method : node_item. item ,
1298
- substs : traits :: translate_substs ( & infcx , impl_def_id , substs, node_item . node ) ,
1306
+ substs : substs,
1299
1307
is_provided : node_item. node . is_from_trait ( ) ,
1300
1308
}
1301
1309
}
1302
1310
None => {
1303
- bug ! ( "method {:?} not found in {:?}" , name, impl_def_id) ;
1311
+ bug ! ( "method {:?} not found in {:?}" , name, impl_def_id)
1304
1312
}
1305
1313
}
1306
1314
}
1307
1315
1308
- pub fn interpret_start_points < ' tcx > ( tcx : & TyCtxt < ' tcx > , mir_map : & MirMap < ' tcx > ) {
1316
+ pub fn interpret_start_points < ' a , ' tcx > (
1317
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1318
+ mir_map : & MirMap < ' tcx > ,
1319
+ ) {
1309
1320
for ( & id, mir) in & mir_map. map {
1310
1321
for attr in tcx. map . attrs ( id) {
1311
1322
use syntax:: attr:: AttrMetaMethods ;
0 commit comments