@@ -99,7 +99,7 @@ impl DefPathTable {
9999
100100#[ derive( Debug ) ]
101101pub struct DisambiguatorState {
102- next : UnordMap < ( LocalDefId , DefPathData ) , u32 > ,
102+ next : UnordMap < ( LocalDefId , DefPathData2 ) , u32 > ,
103103}
104104
105105impl DisambiguatorState {
@@ -109,7 +109,7 @@ impl DisambiguatorState {
109109
110110 /// Creates a `DisambiguatorState` where the next allocated `(LocalDefId, DefPathData)` pair
111111 /// will have `index` as the disambiguator.
112- pub fn with ( def_id : LocalDefId , data : DefPathData , index : u32 ) -> Self {
112+ pub fn with ( def_id : LocalDefId , data : DefPathData2 , index : u32 ) -> Self {
113113 let mut this = Self :: new ( ) ;
114114 this. next . insert ( ( def_id, data) , index) ;
115115 this
@@ -146,8 +146,8 @@ impl DefKey {
146146
147147 let DisambiguatedDefPathData { ref data, disambiguator } = self . disambiguated_data ;
148148
149- std :: mem :: discriminant ( data) . hash ( & mut hasher) ;
150- if let Some ( name) = data. hashed_symbol ( ) {
149+ data. hash ( & mut hasher) ;
150+ if let Some ( name) = data. unwrap ( ) . hashed_symbol ( ) {
151151 // Get a stable hash by considering the symbol chars rather than
152152 // the symbol index.
153153 name. as_str ( ) . hash ( & mut hasher) ;
@@ -166,7 +166,7 @@ impl DefKey {
166166
167167 #[ inline]
168168 pub fn get_opt_name ( & self ) -> Option < Symbol > {
169- self . disambiguated_data . data . get_opt_name ( )
169+ self . disambiguated_data . data . unwrap ( ) . get_opt_name ( )
170170 }
171171}
172172
@@ -178,13 +178,13 @@ impl DefKey {
178178/// the same module, they do get distinct `DefId`s.
179179#[ derive( Copy , Clone , PartialEq , Debug , Encodable , BlobDecodable ) ]
180180pub struct DisambiguatedDefPathData {
181- pub data : DefPathData ,
181+ pub data : DefPathData2 ,
182182 pub disambiguator : u32 ,
183183}
184184
185185impl DisambiguatedDefPathData {
186186 pub fn as_sym ( & self , verbose : bool ) -> Symbol {
187- match self . data . name ( ) {
187+ match self . data . unwrap ( ) . name ( ) {
188188 DefPathDataName :: Named ( name) => {
189189 if verbose && self . disambiguator != 0 {
190190 Symbol :: intern ( & format ! ( "{}#{}" , name, self . disambiguator) )
@@ -193,7 +193,7 @@ impl DisambiguatedDefPathData {
193193 }
194194 }
195195 DefPathDataName :: Anon { namespace } => {
196- if let DefPathData :: AnonAssocTy ( method) = self . data {
196+ if let DefPathData :: AnonAssocTy ( method) = self . data . unwrap ( ) {
197197 Symbol :: intern ( & format ! ( "{}::{{{}#{}}}" , method, namespace, self . disambiguator) )
198198 } else {
199199 Symbol :: intern ( & format ! ( "{{{}#{}}}" , namespace, self . disambiguator) )
@@ -224,7 +224,7 @@ impl DefPath {
224224 let p = index. unwrap ( ) ;
225225 let key = get_key ( p) ;
226226 debug ! ( "DefPath::make: key={:?}" , key) ;
227- match key. disambiguated_data . data {
227+ match key. disambiguated_data . data . unwrap ( ) {
228228 DefPathData :: CrateRoot => {
229229 assert ! ( key. parent. is_none( ) ) ;
230230 break ;
@@ -276,6 +276,31 @@ pub enum DelegationDefPathKind {
276276 TyParam ,
277277}
278278
279+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , Encodable , BlobDecodable ) ]
280+ pub enum DefPathData2 {
281+ Default ( DefPathData ) ,
282+ Delegation { name : Symbol , kind : DelegationDefPathKind } ,
283+ }
284+
285+ impl Into < DefPathData2 > for DefPathData {
286+ fn into ( self ) -> DefPathData2 {
287+ DefPathData2 :: Default ( self )
288+ }
289+ }
290+
291+ impl DefPathData2 {
292+ pub fn unwrap ( & self ) -> DefPathData {
293+ match * self {
294+ DefPathData2 :: Default ( def_path_data) => def_path_data,
295+ DefPathData2 :: Delegation { name, kind } => match kind {
296+ DelegationDefPathKind :: Lifetime => DefPathData :: LifetimeNs ( name) ,
297+ DelegationDefPathKind :: ConstParam => DefPathData :: ValueNs ( name) ,
298+ DelegationDefPathKind :: TyParam => DefPathData :: TypeNs ( name) ,
299+ } ,
300+ }
301+ }
302+ }
303+
279304/// New variants should only be added in synchronization with `enum DefKind`.
280305#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , Encodable , BlobDecodable ) ]
281306pub enum DefPathData {
@@ -325,10 +350,6 @@ pub enum DefPathData {
325350 SyntheticCoroutineBody ,
326351 /// Additional static data referred to by a static.
327352 NestedStatic ,
328- Delegation {
329- name : Symbol ,
330- kind : DelegationDefPathKind ,
331- } ,
332353}
333354
334355impl Definitions {
@@ -367,7 +388,7 @@ impl Definitions {
367388 let key = DefKey {
368389 parent : None ,
369390 disambiguated_data : DisambiguatedDefPathData {
370- data : DefPathData :: CrateRoot ,
391+ data : DefPathData2 :: Default ( DefPathData :: CrateRoot ) ,
371392 disambiguator : 0 ,
372393 } ,
373394 } ;
@@ -399,7 +420,7 @@ impl Definitions {
399420 pub fn create_def (
400421 & mut self ,
401422 parent : LocalDefId ,
402- data : DefPathData ,
423+ data : DefPathData2 ,
403424 disambiguator : & mut DisambiguatorState ,
404425 ) -> LocalDefId {
405426 // We can't use `Debug` implementation for `LocalDefId` here, since it tries to acquire a
@@ -410,7 +431,7 @@ impl Definitions {
410431 ) ;
411432
412433 // The root node must be created in `new()`.
413- assert ! ( data != DefPathData :: CrateRoot ) ;
434+ assert ! ( data. unwrap ( ) != DefPathData :: CrateRoot ) ;
414435
415436 // Find the next free disambiguator for this key.
416437 let disambiguator = {
@@ -466,12 +487,8 @@ impl DefPathData {
466487 pub fn get_opt_name ( & self ) -> Option < Symbol > {
467488 use self :: DefPathData :: * ;
468489 match * self {
469- TypeNs ( name)
470- | ValueNs ( name)
471- | MacroNs ( name)
472- | LifetimeNs ( name)
473- | OpaqueLifetime ( name)
474- | Delegation { name, .. } => Some ( name) ,
490+ TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name)
491+ | OpaqueLifetime ( name) => Some ( name) ,
475492
476493 DesugaredAnonymousLifetime => Some ( kw:: UnderscoreLifetime ) ,
477494
@@ -494,13 +511,8 @@ impl DefPathData {
494511 fn hashed_symbol ( & self ) -> Option < Symbol > {
495512 use self :: DefPathData :: * ;
496513 match * self {
497- TypeNs ( name)
498- | ValueNs ( name)
499- | MacroNs ( name)
500- | LifetimeNs ( name)
501- | AnonAssocTy ( name)
502- | OpaqueLifetime ( name)
503- | Delegation { name, .. } => Some ( name) ,
514+ TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name) | AnonAssocTy ( name)
515+ | OpaqueLifetime ( name) => Some ( name) ,
504516
505517 DesugaredAnonymousLifetime => Some ( kw:: UnderscoreLifetime ) ,
506518
@@ -522,12 +534,8 @@ impl DefPathData {
522534 pub fn name ( & self ) -> DefPathDataName {
523535 use self :: DefPathData :: * ;
524536 match * self {
525- TypeNs ( name)
526- | ValueNs ( name)
527- | MacroNs ( name)
528- | LifetimeNs ( name)
529- | OpaqueLifetime ( name)
530- | Delegation { name, .. } => DefPathDataName :: Named ( name) ,
537+ TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name)
538+ | OpaqueLifetime ( name) => DefPathDataName :: Named ( name) ,
531539 // Note that this does not show up in user print-outs.
532540 CrateRoot => DefPathDataName :: Anon { namespace : kw:: Crate } ,
533541 Impl => DefPathDataName :: Anon { namespace : kw:: Impl } ,
0 commit comments