@@ -1227,22 +1227,27 @@ pub struct ParamEnv<'tcx> {
12271227#[ derive( Copy , Clone ) ]
12281228struct ParamTag {
12291229 reveal : traits:: Reveal ,
1230+ constness : hir:: Constness ,
12301231}
12311232
12321233unsafe impl rustc_data_structures:: tagged_ptr:: Tag for ParamTag {
1233- const BITS : usize = 1 ;
1234+ const BITS : usize = 2 ;
12341235 #[ inline]
12351236 fn into_usize ( self ) -> usize {
12361237 match self {
1237- Self { reveal : traits:: Reveal :: UserFacing } => 0 ,
1238- Self { reveal : traits:: Reveal :: All } => 1 ,
1238+ Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: NotConst } => 0 ,
1239+ Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: NotConst } => 1 ,
1240+ Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: Const } => 2 ,
1241+ Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: Const } => 3 ,
12391242 }
12401243 }
12411244 #[ inline]
12421245 unsafe fn from_usize ( ptr : usize ) -> Self {
12431246 match ptr {
1244- 0 => Self { reveal : traits:: Reveal :: UserFacing } ,
1245- 1 => Self { reveal : traits:: Reveal :: All } ,
1247+ 0 => Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: NotConst } ,
1248+ 1 => Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: NotConst } ,
1249+ 2 => Self { reveal : traits:: Reveal :: UserFacing , constness : hir:: Constness :: Const } ,
1250+ 3 => Self { reveal : traits:: Reveal :: All , constness : hir:: Constness :: Const } ,
12461251 _ => std:: hint:: unreachable_unchecked ( ) ,
12471252 }
12481253 }
@@ -1253,6 +1258,7 @@ impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
12531258 f. debug_struct ( "ParamEnv" )
12541259 . field ( "caller_bounds" , & self . caller_bounds ( ) )
12551260 . field ( "reveal" , & self . reveal ( ) )
1261+ . field ( "constness" , & self . constness ( ) )
12561262 . finish ( )
12571263 }
12581264}
@@ -1261,20 +1267,23 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
12611267 fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
12621268 self . caller_bounds ( ) . hash_stable ( hcx, hasher) ;
12631269 self . reveal ( ) . hash_stable ( hcx, hasher) ;
1270+ self . constness ( ) . hash_stable ( hcx, hasher) ;
12641271 }
12651272}
12661273
12671274impl < ' tcx > TypeFoldable < ' tcx > for ParamEnv < ' tcx > {
1268- fn super_fold_with < F : ty:: fold:: TypeFolder < ' tcx > > (
1269- self ,
1270- folder : & mut F ,
1271- ) -> Result < Self , F :: Error > {
1272- Ok ( ParamEnv :: new ( self . caller_bounds ( ) . fold_with ( folder) ?, self . reveal ( ) . fold_with ( folder) ?) )
1275+ fn super_fold_with < F : ty:: fold:: TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Result < Self , F :: Error > {
1276+ ParamEnv :: new (
1277+ self . caller_bounds ( ) . fold_with ( folder) ?,
1278+ self . reveal ( ) . fold_with ( folder) ?,
1279+ self . constness ( ) . fold_with ( folder) ?,
1280+ )
12731281 }
12741282
12751283 fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < V :: BreakTy > {
12761284 self . caller_bounds ( ) . visit_with ( visitor) ?;
1277- self . reveal ( ) . visit_with ( visitor)
1285+ self . reveal ( ) . visit_with ( visitor) ?;
1286+ self . constness ( ) . visit_with ( visitor)
12781287 }
12791288}
12801289
@@ -1285,7 +1294,7 @@ impl<'tcx> ParamEnv<'tcx> {
12851294 /// type-checking.
12861295 #[ inline]
12871296 pub fn empty ( ) -> Self {
1288- Self :: new ( List :: empty ( ) , Reveal :: UserFacing )
1297+ Self :: new ( List :: empty ( ) , Reveal :: UserFacing , hir :: Constness :: NotConst )
12891298 }
12901299
12911300 #[ inline]
@@ -1298,6 +1307,11 @@ impl<'tcx> ParamEnv<'tcx> {
12981307 self . packed . tag ( ) . reveal
12991308 }
13001309
1310+ #[ inline]
1311+ pub fn constness ( self ) -> hir:: Constness {
1312+ self . packed . tag ( ) . constness
1313+ }
1314+
13011315 /// Construct a trait environment with no where-clauses in scope
13021316 /// where the values of all `impl Trait` and other hidden types
13031317 /// are revealed. This is suitable for monomorphized, post-typeck
@@ -1307,13 +1321,17 @@ impl<'tcx> ParamEnv<'tcx> {
13071321 /// or invoke `param_env.with_reveal_all()`.
13081322 #[ inline]
13091323 pub fn reveal_all ( ) -> Self {
1310- Self :: new ( List :: empty ( ) , Reveal :: All )
1324+ Self :: new ( List :: empty ( ) , Reveal :: All , hir :: Constness :: NotConst )
13111325 }
13121326
13131327 /// Construct a trait environment with the given set of predicates.
13141328 #[ inline]
1315- pub fn new ( caller_bounds : & ' tcx List < Predicate < ' tcx > > , reveal : Reveal ) -> Self {
1316- ty:: ParamEnv { packed : CopyTaggedPtr :: new ( caller_bounds, ParamTag { reveal } ) }
1329+ pub fn new (
1330+ caller_bounds : & ' tcx List < Predicate < ' tcx > > ,
1331+ reveal : Reveal ,
1332+ constness : hir:: Constness ,
1333+ ) -> Self {
1334+ ty:: ParamEnv { packed : CopyTaggedPtr :: new ( caller_bounds, ParamTag { reveal, constness } ) }
13171335 }
13181336
13191337 pub fn with_user_facing ( mut self ) -> Self {
@@ -1335,13 +1353,17 @@ impl<'tcx> ParamEnv<'tcx> {
13351353 return self ;
13361354 }
13371355
1338- ParamEnv :: new ( tcx. normalize_opaque_types ( self . caller_bounds ( ) ) , Reveal :: All )
1356+ ParamEnv :: new (
1357+ tcx. normalize_opaque_types ( self . caller_bounds ( ) ) ,
1358+ Reveal :: All ,
1359+ self . constness ( ) ,
1360+ )
13391361 }
13401362
13411363 /// Returns this same environment but with no caller bounds.
13421364 #[ inline]
13431365 pub fn without_caller_bounds ( self ) -> Self {
1344- Self :: new ( List :: empty ( ) , self . reveal ( ) )
1366+ Self :: new ( List :: empty ( ) , self . reveal ( ) , self . constness ( ) )
13451367 }
13461368
13471369 /// Creates a suitable environment in which to perform trait
0 commit comments