1
- use std:: cell:: { Cell , RefCell } ;
1
+ use std:: cell:: RefCell ;
2
2
use std:: default:: Default ;
3
3
use std:: hash:: { Hash , Hasher } ;
4
4
use std:: iter:: FromIterator ;
@@ -18,7 +18,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
18
18
use rustc_data_structures:: thin_vec:: ThinVec ;
19
19
use rustc_hir as hir;
20
20
use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
21
- use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , CRATE_DEF_INDEX , LOCAL_CRATE } ;
21
+ use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , CRATE_DEF_INDEX } ;
22
22
use rustc_hir:: lang_items:: LangItem ;
23
23
use rustc_hir:: { BodyId , Mutability } ;
24
24
use rustc_index:: vec:: IndexVec ;
@@ -48,73 +48,68 @@ use self::ItemKind::*;
48
48
use self :: SelfTy :: * ;
49
49
use self :: Type :: * ;
50
50
51
- crate type FakeDefIdSet = FxHashSet < FakeDefId > ;
51
+ crate type ItemIdSet = FxHashSet < ItemId > ;
52
52
53
53
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
54
- crate enum FakeDefId {
55
- Real ( DefId ) ,
56
- Fake ( DefIndex , CrateNum ) ,
57
- }
58
-
59
- impl FakeDefId {
60
- #[ cfg( parallel_compiler) ]
61
- crate fn new_fake ( crate : CrateNum ) -> Self {
62
- unimplemented ! ( "" )
63
- }
64
-
65
- #[ cfg( not( parallel_compiler) ) ]
66
- crate fn new_fake ( krate : CrateNum ) -> Self {
67
- thread_local ! ( static FAKE_DEF_ID_COUNTER : Cell <usize > = Cell :: new( 0 ) ) ;
68
- let id = FAKE_DEF_ID_COUNTER . with ( |id| {
69
- let tmp = id. get ( ) ;
70
- id. set ( tmp + 1 ) ;
71
- tmp
72
- } ) ;
73
- Self :: Fake ( DefIndex :: from ( id) , krate)
74
- }
75
-
54
+ crate enum ItemId {
55
+ /// A "normal" item that uses a [`DefId`] for identification.
56
+ DefId ( DefId ) ,
57
+ /// Identifier that is used for auto traits.
58
+ Auto { trait_ : DefId , for_ : DefId } ,
59
+ /// Identifier that is used for blanket implementations.
60
+ Blanket { trait_ : DefId , for_ : DefId } ,
61
+ /// Identifier for primitive types.
62
+ Primitive ( CrateNum ) ,
63
+ }
64
+
65
+ impl ItemId {
76
66
#[ inline]
77
67
crate fn is_local ( self ) -> bool {
78
68
match self {
79
- FakeDefId :: Real ( id) => id. is_local ( ) ,
80
- FakeDefId :: Fake ( _ , krate ) => krate == LOCAL_CRATE ,
69
+ ItemId :: DefId ( id) => id. is_local ( ) ,
70
+ _ => false ,
81
71
}
82
72
}
83
73
84
74
#[ inline]
85
75
#[ track_caller]
86
76
crate fn expect_real ( self ) -> rustc_hir:: def_id:: DefId {
87
- self . as_real ( ) . unwrap_or_else ( || panic ! ( "FakeDefId::expect_real: `{:?}` isn't real" , self ) )
77
+ self . as_real ( )
78
+ . unwrap_or_else ( || panic ! ( "ItemId::expect_real: `{:?}` isn't a real ItemId" , self ) )
88
79
}
89
80
90
81
#[ inline]
91
82
crate fn as_real ( self ) -> Option < DefId > {
92
83
match self {
93
- FakeDefId :: Real ( id) => Some ( id) ,
94
- FakeDefId :: Fake ( _ , _ ) => None ,
84
+ ItemId :: DefId ( id) => Some ( id) ,
85
+ _ => None ,
95
86
}
96
87
}
97
88
98
89
#[ inline]
99
90
crate fn krate ( self ) -> CrateNum {
100
91
match self {
101
- FakeDefId :: Real ( id) => id. krate ,
102
- FakeDefId :: Fake ( _, krate) => krate,
92
+ ItemId :: DefId ( id) => id. krate ,
93
+ ItemId :: Auto { trait_, .. } => trait_. krate ,
94
+ ItemId :: Blanket { trait_, .. } => trait_. krate ,
95
+ ItemId :: Primitive ( krate) => krate,
103
96
}
104
97
}
105
98
106
99
#[ inline]
107
100
crate fn index ( self ) -> Option < DefIndex > {
108
101
match self {
109
- FakeDefId :: Real ( id) => Some ( id. index ) ,
110
- FakeDefId :: Fake ( _, _) => None ,
102
+ ItemId :: DefId ( id) => Some ( id. index ) ,
103
+ ItemId :: Auto { trait_, .. } => Some ( trait_. index ) ,
104
+ ItemId :: Blanket { trait_, .. } => Some ( trait_. index ) ,
105
+ ItemId :: Primitive ( ..) => None ,
111
106
}
112
107
}
113
108
}
114
109
115
- impl From < DefId > for FakeDefId {
110
+ impl From < DefId > for ItemId {
116
111
fn from ( id : DefId ) -> Self {
117
- Self :: Real ( id)
112
+ Self :: DefId ( id)
118
113
}
119
114
}
120
115
@@ -338,14 +333,14 @@ crate struct Item {
338
333
/// Information about this item that is specific to what kind of item it is.
339
334
/// E.g., struct vs enum vs function.
340
335
crate kind : Box < ItemKind > ,
341
- crate def_id : FakeDefId ,
336
+ crate def_id : ItemId ,
342
337
343
338
crate cfg : Option < Arc < Cfg > > ,
344
339
}
345
340
346
341
// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
347
342
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
348
- rustc_data_structures:: static_assert_size!( Item , 48 ) ;
343
+ rustc_data_structures:: static_assert_size!( Item , 56 ) ;
349
344
350
345
crate fn rustc_span ( def_id : DefId , tcx : TyCtxt < ' _ > ) -> Span {
351
346
Span :: from_rustc_span ( def_id. as_local ( ) . map_or_else (
@@ -664,7 +659,8 @@ impl Item {
664
659
}
665
660
666
661
crate fn is_fake ( & self ) -> bool {
667
- matches ! ( self . def_id, FakeDefId :: Fake ( _, _) )
662
+ // FIXME: Find a better way to handle this
663
+ !matches ! ( self . def_id, ItemId :: DefId ( ..) )
668
664
}
669
665
}
670
666
0 commit comments