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