@@ -37,7 +37,7 @@ use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
3737use rustc_hir as hir;
3838use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Res } ;
3939use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , LocalDefIdMap , CRATE_DEF_INDEX } ;
40- use rustc_hir:: { Constness , Node } ;
40+ use rustc_hir:: Node ;
4141use rustc_macros:: HashStable ;
4242use rustc_span:: symbol:: { kw, Ident , Symbol } ;
4343use rustc_span:: Span ;
@@ -181,6 +181,25 @@ pub enum Visibility {
181181 Invisible ,
182182}
183183
184+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , HashStable , TyEncodable , TyDecodable ) ]
185+ pub enum BoundConstness {
186+ /// `T: Trait`
187+ NotConst ,
188+ /// `T: ~const Trait`
189+ ///
190+ /// Requires resolving to const only when we are in a const context.
191+ ConstIfConst ,
192+ }
193+
194+ impl fmt:: Display for BoundConstness {
195+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
196+ match self {
197+ Self :: NotConst => f. write_str ( "normal" ) ,
198+ Self :: ConstIfConst => f. write_str ( "`~const`" ) ,
199+ }
200+ }
201+ }
202+
184203#[ derive(
185204 Clone ,
186205 Debug ,
@@ -628,9 +647,7 @@ impl<'tcx> Predicate<'tcx> {
628647pub struct TraitPredicate < ' tcx > {
629648 pub trait_ref : TraitRef < ' tcx > ,
630649
631- /// A trait predicate will have `Constness::Const` if it originates
632- /// from a bound marked with `~const`.
633- pub constness : hir:: Constness ,
650+ pub constness : BoundConstness ,
634651}
635652
636653pub type PolyTraitPredicate < ' tcx > = ty:: Binder < ' tcx , TraitPredicate < ' tcx > > ;
@@ -1299,26 +1316,26 @@ impl<'tcx> ParamEnv<'tcx> {
12991316
13001317#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable ) ]
13011318pub struct ConstnessAnd < T > {
1302- pub constness : Constness ,
1319+ pub constness : BoundConstness ,
13031320 pub value : T ,
13041321}
13051322
13061323// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate(tcx)` to ensure that
13071324// the constness of trait bounds is being propagated correctly.
13081325pub trait WithConstness : Sized {
13091326 #[ inline]
1310- fn with_constness ( self , constness : Constness ) -> ConstnessAnd < Self > {
1327+ fn with_constness ( self , constness : BoundConstness ) -> ConstnessAnd < Self > {
13111328 ConstnessAnd { constness, value : self }
13121329 }
13131330
13141331 #[ inline]
1315- fn with_const ( self ) -> ConstnessAnd < Self > {
1316- self . with_constness ( Constness :: Const )
1332+ fn with_const_if_const ( self ) -> ConstnessAnd < Self > {
1333+ self . with_constness ( BoundConstness :: ConstIfConst )
13171334 }
13181335
13191336 #[ inline]
13201337 fn without_const ( self ) -> ConstnessAnd < Self > {
1321- self . with_constness ( Constness :: NotConst )
1338+ self . with_constness ( BoundConstness :: NotConst )
13221339 }
13231340}
13241341
0 commit comments