@@ -57,6 +57,7 @@ use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
5757use syntax_pos:: { DUMMY_SP , Span } ;
5858
5959use smallvec;
60+ use rustc_data_structures:: indexed_vec:: Idx ;
6061use rustc_data_structures:: stable_hasher:: { StableHasher , StableHasherResult ,
6162 HashStable } ;
6263
@@ -1488,28 +1489,16 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
14881489/// declared, but a type name in a non-zero universe is a placeholder
14891490/// type -- an idealized representative of "types in general" that we
14901491/// use for checking generic functions.
1491- #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
1492- pub struct UniverseIndex { private : u32 }
1492+ newtype_index ! {
1493+ pub struct UniverseIndex {
1494+ DEBUG_FORMAT = "U{}" ,
1495+ }
1496+ }
14931497
14941498impl_stable_hash_for ! ( struct UniverseIndex { private } ) ;
14951499
14961500impl UniverseIndex {
1497- /// The root universe, where things that the user defined are
1498- /// visible.
1499- pub const ROOT : Self = UniverseIndex { private : 0 } ;
1500-
1501- /// The "max universe" -- this isn't really a valid universe, but
1502- /// it's useful sometimes as a "starting value" when you are
1503- /// taking the minimum of a (non-empty!) set of universes.
1504- pub const MAX : Self = UniverseIndex { private : :: std:: u32:: MAX } ;
1505-
1506- /// Creates a universe index from the given integer. Not to be
1507- /// used lightly lest you pick a bad value. But sometimes we
1508- /// convert universe indices into integers and back for various
1509- /// reasons.
1510- pub fn from_u32 ( index : u32 ) -> Self {
1511- UniverseIndex { private : index }
1512- }
1501+ pub const ROOT : UniverseIndex = UniverseIndex :: from_u32_const ( 0 ) ;
15131502
15141503 /// A "superuniverse" corresponds to being inside a `forall` quantifier.
15151504 /// So, for example, suppose we have this type in universe `U`:
@@ -1530,26 +1519,6 @@ impl UniverseIndex {
15301519 pub fn is_subset_of ( self , other : UniverseIndex ) -> bool {
15311520 self . private <= other. private
15321521 }
1533-
1534- pub fn as_u32 ( & self ) -> u32 {
1535- self . private
1536- }
1537-
1538- pub fn as_usize ( & self ) -> usize {
1539- self . private as usize
1540- }
1541- }
1542-
1543- impl fmt:: Debug for UniverseIndex {
1544- fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1545- write ! ( fmt, "U{}" , self . as_u32( ) )
1546- }
1547- }
1548-
1549- impl From < u32 > for UniverseIndex {
1550- fn from ( index : u32 ) -> Self {
1551- UniverseIndex :: from_u32 ( index)
1552- }
15531522}
15541523
15551524/// The "placeholder index" fully defines a placeholder region.
0 commit comments