12
12
//! If you need an internal construct, consider using `rustc_internal` or `rustc_smir`.
13
13
14
14
use std:: cell:: Cell ;
15
+ use std:: fmt;
16
+ use std:: fmt:: Debug ;
15
17
16
18
use self :: ty:: {
17
19
GenericPredicates , Generics , ImplDef , ImplTrait , Span , TraitDecl , TraitDef , Ty , TyKind ,
@@ -29,9 +31,18 @@ pub type Symbol = String;
29
31
pub type CrateNum = usize ;
30
32
31
33
/// 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 ) ]
33
35
pub struct DefId ( pub ( crate ) usize ) ;
34
36
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
+
35
46
/// A unique identification number for each provenance
36
47
#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
37
48
pub struct AllocId ( pub ( crate ) usize ) ;
@@ -127,6 +138,9 @@ pub trait Context {
127
138
/// Find a crate with the given name.
128
139
fn find_crate ( & self , name : & str ) -> Option < Crate > ;
129
140
141
+ /// Prints the name of given `DefId`
142
+ fn name_of_def_id ( & self , def_id : DefId ) -> String ;
143
+
130
144
/// Obtain the representation of a type.
131
145
fn ty_kind ( & mut self , ty : Ty ) -> TyKind ;
132
146
0 commit comments