1- use std:: cell:: { Cell , RefCell } ;
1+ use std:: cell:: RefCell ;
22use std:: default:: Default ;
33use std:: hash:: { Hash , Hasher } ;
44use std:: iter:: FromIterator ;
@@ -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
53- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
54- crate enum FakeDefId {
55- Real ( DefId ) ,
56- Fake ( DefIndex , CrateNum ) ,
53+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Copy ) ]
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 { impl_id : DefId , for_ : DefId } ,
61+ /// Identifier for primitive types.
62+ Primitive ( PrimitiveType , CrateNum ) ,
5763}
5864
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-
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 :: Auto { for_ : id, .. }
70+ | ItemId :: Blanket { for_ : id, .. }
71+ | ItemId :: DefId ( id) => id. is_local ( ) ,
72+ ItemId :: Primitive ( _, krate) => krate == LOCAL_CRATE ,
8173 }
8274 }
8375
8476 #[ inline]
8577 #[ track_caller]
86- 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 ) )
78+ crate fn expect_def_id ( self ) -> DefId {
79+ self . as_def_id ( )
80+ . unwrap_or_else ( || panic ! ( "ItemId::expect_def_id: `{:?}` isn't a DefId" , self ) )
8881 }
8982
9083 #[ inline]
91- crate fn as_real ( self ) -> Option < DefId > {
84+ crate fn as_def_id ( self ) -> Option < DefId > {
9285 match self {
93- FakeDefId :: Real ( id) => Some ( id) ,
94- FakeDefId :: Fake ( _ , _ ) => None ,
86+ ItemId :: DefId ( id) => Some ( id) ,
87+ _ => None ,
9588 }
9689 }
9790
9891 #[ inline]
9992 crate fn krate ( self ) -> CrateNum {
10093 match self {
101- FakeDefId :: Real ( id) => id. krate ,
102- FakeDefId :: Fake ( _, krate) => krate,
94+ ItemId :: Auto { for_ : id, .. }
95+ | ItemId :: Blanket { for_ : id, .. }
96+ | ItemId :: DefId ( id) => id. krate ,
97+ ItemId :: Primitive ( _, krate) => krate,
10398 }
10499 }
105100
106101 #[ inline]
107102 crate fn index ( self ) -> Option < DefIndex > {
108103 match self {
109- FakeDefId :: Real ( id) => Some ( id. index ) ,
110- FakeDefId :: Fake ( _ , _ ) => None ,
104+ ItemId :: DefId ( id) => Some ( id. index ) ,
105+ _ => 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 (
@@ -359,19 +354,19 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
359354
360355impl Item {
361356 crate fn stability < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Option < & ' tcx Stability > {
362- if self . is_fake ( ) { None } else { tcx. lookup_stability ( self . def_id . expect_real ( ) ) }
357+ self . def_id . as_def_id ( ) . and_then ( |did| tcx. lookup_stability ( did ) )
363358 }
364359
365360 crate fn const_stability < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Option < & ' tcx ConstStability > {
366- if self . is_fake ( ) { None } else { tcx. lookup_const_stability ( self . def_id . expect_real ( ) ) }
361+ self . def_id . as_def_id ( ) . and_then ( |did| tcx. lookup_const_stability ( did ) )
367362 }
368363
369364 crate fn deprecation ( & self , tcx : TyCtxt < ' _ > ) -> Option < Deprecation > {
370- if self . is_fake ( ) { None } else { tcx. lookup_deprecation ( self . def_id . expect_real ( ) ) }
365+ self . def_id . as_def_id ( ) . and_then ( |did| tcx. lookup_deprecation ( did ) )
371366 }
372367
373368 crate fn inner_docs ( & self , tcx : TyCtxt < ' _ > ) -> bool {
374- if self . is_fake ( ) { false } else { tcx. get_attrs ( self . def_id . expect_real ( ) ) . inner_docs ( ) }
369+ self . def_id . as_def_id ( ) . map ( |did| tcx. get_attrs ( did ) . inner_docs ( ) ) . unwrap_or ( false )
375370 }
376371
377372 crate fn span ( & self , tcx : TyCtxt < ' _ > ) -> Span {
@@ -383,10 +378,8 @@ impl Item {
383378 kind
384379 {
385380 * span
386- } else if self . is_fake ( ) {
387- Span :: dummy ( )
388381 } else {
389- rustc_span ( self . def_id . expect_real ( ) , tcx)
382+ self . def_id . as_def_id ( ) . map ( |did| rustc_span ( did , tcx) ) . unwrap_or_else ( || Span :: dummy ( ) )
390383 }
391384 }
392385
@@ -551,7 +544,7 @@ impl Item {
551544 }
552545
553546 crate fn is_crate ( & self ) -> bool {
554- self . is_mod ( ) && self . def_id . as_real ( ) . map_or ( false , |did| did. index == CRATE_DEF_INDEX )
547+ self . is_mod ( ) && self . def_id . as_def_id ( ) . map_or ( false , |did| did. index == CRATE_DEF_INDEX )
555548 }
556549 crate fn is_mod ( & self ) -> bool {
557550 self . type_ ( ) == ItemType :: Module
@@ -662,10 +655,6 @@ impl Item {
662655 _ => false ,
663656 }
664657 }
665-
666- crate fn is_fake ( & self ) -> bool {
667- matches ! ( self . def_id, FakeDefId :: Fake ( _, _) )
668- }
669658}
670659
671660#[ derive( Clone , Debug ) ]
0 commit comments