@@ -68,7 +68,7 @@ impl DefPathTable {
68
68
//
69
69
// See the documentation for DefPathHash for more information.
70
70
panic ! (
71
- "found DefPathHash collision between {def_path1:?} and {def_path2:?}. \
71
+ "found DefPathHash collision between {def_path1:# ?} and {def_path2:# ?}. \
72
72
Compilation cannot continue."
73
73
) ;
74
74
}
@@ -97,13 +97,31 @@ impl DefPathTable {
97
97
}
98
98
}
99
99
100
+ #[ derive( Debug ) ]
101
+ pub struct DisambiguatorState {
102
+ next : UnordMap < ( LocalDefId , DefPathData ) , u32 > ,
103
+ }
104
+
105
+ impl DisambiguatorState {
106
+ pub fn new ( ) -> Self {
107
+ Self { next : Default :: default ( ) }
108
+ }
109
+
110
+ /// Creates a `DisambiguatorState` where the next allocated `(LocalDefId, DefPathData)` pair
111
+ /// will have `index` as the disambiguator.
112
+ pub fn with ( def_id : LocalDefId , data : DefPathData , index : u32 ) -> Self {
113
+ let mut this = Self :: new ( ) ;
114
+ this. next . insert ( ( def_id, data) , index) ;
115
+ this
116
+ }
117
+ }
118
+
100
119
/// The definition table containing node definitions.
101
120
/// It holds the `DefPathTable` for `LocalDefId`s/`DefPath`s.
102
121
/// It also stores mappings to convert `LocalDefId`s to/from `HirId`s.
103
122
#[ derive( Debug ) ]
104
123
pub struct Definitions {
105
124
table : DefPathTable ,
106
- next_disambiguator : UnordMap < ( LocalDefId , DefPathData ) , u32 > ,
107
125
}
108
126
109
127
/// A unique identifier that we can use to lookup a definition
@@ -173,7 +191,11 @@ impl DisambiguatedDefPathData {
173
191
}
174
192
}
175
193
DefPathDataName :: Anon { namespace } => {
176
- write ! ( writer, "{{{}#{}}}" , namespace, self . disambiguator)
194
+ if let DefPathData :: AnonAssocTy ( method) = self . data {
195
+ write ! ( writer, "{}::{{{}#{}}}" , method, namespace, self . disambiguator)
196
+ } else {
197
+ write ! ( writer, "{{{}#{}}}" , namespace, self . disambiguator)
198
+ }
177
199
}
178
200
}
179
201
}
@@ -288,7 +310,7 @@ pub enum DefPathData {
288
310
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
289
311
OpaqueTy ,
290
312
/// An anonymous associated type from an RPITIT.
291
- AnonAssocTy ,
313
+ AnonAssocTy ( Symbol ) ,
292
314
/// A synthetic body for a coroutine's by-move body.
293
315
SyntheticCoroutineBody ,
294
316
}
@@ -342,24 +364,33 @@ impl Definitions {
342
364
let root = LocalDefId { local_def_index : table. allocate ( key, def_path_hash) } ;
343
365
assert_eq ! ( root. local_def_index, CRATE_DEF_INDEX ) ;
344
366
345
- Definitions { table, next_disambiguator : Default :: default ( ) }
367
+ Definitions { table }
346
368
}
347
369
348
- /// Adds a definition with a parent definition.
349
- pub fn create_def ( & mut self , parent : LocalDefId , data : DefPathData ) -> LocalDefId {
370
+ /// Creates a definition with a parent definition.
371
+ /// If there are multiple definitions with the same DefPathData and the same parent, use
372
+ /// `disambiguator` to differentiate them. Distinct `DisambiguatorState` instances are not
373
+ /// guaranteed to generate unique disambiguators and should instead ensure that the `parent`
374
+ /// and `data` pair is distinct from other instances.
375
+ pub fn create_def (
376
+ & mut self ,
377
+ parent : LocalDefId ,
378
+ data : DefPathData ,
379
+ disambiguator : & mut DisambiguatorState ,
380
+ ) -> LocalDefId {
350
381
// We can't use `Debug` implementation for `LocalDefId` here, since it tries to acquire a
351
382
// reference to `Definitions` and we're already holding a mutable reference.
352
383
debug ! (
353
384
"create_def(parent={}, data={data:?})" ,
354
385
self . def_path( parent) . to_string_no_crate_verbose( ) ,
355
386
) ;
356
387
357
- // The root node must be created with `create_root_def ()`.
388
+ // The root node must be created in `new ()`.
358
389
assert ! ( data != DefPathData :: CrateRoot ) ;
359
390
360
391
// Find the next free disambiguator for this key.
361
392
let disambiguator = {
362
- let next_disamb = self . next_disambiguator . entry ( ( parent, data) ) . or_insert ( 0 ) ;
393
+ let next_disamb = disambiguator . next . entry ( ( parent, data) ) . or_insert ( 0 ) ;
363
394
let disambiguator = * next_disamb;
364
395
* next_disamb = next_disamb. checked_add ( 1 ) . expect ( "disambiguator overflow" ) ;
365
396
disambiguator
@@ -411,7 +442,9 @@ impl DefPathData {
411
442
pub fn get_opt_name ( & self ) -> Option < Symbol > {
412
443
use self :: DefPathData :: * ;
413
444
match * self {
414
- TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name) => Some ( name) ,
445
+ TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name) | AnonAssocTy ( name) => {
446
+ Some ( name)
447
+ }
415
448
416
449
Impl
417
450
| ForeignMod
@@ -422,7 +455,6 @@ impl DefPathData {
422
455
| Ctor
423
456
| AnonConst
424
457
| OpaqueTy
425
- | AnonAssocTy
426
458
| SyntheticCoroutineBody => None ,
427
459
}
428
460
}
@@ -443,7 +475,7 @@ impl DefPathData {
443
475
Ctor => DefPathDataName :: Anon { namespace : sym:: constructor } ,
444
476
AnonConst => DefPathDataName :: Anon { namespace : sym:: constant } ,
445
477
OpaqueTy => DefPathDataName :: Anon { namespace : sym:: opaque } ,
446
- AnonAssocTy => DefPathDataName :: Anon { namespace : sym:: anon_assoc } ,
478
+ AnonAssocTy ( .. ) => DefPathDataName :: Anon { namespace : sym:: anon_assoc } ,
447
479
SyntheticCoroutineBody => DefPathDataName :: Anon { namespace : sym:: synthetic } ,
448
480
}
449
481
}
0 commit comments