@@ -10,76 +10,29 @@ use std::borrow::Borrow;
1010use std:: fmt;
1111
1212rustc_index:: newtype_index! {
13- pub struct CrateId {
13+ pub struct CrateNum {
1414 ENCODABLE = custom
15+ DEBUG_FORMAT = "crate{}"
1516 }
1617}
1718
18- #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
19- pub enum CrateNum {
20- /// A special `CrateNum` that we use for the `tcx.rcache` when decoding from
21- /// the incr. comp. cache.
22- ReservedForIncrCompCache ,
23- Index ( CrateId ) ,
24- }
25-
2619/// Item definitions in the currently-compiled crate would have the `CrateNum`
2720/// `LOCAL_CRATE` in their `DefId`.
28- pub const LOCAL_CRATE : CrateNum = CrateNum :: Index ( CrateId :: from_u32 ( 0 ) ) ;
29-
30- impl Idx for CrateNum {
31- #[ inline]
32- fn new ( value : usize ) -> Self {
33- CrateNum :: Index ( Idx :: new ( value) )
34- }
35-
36- #[ inline]
37- fn index ( self ) -> usize {
38- match self {
39- CrateNum :: Index ( idx) => Idx :: index ( idx) ,
40- _ => panic ! ( "Tried to get crate index of {:?}" , self ) ,
41- }
42- }
43- }
21+ pub const LOCAL_CRATE : CrateNum = CrateNum :: from_u32 ( 0 ) ;
4422
4523impl CrateNum {
4624 pub fn new ( x : usize ) -> CrateNum {
4725 CrateNum :: from_usize ( x)
4826 }
4927
50- pub fn from_usize ( x : usize ) -> CrateNum {
51- CrateNum :: Index ( CrateId :: from_usize ( x) )
52- }
53-
54- pub fn from_u32 ( x : u32 ) -> CrateNum {
55- CrateNum :: Index ( CrateId :: from_u32 ( x) )
56- }
57-
58- pub fn as_usize ( self ) -> usize {
59- match self {
60- CrateNum :: Index ( id) => id. as_usize ( ) ,
61- _ => panic ! ( "tried to get index of non-standard crate {:?}" , self ) ,
62- }
63- }
64-
65- pub fn as_u32 ( self ) -> u32 {
66- match self {
67- CrateNum :: Index ( id) => id. as_u32 ( ) ,
68- _ => panic ! ( "tried to get index of non-standard crate {:?}" , self ) ,
69- }
70- }
71-
7228 pub fn as_def_id ( & self ) -> DefId {
7329 DefId { krate : * self , index : CRATE_DEF_INDEX }
7430 }
7531}
7632
7733impl fmt:: Display for CrateNum {
7834 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
79- match self {
80- CrateNum :: Index ( id) => fmt:: Display :: fmt ( & id. private , f) ,
81- CrateNum :: ReservedForIncrCompCache => write ! ( f, "crate for decoding incr comp cache" ) ,
82- }
35+ fmt:: Display :: fmt ( & self . private , f)
8336 }
8437}
8538
@@ -97,15 +50,6 @@ impl<D: Decoder> Decodable<D> for CrateNum {
9750 }
9851}
9952
100- impl :: std:: fmt:: Debug for CrateNum {
101- fn fmt ( & self , fmt : & mut :: std:: fmt:: Formatter < ' _ > ) -> :: std:: fmt:: Result {
102- match self {
103- CrateNum :: Index ( id) => write ! ( fmt, "crate{}" , id. private) ,
104- CrateNum :: ReservedForIncrCompCache => write ! ( fmt, "crate for decoding incr comp cache" ) ,
105- }
106- }
107- }
108-
10953/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
11054/// stable across crate and compilation session boundaries. It consists of two
11155/// separate 64-bit hashes. The first uniquely identifies the crate this
0 commit comments