1212//! If you need an internal construct, consider using `rustc_internal` or `rustc_smir`.
1313
1414use std:: cell:: Cell ;
15+ use std:: fmt;
16+ use std:: fmt:: Debug ;
1517
1618use self :: ty:: {
1719 GenericPredicates , Generics , ImplDef , ImplTrait , Span , TraitDecl , TraitDef , Ty , TyKind ,
@@ -29,9 +31,18 @@ pub type Symbol = String;
2931pub type CrateNum = usize ;
3032
3133/// A unique identification number for each item accessible for the current compilation unit.
32- #[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
34+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
3335pub struct DefId ( pub ( crate ) usize ) ;
3436
37+ impl Debug for DefId {
38+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
39+ f. debug_struct ( "DefId:" )
40+ . field ( "id" , & self . 0 )
41+ . field ( "name" , & with ( |cx| cx. name_of_def_id ( * self ) ) )
42+ . finish ( )
43+ }
44+ }
45+
3546/// A unique identification number for each provenance
3647#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
3748pub struct AllocId ( pub ( crate ) usize ) ;
@@ -127,6 +138,9 @@ pub trait Context {
127138 /// Find a crate with the given name.
128139 fn find_crate ( & self , name : & str ) -> Option < Crate > ;
129140
141+ /// Prints the name of given `DefId`
142+ fn name_of_def_id ( & self , def_id : DefId ) -> String ;
143+
130144 /// Obtain the representation of a type.
131145 fn ty_kind ( & mut self , ty : Ty ) -> TyKind ;
132146
0 commit comments