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