@@ -1222,22 +1222,27 @@ pub struct ParamEnv<'tcx> {
1222
1222
#[ derive( Copy , Clone ) ]
1223
1223
struct ParamTag {
1224
1224
reveal : traits:: Reveal ,
1225
+ constness : hir:: Constness ,
1225
1226
}
1226
1227
1227
1228
unsafe impl rustc_data_structures:: tagged_ptr:: Tag for ParamTag {
1228
- const BITS : usize = 1 ;
1229
+ const BITS : usize = 2 ;
1229
1230
#[ inline]
1230
1231
fn into_usize ( self ) -> usize {
1231
1232
match self {
1232
- Self { reveal : traits:: Reveal :: UserFacing } => 0 ,
1233
- Self { reveal : traits:: Reveal :: All } => 1 ,
1233
+ Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: NotConst } => 0 ,
1234
+ Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: NotConst } => 1 ,
1235
+ Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: Const } => 2 ,
1236
+ Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: Const } => 3 ,
1234
1237
}
1235
1238
}
1236
1239
#[ inline]
1237
1240
unsafe fn from_usize ( ptr : usize ) -> Self {
1238
1241
match ptr {
1239
- 0 => Self { reveal : traits:: Reveal :: UserFacing } ,
1240
- 1 => Self { reveal : traits:: Reveal :: All } ,
1242
+ 0 => Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: NotConst } ,
1243
+ 1 => Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: NotConst } ,
1244
+ 2 => Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: Const } ,
1245
+ 3 => Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: Const } ,
1241
1246
_ => std:: hint:: unreachable_unchecked ( ) ,
1242
1247
}
1243
1248
}
@@ -1248,6 +1253,7 @@ impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
1248
1253
f. debug_struct ( "ParamEnv" )
1249
1254
. field ( "caller_bounds" , & self . caller_bounds ( ) )
1250
1255
. field ( "reveal" , & self . reveal ( ) )
1256
+ . field ( "constness" , & self . constness ( ) )
1251
1257
. finish ( )
1252
1258
}
1253
1259
}
@@ -1256,17 +1262,23 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
1256
1262
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
1257
1263
self . caller_bounds ( ) . hash_stable ( hcx, hasher) ;
1258
1264
self . reveal ( ) . hash_stable ( hcx, hasher) ;
1265
+ self . constness ( ) . hash_stable ( hcx, hasher) ;
1259
1266
}
1260
1267
}
1261
1268
1262
1269
impl < ' tcx > TypeFoldable < ' tcx > for ParamEnv < ' tcx > {
1263
1270
fn super_fold_with < F : ty:: fold:: TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
1264
- ParamEnv :: new ( self . caller_bounds ( ) . fold_with ( folder) , self . reveal ( ) . fold_with ( folder) )
1271
+ ParamEnv :: new (
1272
+ self . caller_bounds ( ) . fold_with ( folder) ,
1273
+ self . reveal ( ) . fold_with ( folder) ,
1274
+ self . constness ( ) . fold_with ( folder) ,
1275
+ )
1265
1276
}
1266
1277
1267
1278
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < V :: BreakTy > {
1268
1279
self . caller_bounds ( ) . visit_with ( visitor) ?;
1269
- self . reveal ( ) . visit_with ( visitor)
1280
+ self . reveal ( ) . visit_with ( visitor) ?;
1281
+ self . constness ( ) . visit_with ( visitor)
1270
1282
}
1271
1283
}
1272
1284
@@ -1277,7 +1289,7 @@ impl<'tcx> ParamEnv<'tcx> {
1277
1289
/// type-checking.
1278
1290
#[ inline]
1279
1291
pub fn empty ( ) -> Self {
1280
- Self :: new ( List :: empty ( ) , Reveal :: UserFacing )
1292
+ Self :: new ( List :: empty ( ) , Reveal :: UserFacing , hir :: Constness :: NotConst )
1281
1293
}
1282
1294
1283
1295
#[ inline]
@@ -1290,6 +1302,11 @@ impl<'tcx> ParamEnv<'tcx> {
1290
1302
self . packed . tag ( ) . reveal
1291
1303
}
1292
1304
1305
+ #[ inline]
1306
+ pub fn constness ( self ) -> hir:: Constness {
1307
+ self . packed . tag ( ) . constness
1308
+ }
1309
+
1293
1310
/// Construct a trait environment with no where-clauses in scope
1294
1311
/// where the values of all `impl Trait` and other hidden types
1295
1312
/// are revealed. This is suitable for monomorphized, post-typeck
@@ -1299,13 +1316,17 @@ impl<'tcx> ParamEnv<'tcx> {
1299
1316
/// or invoke `param_env.with_reveal_all()`.
1300
1317
#[ inline]
1301
1318
pub fn reveal_all ( ) -> Self {
1302
- Self :: new ( List :: empty ( ) , Reveal :: All )
1319
+ Self :: new ( List :: empty ( ) , Reveal :: All , hir :: Constness :: NotConst )
1303
1320
}
1304
1321
1305
1322
/// Construct a trait environment with the given set of predicates.
1306
1323
#[ inline]
1307
- pub fn new ( caller_bounds : & ' tcx List < Predicate < ' tcx > > , reveal : Reveal ) -> Self {
1308
- ty:: ParamEnv { packed : CopyTaggedPtr :: new ( caller_bounds, ParamTag { reveal } ) }
1324
+ pub fn new (
1325
+ caller_bounds : & ' tcx List < Predicate < ' tcx > > ,
1326
+ reveal : Reveal ,
1327
+ constness : hir:: Constness ,
1328
+ ) -> Self {
1329
+ ty:: ParamEnv { packed : CopyTaggedPtr :: new ( caller_bounds, ParamTag { reveal, constness } ) }
1309
1330
}
1310
1331
1311
1332
pub fn with_user_facing ( mut self ) -> Self {
@@ -1327,13 +1348,17 @@ impl<'tcx> ParamEnv<'tcx> {
1327
1348
return self ;
1328
1349
}
1329
1350
1330
- ParamEnv :: new ( tcx. normalize_opaque_types ( self . caller_bounds ( ) ) , Reveal :: All )
1351
+ ParamEnv :: new (
1352
+ tcx. normalize_opaque_types ( self . caller_bounds ( ) ) ,
1353
+ Reveal :: All ,
1354
+ self . constness ( ) ,
1355
+ )
1331
1356
}
1332
1357
1333
1358
/// Returns this same environment but with no caller bounds.
1334
1359
#[ inline]
1335
1360
pub fn without_caller_bounds ( self ) -> Self {
1336
- Self :: new ( List :: empty ( ) , self . reveal ( ) )
1361
+ Self :: new ( List :: empty ( ) , self . reveal ( ) , self . constness ( ) )
1337
1362
}
1338
1363
1339
1364
/// Creates a suitable environment in which to perform trait
0 commit comments