1- use crate :: ty ;
1+ use rustc_data_structures :: AtomicRef ;
22use rustc_index:: vec:: Idx ;
33use std:: fmt;
44use std:: u32;
@@ -40,7 +40,7 @@ impl Idx for CrateNum {
4040 fn index ( self ) -> usize {
4141 match self {
4242 CrateNum :: Index ( idx) => Idx :: index ( idx) ,
43- _ => bug ! ( "Tried to get crate index of {:?}" , self ) ,
43+ _ => panic ! ( "Tried to get crate index of {:?}" , self ) ,
4444 }
4545 }
4646}
@@ -61,14 +61,14 @@ impl CrateNum {
6161 pub fn as_usize ( self ) -> usize {
6262 match self {
6363 CrateNum :: Index ( id) => id. as_usize ( ) ,
64- _ => bug ! ( "tried to get index of non-standard crate {:?}" , self ) ,
64+ _ => panic ! ( "tried to get index of non-standard crate {:?}" , self ) ,
6565 }
6666 }
6767
6868 pub fn as_u32 ( self ) -> u32 {
6969 match self {
7070 CrateNum :: Index ( id) => id. as_u32 ( ) ,
71- _ => bug ! ( "tried to get index of non-standard crate {:?}" , self ) ,
71+ _ => panic ! ( "tried to get index of non-standard crate {:?}" , self ) ,
7272 }
7373 }
7474
@@ -113,21 +113,6 @@ pub struct DefId {
113113 pub index : DefIndex ,
114114}
115115
116- impl fmt:: Debug for DefId {
117- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
118- write ! ( f, "DefId({}:{}" , self . krate, self . index. index( ) ) ?;
119-
120- ty:: tls:: with_opt ( |opt_tcx| {
121- if let Some ( tcx) = opt_tcx {
122- write ! ( f, " ~ {}" , tcx. def_path_debug_str( * self ) ) ?;
123- }
124- Ok ( ( ) )
125- } ) ?;
126-
127- write ! ( f, ")" )
128- }
129- }
130-
131116impl DefId {
132117 /// Makes a local `DefId` from the given `DefIndex`.
133118 #[ inline]
@@ -153,6 +138,19 @@ impl DefId {
153138impl rustc_serialize:: UseSpecializedEncodable for DefId { }
154139impl rustc_serialize:: UseSpecializedDecodable for DefId { }
155140
141+ pub fn default_def_id_debug ( def_id : DefId , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
142+ f. debug_struct ( "DefId" ) . field ( "krate" , & def_id. krate ) . field ( "index" , & def_id. index ) . finish ( )
143+ }
144+
145+ pub static DEF_ID_DEBUG : AtomicRef < fn ( DefId , & mut fmt:: Formatter < ' _ > ) -> fmt:: Result > =
146+ AtomicRef :: new ( & ( default_def_id_debug as fn ( _, & mut fmt:: Formatter < ' _ > ) -> _ ) ) ;
147+
148+ impl fmt:: Debug for DefId {
149+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
150+ ( * DEF_ID_DEBUG ) ( * self , f)
151+ }
152+ }
153+
156154rustc_data_structures:: define_id_collections!( DefIdMap , DefIdSet , DefId ) ;
157155
158156/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since
0 commit comments