@@ -5,13 +5,13 @@ use rustc::hir::def_id::DefId;
5
5
use rustc:: hir:: map:: definitions:: DefPathData ;
6
6
use rustc:: middle:: const_val:: { ConstVal , ErrKind } ;
7
7
use rustc:: mir;
8
- use rustc:: traits:: Reveal ;
9
8
use rustc:: ty:: layout:: { self , Size , Align , HasDataLayout , LayoutOf , TyLayout } ;
10
9
use rustc:: ty:: subst:: { Subst , Substs } ;
11
10
use rustc:: ty:: { self , Ty , TyCtxt } ;
11
+ use rustc:: ty:: maps:: TyCtxtAt ;
12
12
use rustc_data_structures:: indexed_vec:: Idx ;
13
13
use rustc:: middle:: const_val:: FrameInfo ;
14
- use syntax:: codemap:: { self , DUMMY_SP , Span } ;
14
+ use syntax:: codemap:: { self , Span } ;
15
15
use syntax:: ast:: Mutability ;
16
16
use rustc:: mir:: interpret:: {
17
17
GlobalId , Value , Pointer , PrimVal , PrimValKind ,
@@ -27,7 +27,7 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
27
27
pub machine : M ,
28
28
29
29
/// The results of the type checker, from rustc.
30
- pub tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
30
+ pub tcx : TyCtxtAt < ' a , ' tcx , ' tcx > ,
31
31
32
32
/// Bounds in scope for polymorphic evaluations.
33
33
pub param_env : ty:: ParamEnv < ' tcx > ,
@@ -45,11 +45,6 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
45
45
/// This prevents infinite loops and huge computations from freezing up const eval.
46
46
/// Remove once halting problem is solved.
47
47
pub ( crate ) steps_remaining : usize ,
48
-
49
- /// The span that is used if no more stack frames are available
50
- ///
51
- /// This happens after successful evaluation when the result is inspected
52
- root_span : codemap:: Span ,
53
48
}
54
49
55
50
/// A stack frame.
@@ -154,15 +149,15 @@ impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout
154
149
impl < ' a , ' mir , ' tcx , M : Machine < ' mir , ' tcx > > layout:: HasTyCtxt < ' tcx > for & ' a EvalContext < ' a , ' mir , ' tcx , M > {
155
150
#[ inline]
156
151
fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' b , ' tcx , ' tcx > {
157
- self . tcx
152
+ * self . tcx
158
153
}
159
154
}
160
155
161
156
impl < ' c , ' b , ' a , ' mir , ' tcx , M : Machine < ' mir , ' tcx > > layout:: HasTyCtxt < ' tcx >
162
157
for & ' c & ' b mut EvalContext < ' a , ' mir , ' tcx , M > {
163
158
#[ inline]
164
159
fn tcx < ' d > ( & ' d self ) -> TyCtxt < ' d , ' tcx , ' tcx > {
165
- self . tcx
160
+ * self . tcx
166
161
}
167
162
}
168
163
@@ -187,11 +182,10 @@ impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf<Ty<'tcx>>
187
182
188
183
impl < ' a , ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > EvalContext < ' a , ' mir , ' tcx , M > {
189
184
pub fn new (
190
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
185
+ tcx : TyCtxtAt < ' a , ' tcx , ' tcx > ,
191
186
param_env : ty:: ParamEnv < ' tcx > ,
192
187
machine : M ,
193
188
memory_data : M :: MemoryData ,
194
- root_span : codemap:: Span ,
195
189
) -> Self {
196
190
EvalContext {
197
191
machine,
@@ -201,7 +195,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
201
195
stack : Vec :: new ( ) ,
202
196
stack_limit : tcx. sess . const_eval_stack_frame_limit . get ( ) ,
203
197
steps_remaining : tcx. sess . const_eval_step_limit . get ( ) ,
204
- root_span,
205
198
}
206
199
}
207
200
@@ -255,15 +248,15 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
255
248
pub ( super ) fn resolve ( & self , def_id : DefId , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
256
249
let substs = self . tcx . trans_apply_param_substs ( self . substs ( ) , & substs) ;
257
250
ty:: Instance :: resolve (
258
- self . tcx ,
251
+ * self . tcx ,
259
252
self . param_env ,
260
253
def_id,
261
254
substs,
262
255
) . ok_or ( EvalErrorKind :: TypeckError . into ( ) ) // turn error prop into a panic to expose associated type in const issue
263
256
}
264
257
265
258
pub ( super ) fn type_is_sized ( & self , ty : Ty < ' tcx > ) -> bool {
266
- ty. is_sized ( self . tcx . at ( DUMMY_SP ) , self . param_env )
259
+ ty. is_sized ( self . tcx , self . param_env )
267
260
}
268
261
269
262
pub fn load_mir (
@@ -290,7 +283,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
290
283
// miri doesn't care about lifetimes, and will choke on some crazy ones
291
284
// let's simply get rid of them
292
285
let without_lifetimes = self . tcx . erase_regions ( & ty) ;
293
- let substituted = without_lifetimes. subst ( self . tcx , substs) ;
286
+ let substituted = without_lifetimes. subst ( * self . tcx , substs) ;
294
287
let substituted = self . tcx . fully_normalize_monormophic_ty ( & substituted) ;
295
288
substituted
296
289
}
@@ -725,7 +718,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
725
718
ty:: TyClosure ( def_id, substs) => {
726
719
let substs = self . tcx . trans_apply_param_substs ( self . substs ( ) , & substs) ;
727
720
let instance = ty:: Instance :: resolve_closure (
728
- self . tcx ,
721
+ * self . tcx ,
729
722
def_id,
730
723
substs,
731
724
ty:: ClosureKind :: FnOnce ,
@@ -748,8 +741,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
748
741
let place = self . eval_place ( place) ?;
749
742
let discr_val = self . read_discriminant_value ( place, ty) ?;
750
743
if let ty:: TyAdt ( adt_def, _) = ty. sty {
751
- trace ! ( "Read discriminant {}, valid discriminants {:?}" , discr_val, adt_def. discriminants( self . tcx) . collect:: <Vec <_>>( ) ) ;
752
- if adt_def. discriminants ( self . tcx ) . all ( |v| {
744
+ trace ! ( "Read discriminant {}, valid discriminants {:?}" , discr_val, adt_def. discriminants( * self . tcx) . collect:: <Vec <_>>( ) ) ;
745
+ if adt_def. discriminants ( * self . tcx ) . all ( |v| {
753
746
discr_val != v. val
754
747
} )
755
748
{
@@ -797,7 +790,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
797
790
798
791
pub fn eval_operand ( & mut self , op : & mir:: Operand < ' tcx > ) -> EvalResult < ' tcx , ValTy < ' tcx > > {
799
792
use rustc:: mir:: Operand :: * ;
800
- let ty = self . monomorphize ( op. ty ( self . mir ( ) , self . tcx ) , self . substs ( ) ) ;
793
+ let ty = self . monomorphize ( op. ty ( self . mir ( ) , * self . tcx ) , self . substs ( ) ) ;
801
794
match * op {
802
795
// FIXME: do some more logic on `move` to invalidate the old location
803
796
Copy ( ref place) |
@@ -905,7 +898,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
905
898
}
906
899
layout:: Variants :: Tagged { .. } => {
907
900
let discr_val = dest_ty. ty_adt_def ( ) . unwrap ( )
908
- . discriminant_for_variant ( self . tcx , variant_index)
901
+ . discriminant_for_variant ( * self . tcx , variant_index)
909
902
. val ;
910
903
911
904
let ( discr_dest, discr) = self . place_field ( dest, mir:: Field :: new ( 0 ) , layout) ?;
@@ -1412,7 +1405,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1412
1405
}
1413
1406
( _, & ty:: TyDynamic ( ref data, _) ) => {
1414
1407
let trait_ref = data. principal ( ) . unwrap ( ) . with_self_ty (
1415
- self . tcx ,
1408
+ * self . tcx ,
1416
1409
src_pointee_ty,
1417
1410
) ;
1418
1411
let trait_ref = self . tcx . erase_regions ( & trait_ref) ;
@@ -1601,18 +1594,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1601
1594
} ;
1602
1595
frames. push ( FrameInfo { span, location } ) ;
1603
1596
}
1604
- let span = if let Some ( frame) = self . stack ( ) . last ( ) {
1605
- let bb = & frame. mir . basic_blocks ( ) [ frame. block ] ;
1606
- if let Some ( stmt) = bb. statements . get ( frame. stmt ) {
1607
- stmt. source_info . span
1608
- } else {
1609
- bb. terminator ( ) . source_info . span
1610
- }
1611
- } else {
1612
- self . root_span
1613
- } ;
1614
1597
trace ! ( "generate stacktrace: {:#?}, {:?}" , frames, explicit_span) ;
1615
- ( frames, span)
1598
+ ( frames, self . tcx . span )
1616
1599
}
1617
1600
1618
1601
pub fn report ( & self , e : & mut EvalError , as_err : bool , explicit_span : Option < Span > ) {
@@ -1660,7 +1643,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1660
1643
} ) ;
1661
1644
trace ! ( "reporting const eval failure at {:?}" , span) ;
1662
1645
let mut err = if as_err {
1663
- :: rustc:: middle:: const_val:: struct_error ( self . tcx , span, "constant evaluation error" )
1646
+ :: rustc:: middle:: const_val:: struct_error ( * self . tcx , span, "constant evaluation error" )
1664
1647
} else {
1665
1648
let node_id = self
1666
1649
. stack ( )
@@ -1722,14 +1705,3 @@ impl<'mir, 'tcx> Frame<'mir, 'tcx> {
1722
1705
return Ok ( old) ;
1723
1706
}
1724
1707
}
1725
-
1726
- // TODO(solson): Upstream these methods into rustc::ty::layout.
1727
-
1728
- pub fn resolve_drop_in_place < ' a , ' tcx > (
1729
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1730
- ty : Ty < ' tcx > ,
1731
- ) -> ty:: Instance < ' tcx > {
1732
- let def_id = tcx. require_lang_item ( :: rustc:: middle:: lang_items:: DropInPlaceFnLangItem ) ;
1733
- let substs = tcx. intern_substs ( & [ ty. into ( ) ] ) ;
1734
- ty:: Instance :: resolve ( tcx, ty:: ParamEnv :: empty ( Reveal :: All ) , def_id, substs) . unwrap ( )
1735
- }
0 commit comments