@@ -25,10 +25,10 @@ use rustc_hir as hir;
25
25
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
26
26
use rustc_macros:: extension;
27
27
pub use rustc_macros:: { TypeFoldable , TypeVisitable } ;
28
+ use rustc_middle:: bug;
28
29
use rustc_middle:: infer:: canonical:: { CanonicalQueryInput , CanonicalVarValues } ;
29
30
use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableValue , ConstVidKey } ;
30
31
use rustc_middle:: mir:: ConstraintCategory ;
31
- use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
32
32
use rustc_middle:: traits:: select;
33
33
pub use rustc_middle:: ty:: IntVarValue ;
34
34
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
@@ -40,7 +40,6 @@ use rustc_middle::ty::{
40
40
self , ConstVid , FloatVid , GenericArg , GenericArgKind , GenericArgs , GenericArgsRef ,
41
41
GenericParamDefKind , InferConst , IntVid , Ty , TyCtxt , TyVid , TypingMode ,
42
42
} ;
43
- use rustc_middle:: { bug, span_bug} ;
44
43
use rustc_span:: Span ;
45
44
use rustc_span:: symbol:: Symbol ;
46
45
use rustc_type_ir:: solve:: Reveal ;
@@ -1279,84 +1278,6 @@ impl<'tcx> InferCtxt<'tcx> {
1279
1278
u
1280
1279
}
1281
1280
1282
- pub fn try_const_eval_resolve (
1283
- & self ,
1284
- param_env : ty:: ParamEnv < ' tcx > ,
1285
- unevaluated : ty:: UnevaluatedConst < ' tcx > ,
1286
- span : Span ,
1287
- ) -> Result < ty:: Const < ' tcx > , ErrorHandled > {
1288
- match self . const_eval_resolve ( param_env, unevaluated, span) {
1289
- Ok ( Ok ( val) ) => Ok ( ty:: Const :: new_value (
1290
- self . tcx ,
1291
- val,
1292
- self . tcx . type_of ( unevaluated. def ) . instantiate ( self . tcx , unevaluated. args ) ,
1293
- ) ) ,
1294
- Ok ( Err ( bad_ty) ) => {
1295
- let tcx = self . tcx ;
1296
- let def_id = unevaluated. def ;
1297
- span_bug ! (
1298
- tcx. def_span( def_id) ,
1299
- "unable to construct a valtree for the unevaluated constant {:?}: type {bad_ty} is not valtree-compatible" ,
1300
- unevaluated
1301
- ) ;
1302
- }
1303
- Err ( err) => Err ( err) ,
1304
- }
1305
- }
1306
-
1307
- /// Resolves and evaluates a constant.
1308
- ///
1309
- /// The constant can be located on a trait like `<A as B>::C`, in which case the given
1310
- /// generic parameters and environment are used to resolve the constant. Alternatively if the
1311
- /// constant has generic parameters in scope the instantiations are used to evaluate the value
1312
- /// of the constant. For example in `fn foo<T>() { let _ = [0; bar::<T>()]; }` the repeat count
1313
- /// constant `bar::<T>()` requires a instantiation for `T`, if the instantiation for `T` is
1314
- /// still too generic for the constant to be evaluated then `Err(ErrorHandled::TooGeneric)` is
1315
- /// returned.
1316
- ///
1317
- /// This handles inferences variables within both `param_env` and `args` by
1318
- /// performing the operation on their respective canonical forms.
1319
- #[ instrument( skip( self ) , level = "debug" ) ]
1320
- pub fn const_eval_resolve (
1321
- & self ,
1322
- mut param_env : ty:: ParamEnv < ' tcx > ,
1323
- unevaluated : ty:: UnevaluatedConst < ' tcx > ,
1324
- span : Span ,
1325
- ) -> EvalToValTreeResult < ' tcx > {
1326
- let mut args = self . resolve_vars_if_possible ( unevaluated. args ) ;
1327
- debug ! ( ?args) ;
1328
-
1329
- // Postpone the evaluation of constants whose args depend on inference
1330
- // variables
1331
- let tcx = self . tcx ;
1332
- if args. has_non_region_infer ( ) {
1333
- if let Some ( ct) = tcx. thir_abstract_const ( unevaluated. def ) ? {
1334
- let ct = tcx. expand_abstract_consts ( ct. instantiate ( tcx, args) ) ;
1335
- if let Err ( e) = ct. error_reported ( ) {
1336
- return Err ( ErrorHandled :: Reported ( e. into ( ) , span) ) ;
1337
- } else if ct. has_non_region_infer ( ) || ct. has_non_region_param ( ) {
1338
- return Err ( ErrorHandled :: TooGeneric ( span) ) ;
1339
- } else {
1340
- args = replace_param_and_infer_args_with_placeholder ( tcx, args) ;
1341
- }
1342
- } else {
1343
- args = GenericArgs :: identity_for_item ( tcx, unevaluated. def ) ;
1344
- param_env = tcx. param_env ( unevaluated. def ) ;
1345
- }
1346
- }
1347
-
1348
- let param_env_erased = tcx. erase_regions ( param_env) ;
1349
- let args_erased = tcx. erase_regions ( args) ;
1350
- debug ! ( ?param_env_erased) ;
1351
- debug ! ( ?args_erased) ;
1352
-
1353
- let unevaluated = ty:: UnevaluatedConst { def : unevaluated. def , args : args_erased } ;
1354
-
1355
- // The return value is the evaluated value which doesn't contain any reference to inference
1356
- // variables, thus we don't need to instantiate back the original values.
1357
- tcx. const_eval_resolve_for_typeck ( param_env_erased, unevaluated, span)
1358
- }
1359
-
1360
1281
/// The returned function is used in a fast path. If it returns `true` the variable is
1361
1282
/// unchanged, `false` indicates that the status is unknown.
1362
1283
#[ inline]
@@ -1622,61 +1543,6 @@ impl RegionVariableOrigin {
1622
1543
}
1623
1544
}
1624
1545
1625
- /// Replaces args that reference param or infer variables with suitable
1626
- /// placeholders. This function is meant to remove these param and infer
1627
- /// args when they're not actually needed to evaluate a constant.
1628
- fn replace_param_and_infer_args_with_placeholder < ' tcx > (
1629
- tcx : TyCtxt < ' tcx > ,
1630
- args : GenericArgsRef < ' tcx > ,
1631
- ) -> GenericArgsRef < ' tcx > {
1632
- struct ReplaceParamAndInferWithPlaceholder < ' tcx > {
1633
- tcx : TyCtxt < ' tcx > ,
1634
- idx : u32 ,
1635
- }
1636
-
1637
- impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for ReplaceParamAndInferWithPlaceholder < ' tcx > {
1638
- fn cx ( & self ) -> TyCtxt < ' tcx > {
1639
- self . tcx
1640
- }
1641
-
1642
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
1643
- if let ty:: Infer ( _) = t. kind ( ) {
1644
- let idx = {
1645
- let idx = self . idx ;
1646
- self . idx += 1 ;
1647
- idx
1648
- } ;
1649
- Ty :: new_placeholder ( self . tcx , ty:: PlaceholderType {
1650
- universe : ty:: UniverseIndex :: ROOT ,
1651
- bound : ty:: BoundTy {
1652
- var : ty:: BoundVar :: from_u32 ( idx) ,
1653
- kind : ty:: BoundTyKind :: Anon ,
1654
- } ,
1655
- } )
1656
- } else {
1657
- t. super_fold_with ( self )
1658
- }
1659
- }
1660
-
1661
- fn fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
1662
- if let ty:: ConstKind :: Infer ( _) = c. kind ( ) {
1663
- ty:: Const :: new_placeholder ( self . tcx , ty:: PlaceholderConst {
1664
- universe : ty:: UniverseIndex :: ROOT ,
1665
- bound : ty:: BoundVar :: from_u32 ( {
1666
- let idx = self . idx ;
1667
- self . idx += 1 ;
1668
- idx
1669
- } ) ,
1670
- } )
1671
- } else {
1672
- c. super_fold_with ( self )
1673
- }
1674
- }
1675
- }
1676
-
1677
- args. fold_with ( & mut ReplaceParamAndInferWithPlaceholder { tcx, idx : 0 } )
1678
- }
1679
-
1680
1546
impl < ' tcx > InferCtxt < ' tcx > {
1681
1547
/// Given a [`hir::Block`], get the span of its last expression or
1682
1548
/// statement, peeling off any inner blocks.
0 commit comments