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 ;
@@ -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
- #[ 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 ) ,
57
63
}
58
64
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 {
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 :: Auto { for_ : id, .. }
70
+ | ItemId :: Blanket { for_ : id, .. }
71
+ | ItemId :: DefId ( id) => id. is_local ( ) ,
72
+ ItemId :: Primitive ( _, krate) => krate == LOCAL_CRATE ,
81
73
}
82
74
}
83
75
84
76
#[ inline]
85
77
#[ 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 ) )
88
81
}
89
82
90
83
#[ inline]
91
- crate fn as_real ( self ) -> Option < DefId > {
84
+ crate fn as_def_id ( self ) -> Option < DefId > {
92
85
match self {
93
- FakeDefId :: Real ( id) => Some ( id) ,
94
- FakeDefId :: Fake ( _ , _ ) => None ,
86
+ ItemId :: DefId ( id) => Some ( id) ,
87
+ _ => None ,
95
88
}
96
89
}
97
90
98
91
#[ inline]
99
92
crate fn krate ( self ) -> CrateNum {
100
93
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,
103
98
}
104
99
}
105
100
106
101
#[ inline]
107
102
crate fn index ( self ) -> Option < DefIndex > {
108
103
match self {
109
- FakeDefId :: Real ( id) => Some ( id. index ) ,
110
- FakeDefId :: Fake ( _ , _ ) => None ,
104
+ ItemId :: DefId ( id) => Some ( id. index ) ,
105
+ _ => 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 (
@@ -359,19 +354,19 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
359
354
360
355
impl Item {
361
356
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 ) )
363
358
}
364
359
365
360
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 ) )
367
362
}
368
363
369
364
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 ) )
371
366
}
372
367
373
368
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 )
375
370
}
376
371
377
372
crate fn span ( & self , tcx : TyCtxt < ' _ > ) -> Span {
@@ -383,10 +378,8 @@ impl Item {
383
378
kind
384
379
{
385
380
* span
386
- } else if self . is_fake ( ) {
387
- Span :: dummy ( )
388
381
} 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 ( ) )
390
383
}
391
384
}
392
385
@@ -551,7 +544,7 @@ impl Item {
551
544
}
552
545
553
546
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 )
555
548
}
556
549
crate fn is_mod ( & self ) -> bool {
557
550
self . type_ ( ) == ItemType :: Module
@@ -662,10 +655,6 @@ impl Item {
662
655
_ => false ,
663
656
}
664
657
}
665
-
666
- crate fn is_fake ( & self ) -> bool {
667
- matches ! ( self . def_id, FakeDefId :: Fake ( _, _) )
668
- }
669
658
}
670
659
671
660
#[ derive( Clone , Debug ) ]
0 commit comments