@@ -57,6 +57,7 @@ use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
57
57
use syntax_pos:: { DUMMY_SP , Span } ;
58
58
59
59
use smallvec;
60
+ use rustc_data_structures:: indexed_vec:: Idx ;
60
61
use rustc_data_structures:: stable_hasher:: { StableHasher , StableHasherResult ,
61
62
HashStable } ;
62
63
@@ -1488,28 +1489,16 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
1488
1489
/// declared, but a type name in a non-zero universe is a placeholder
1489
1490
/// type -- an idealized representative of "types in general" that we
1490
1491
/// 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
+ }
1493
1497
1494
1498
impl_stable_hash_for ! ( struct UniverseIndex { private } ) ;
1495
1499
1496
1500
impl 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 ) ;
1513
1502
1514
1503
/// A "superuniverse" corresponds to being inside a `forall` quantifier.
1515
1504
/// So, for example, suppose we have this type in universe `U`:
@@ -1530,26 +1519,6 @@ impl UniverseIndex {
1530
1519
pub fn is_subset_of ( self , other : UniverseIndex ) -> bool {
1531
1520
self . private <= other. private
1532
1521
}
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
- }
1553
1522
}
1554
1523
1555
1524
/// The "placeholder index" fully defines a placeholder region.
0 commit comments