1- use std:: cell:: { Cell , RefCell } ;
1+ use std:: cell:: RefCell ;
22use std:: default:: Default ;
33use std:: hash:: { Hash , Hasher } ;
44use std:: iter:: FromIterator ;
@@ -18,7 +18,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1818use rustc_data_structures:: thin_vec:: ThinVec ;
1919use rustc_hir as hir;
2020use 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 } ;
2222use rustc_hir:: lang_items:: LangItem ;
2323use rustc_hir:: { BodyId , Mutability } ;
2424use rustc_index:: vec:: IndexVec ;
@@ -48,73 +48,68 @@ use self::ItemKind::*;
4848use self :: SelfTy :: * ;
4949use self :: Type :: * ;
5050
51- crate type FakeDefIdSet = FxHashSet < FakeDefId > ;
51+ crate type ItemIdSet = FxHashSet < ItemId > ;
5252
5353#[ 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 {
7666 #[ inline]
7767 crate fn is_local ( self ) -> bool {
7868 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 ,
8171 }
8272 }
8373
8474 #[ inline]
8575 #[ track_caller]
8676 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 ) )
8879 }
8980
9081 #[ inline]
9182 crate fn as_real ( self ) -> Option < DefId > {
9283 match self {
93- FakeDefId :: Real ( id) => Some ( id) ,
94- FakeDefId :: Fake ( _ , _ ) => None ,
84+ ItemId :: DefId ( id) => Some ( id) ,
85+ _ => None ,
9586 }
9687 }
9788
9889 #[ inline]
9990 crate fn krate ( self ) -> CrateNum {
10091 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,
10396 }
10497 }
10598
10699 #[ inline]
107100 crate fn index ( self ) -> Option < DefIndex > {
108101 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 ,
111106 }
112107 }
113108}
114109
115- impl From < DefId > for FakeDefId {
110+ impl From < DefId > for ItemId {
116111 fn from ( id : DefId ) -> Self {
117- Self :: Real ( id)
112+ Self :: DefId ( id)
118113 }
119114}
120115
@@ -338,14 +333,14 @@ crate struct Item {
338333 /// Information about this item that is specific to what kind of item it is.
339334 /// E.g., struct vs enum vs function.
340335 crate kind : Box < ItemKind > ,
341- crate def_id : FakeDefId ,
336+ crate def_id : ItemId ,
342337
343338 crate cfg : Option < Arc < Cfg > > ,
344339}
345340
346341// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
347342#[ 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 ) ;
349344
350345crate fn rustc_span ( def_id : DefId , tcx : TyCtxt < ' _ > ) -> Span {
351346 Span :: from_rustc_span ( def_id. as_local ( ) . map_or_else (
@@ -664,7 +659,8 @@ impl Item {
664659 }
665660
666661 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 ( ..) )
668664 }
669665}
670666
0 commit comments