@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
6
6
use rustc_data_structures:: sso:: SsoHashSet ;
7
7
use rustc_hir as hir;
8
8
use rustc_hir:: def:: { self , CtorKind , DefKind , Namespace } ;
9
- use rustc_hir:: def_id:: { DefId , DefIdSet , CRATE_DEF_INDEX , LOCAL_CRATE } ;
9
+ use rustc_hir:: def_id:: { DefId , DefIdSet , CRATE_DEF_ID , LOCAL_CRATE } ;
10
10
use rustc_hir:: definitions:: { DefPathData , DefPathDataName , DisambiguatedDefPathData } ;
11
11
use rustc_session:: config:: TrimmedDefPaths ;
12
12
use rustc_session:: cstore:: { ExternCrate , ExternCrateSource } ;
@@ -335,9 +335,7 @@ pub trait PrettyPrinter<'tcx>:
335
335
336
336
// If `def_id` is a direct or injected extern crate, return the
337
337
// path to the crate followed by the path to the item within the crate.
338
- if def_id. index == CRATE_DEF_INDEX {
339
- let cnum = def_id. krate ;
340
-
338
+ if let Some ( cnum) = def_id. as_crate_root ( ) {
341
339
if cnum == LOCAL_CRATE {
342
340
return Ok ( ( self . path_crate ( cnum) ?, true ) ) ;
343
341
}
@@ -2227,11 +2225,11 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2227
2225
ty:: BrNamed ( _, _) => br. kind ,
2228
2226
ty:: BrAnon ( i) => {
2229
2227
let name = region_map[ & ( i + 1 ) ] ;
2230
- ty:: BrNamed ( DefId :: local ( CRATE_DEF_INDEX ) , name)
2228
+ ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name)
2231
2229
}
2232
2230
ty:: BrEnv => {
2233
2231
let name = region_map[ & 0 ] ;
2234
- ty:: BrNamed ( DefId :: local ( CRATE_DEF_INDEX ) , name)
2232
+ ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name)
2235
2233
}
2236
2234
} ;
2237
2235
self . tcx . mk_region ( ty:: ReLateBound (
@@ -2257,7 +2255,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2257
2255
}
2258
2256
} ;
2259
2257
do_continue ( & mut self , name) ;
2260
- ty:: BrNamed ( DefId :: local ( CRATE_DEF_INDEX ) , name)
2258
+ ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name)
2261
2259
}
2262
2260
} ;
2263
2261
tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST , ty:: BoundRegion { var : br. var , kind } ) )
@@ -2697,7 +2695,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
2697
2695
let mut seen_defs: DefIdSet = Default :: default ( ) ;
2698
2696
2699
2697
for & cnum in tcx. crates ( ( ) ) . iter ( ) {
2700
- let def_id = DefId { krate : cnum, index : CRATE_DEF_INDEX } ;
2698
+ let def_id = cnum. as_def_id ( ) ;
2701
2699
2702
2700
// Ignore crates that are not direct dependencies.
2703
2701
match tcx. extern_crate ( def_id) {
0 commit comments