@@ -9,76 +9,29 @@ use std::borrow::Borrow;
9
9
use std:: fmt;
10
10
11
11
rustc_index:: newtype_index! {
12
- pub struct CrateId {
12
+ pub struct CrateNum {
13
13
ENCODABLE = custom
14
+ DEBUG_FORMAT = "crate{}"
14
15
}
15
16
}
16
17
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
-
25
18
/// Item definitions in the currently-compiled crate would have the `CrateNum`
26
19
/// `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 ) ;
43
21
44
22
impl CrateNum {
45
23
pub fn new ( x : usize ) -> CrateNum {
46
24
CrateNum :: from_usize ( x)
47
25
}
48
26
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
-
71
27
pub fn as_def_id ( & self ) -> DefId {
72
28
DefId { krate : * self , index : CRATE_DEF_INDEX }
73
29
}
74
30
}
75
31
76
32
impl fmt:: Display for CrateNum {
77
33
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)
82
35
}
83
36
}
84
37
@@ -96,15 +49,6 @@ impl<D: Decoder> Decodable<D> for CrateNum {
96
49
}
97
50
}
98
51
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
-
108
52
/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
109
53
/// stable across crate and compilation session boundaries. It consists of two
110
54
/// separate 64-bit hashes. The first uniquely identifies the crate this
0 commit comments