11#![ allow( clippy:: float_cmp) ]
22
3- use crate :: utils:: { clip, get_def_path , sext, unsext} ;
3+ use crate :: utils:: { clip, sext, unsext} ;
44use if_chain:: if_chain;
55use rustc:: hir:: def:: Def ;
66use rustc:: hir:: * ;
@@ -16,7 +16,7 @@ use std::convert::TryInto;
1616use std:: hash:: { Hash , Hasher } ;
1717use syntax:: ast:: { FloatTy , LitKind } ;
1818use syntax:: ptr:: P ;
19- use syntax_pos:: symbol:: Symbol ;
19+ use syntax_pos:: symbol:: { LocalInternedString , Symbol } ;
2020
2121/// A `LitKind`-like enum to fold constant `Expr`s into.
2222#[ derive( Debug , Clone ) ]
@@ -180,7 +180,7 @@ pub fn constant<'c, 'cc>(
180180 e : & Expr ,
181181) -> Option < ( Constant , bool ) > {
182182 let mut cx = ConstEvalLateContext {
183- tcx : lcx. tcx ,
183+ lcx,
184184 tables,
185185 param_env : lcx. param_env ,
186186 needed_resolution : false ,
@@ -199,11 +199,11 @@ pub fn constant_simple<'c, 'cc>(
199199
200200/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`.
201201pub fn constant_context < ' c , ' cc > (
202- lcx : & LateContext < ' c , ' cc > ,
202+ lcx : & ' c LateContext < ' c , ' cc > ,
203203 tables : & ' c ty:: TypeckTables < ' cc > ,
204204) -> ConstEvalLateContext < ' c , ' cc > {
205205 ConstEvalLateContext {
206- tcx : lcx. tcx ,
206+ lcx,
207207 tables,
208208 param_env : lcx. param_env ,
209209 needed_resolution : false ,
@@ -212,7 +212,7 @@ pub fn constant_context<'c, 'cc>(
212212}
213213
214214pub struct ConstEvalLateContext < ' a , ' tcx : ' a > {
215- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
215+ lcx : & ' a LateContext < ' a , ' tcx > ,
216216 tables : & ' a ty:: TypeckTables < ' tcx > ,
217217 param_env : ty:: ParamEnv < ' tcx > ,
218218 needed_resolution : bool ,
@@ -231,7 +231,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
231231 ExprKind :: Tup ( ref tup) => self . multi ( tup) . map ( Constant :: Tuple ) ,
232232 ExprKind :: Repeat ( ref value, _) => {
233233 let n = match self . tables . expr_ty ( e) . sty {
234- ty:: Array ( _, n) => n. assert_usize ( self . tcx ) . expect ( "array length" ) ,
234+ ty:: Array ( _, n) => n. assert_usize ( self . lcx . tcx ) . expect ( "array length" ) ,
235235 _ => span_bug ! ( e. span, "typeck error" ) ,
236236 } ;
237237 self . expr ( value) . map ( |v| Constant :: Repeat ( Box :: new ( v) , n) )
@@ -249,7 +249,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
249249 if let ExprKind :: Path ( qpath) = & callee. node;
250250 let def = self . tables. qpath_def( qpath, callee. hir_id) ;
251251 if let Some ( def_id) = def. opt_def_id( ) ;
252- let def_path = get_def_path( self . tcx, def_id) ;
252+ let def_path = self . lcx. get_def_path( def_id)
253+ . iter( )
254+ . map( LocalInternedString :: get)
255+ . collect:: <Vec <_>>( ) ;
253256 if let & [ "core" , "num" , impl_ty, "max_value" ] = & def_path[ ..] ;
254257 then {
255258 let value = match impl_ty {
@@ -280,8 +283,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
280283 Int ( value) => {
281284 let value = !value;
282285 match ty. sty {
283- ty:: Int ( ity) => Some ( Int ( unsext ( self . tcx , value as i128 , ity) ) ) ,
284- ty:: Uint ( ity) => Some ( Int ( clip ( self . tcx , value, ity) ) ) ,
286+ ty:: Int ( ity) => Some ( Int ( unsext ( self . lcx . tcx , value as i128 , ity) ) ) ,
287+ ty:: Uint ( ity) => Some ( Int ( clip ( self . lcx . tcx , value, ity) ) ) ,
285288 _ => None ,
286289 }
287290 } ,
@@ -298,10 +301,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
298301 _ => return None ,
299302 } ;
300303 // sign extend
301- let value = sext ( self . tcx , value, ity) ;
304+ let value = sext ( self . lcx . tcx , value, ity) ;
302305 let value = value. checked_neg ( ) ?;
303306 // clear unused bits
304- Some ( Int ( unsext ( self . tcx , value, ity) ) )
307+ Some ( Int ( unsext ( self . lcx . tcx , value, ity) ) )
305308 } ,
306309 F32 ( f) => Some ( F32 ( -f) ) ,
307310 F64 ( f) => Some ( F64 ( -f) ) ,
@@ -326,16 +329,16 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
326329 let substs = if self . substs . is_empty ( ) {
327330 substs
328331 } else {
329- substs. subst ( self . tcx , self . substs )
332+ substs. subst ( self . lcx . tcx , self . substs )
330333 } ;
331- let instance = Instance :: resolve ( self . tcx , self . param_env , def_id, substs) ?;
334+ let instance = Instance :: resolve ( self . lcx . tcx , self . param_env , def_id, substs) ?;
332335 let gid = GlobalId {
333336 instance,
334337 promoted : None ,
335338 } ;
336339
337- let result = self . tcx . const_eval ( self . param_env . and ( gid) ) . ok ( ) ?;
338- let ret = miri_to_const ( self . tcx , & result) ;
340+ let result = self . lcx . tcx . const_eval ( self . param_env . and ( gid) ) . ok ( ) ?;
341+ let ret = miri_to_const ( self . lcx . tcx , & result) ;
339342 if ret. is_some ( ) {
340343 self . needed_resolution = true ;
341344 }
@@ -373,9 +376,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
373376 match ( l, r) {
374377 ( Constant :: Int ( l) , Some ( Constant :: Int ( r) ) ) => match self . tables . expr_ty ( left) . sty {
375378 ty:: Int ( ity) => {
376- let l = sext ( self . tcx , l, ity) ;
377- let r = sext ( self . tcx , r, ity) ;
378- let zext = |n : i128 | Constant :: Int ( unsext ( self . tcx , n, ity) ) ;
379+ let l = sext ( self . lcx . tcx , l, ity) ;
380+ let r = sext ( self . lcx . tcx , r, ity) ;
381+ let zext = |n : i128 | Constant :: Int ( unsext ( self . lcx . tcx , n, ity) ) ;
379382 match op. node {
380383 BinOpKind :: Add => l. checked_add ( r) . map ( zext) ,
381384 BinOpKind :: Sub => l. checked_sub ( r) . map ( zext) ,
0 commit comments