@@ -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
- use rustc:: ty:: subst:: { Subst , Substs , Kind } ;
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 , self . param_env , DUMMY_SP )
259
+ ty. is_sized ( * self . tcx , self . param_env , self . tcx . span )
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
}
@@ -721,7 +714,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
721
714
ty:: TyClosure ( def_id, substs) => {
722
715
let substs = self . tcx . trans_apply_param_substs ( self . substs ( ) , & substs) ;
723
716
let instance = ty:: Instance :: resolve_closure (
724
- self . tcx ,
717
+ * self . tcx ,
725
718
def_id,
726
719
substs,
727
720
ty:: ClosureKind :: FnOnce ,
@@ -744,8 +737,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
744
737
let place = self . eval_place ( place) ?;
745
738
let discr_val = self . read_discriminant_value ( place, ty) ?;
746
739
if let ty:: TyAdt ( adt_def, _) = ty. sty {
747
- trace ! ( "Read discriminant {}, valid discriminants {:?}" , discr_val, adt_def. discriminants( self . tcx) . collect:: <Vec <_>>( ) ) ;
748
- if adt_def. discriminants ( self . tcx ) . all ( |v| {
740
+ trace ! ( "Read discriminant {}, valid discriminants {:?}" , discr_val, adt_def. discriminants( * self . tcx) . collect:: <Vec <_>>( ) ) ;
741
+ if adt_def. discriminants ( * self . tcx ) . all ( |v| {
749
742
discr_val != v. val
750
743
} )
751
744
{
@@ -793,7 +786,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
793
786
794
787
pub fn eval_operand ( & mut self , op : & mir:: Operand < ' tcx > ) -> EvalResult < ' tcx , ValTy < ' tcx > > {
795
788
use rustc:: mir:: Operand :: * ;
796
- let ty = self . monomorphize ( op. ty ( self . mir ( ) , self . tcx ) , self . substs ( ) ) ;
789
+ let ty = self . monomorphize ( op. ty ( self . mir ( ) , * self . tcx ) , self . substs ( ) ) ;
797
790
match * op {
798
791
// FIXME: do some more logic on `move` to invalidate the old location
799
792
Copy ( ref place) |
@@ -901,7 +894,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
901
894
}
902
895
layout:: Variants :: Tagged { .. } => {
903
896
let discr_val = dest_ty. ty_adt_def ( ) . unwrap ( )
904
- . discriminant_for_variant ( self . tcx , variant_index)
897
+ . discriminant_for_variant ( * self . tcx , variant_index)
905
898
. val ;
906
899
907
900
let ( discr_dest, discr) = self . place_field ( dest, mir:: Field :: new ( 0 ) , layout) ?;
@@ -1408,7 +1401,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1408
1401
}
1409
1402
( _, & ty:: TyDynamic ( ref data, _) ) => {
1410
1403
let trait_ref = data. principal ( ) . unwrap ( ) . with_self_ty (
1411
- self . tcx ,
1404
+ * self . tcx ,
1412
1405
src_pointee_ty,
1413
1406
) ;
1414
1407
let trait_ref = self . tcx . erase_regions ( & trait_ref) ;
@@ -1597,18 +1590,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1597
1590
} ;
1598
1591
frames. push ( FrameInfo { span, location } ) ;
1599
1592
}
1600
- let span = if let Some ( frame) = self . stack ( ) . last ( ) {
1601
- let bb = & frame. mir . basic_blocks ( ) [ frame. block ] ;
1602
- if let Some ( stmt) = bb. statements . get ( frame. stmt ) {
1603
- stmt. source_info . span
1604
- } else {
1605
- bb. terminator ( ) . source_info . span
1606
- }
1607
- } else {
1608
- self . root_span
1609
- } ;
1610
1593
trace ! ( "generate stacktrace: {:#?}, {:?}" , frames, explicit_span) ;
1611
- ( frames, span)
1594
+ ( frames, self . tcx . span )
1612
1595
}
1613
1596
1614
1597
pub fn report ( & self , e : & mut EvalError , as_err : bool , explicit_span : Option < Span > ) {
@@ -1656,7 +1639,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1656
1639
} ) ;
1657
1640
trace ! ( "reporting const eval failure at {:?}" , span) ;
1658
1641
let mut err = if as_err {
1659
- :: rustc:: middle:: const_val:: struct_error ( self . tcx , span, "constant evaluation error" )
1642
+ :: rustc:: middle:: const_val:: struct_error ( * self . tcx , span, "constant evaluation error" )
1660
1643
} else {
1661
1644
let node_id = self
1662
1645
. stack ( )
@@ -1718,14 +1701,3 @@ impl<'mir, 'tcx> Frame<'mir, 'tcx> {
1718
1701
return Ok ( old) ;
1719
1702
}
1720
1703
}
1721
-
1722
- // TODO(solson): Upstream these methods into rustc::ty::layout.
1723
-
1724
- pub fn resolve_drop_in_place < ' a , ' tcx > (
1725
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1726
- ty : Ty < ' tcx > ,
1727
- ) -> ty:: Instance < ' tcx > {
1728
- let def_id = tcx. require_lang_item ( :: rustc:: middle:: lang_items:: DropInPlaceFnLangItem ) ;
1729
- let substs = tcx. intern_substs ( & [ Kind :: from ( ty) ] ) ;
1730
- ty:: Instance :: resolve ( tcx, ty:: ParamEnv :: empty ( Reveal :: All ) , def_id, substs) . unwrap ( )
1731
- }
0 commit comments