@@ -96,34 +96,20 @@ impl fmt::Display for CrateNum {
9696impl  serialize:: UseSpecializedEncodable  for  CrateNum  { } 
9797impl  serialize:: UseSpecializedDecodable  for  CrateNum  { } 
9898
99- /// A DefIndex is an index into the hir-map for a crate, identifying a 
100- /// particular definition. It should really be considered an interned 
101- /// shorthand for a particular DefPath. 
102- #[ derive( Clone ,  PartialEq ,  Eq ,  PartialOrd ,  Ord ,  Hash ,  Copy ) ]  
103- pub  struct  DefIndex ( u32 ) ; 
104- 
105- /// The crate root is always assigned index 0 by the AST Map code, 
106- /// thanks to `NodeCollector::new`. 
107- pub  const  CRATE_DEF_INDEX :  DefIndex  = DefIndex ( 0 ) ; 
99+ newtype_index !  { 
100+     /// A DefIndex is an index into the hir-map for a crate, identifying a 
101+      /// particular definition. It should really be considered an interned 
102+      /// shorthand for a particular DefPath. 
103+      pub  struct  DefIndex  { 
104+         DEBUG_FORMAT  = "DefIndex({})" , 
108105
109- impl  fmt :: Debug   for   DefIndex   { 
110-     fn   fmt ( & self ,   f :   & mut  fmt :: Formatter < ' _ > )  -> fmt :: Result   { 
111-         write ! ( f ,   "DefIndex({})" ,   self . as_array_index ( ) ) 
106+          /// The crate root is always assigned index 0 by the AST Map code, 
107+           /// thanks to `NodeCollector::new`. 
108+          const   CRATE_DEF_INDEX  =  0 , 
112109    } 
113110} 
114111
115112impl  DefIndex  { 
116-     /// Converts this DefIndex into a zero-based array index. 
117-      #[ inline]  
118-     pub  fn  as_array_index ( & self )  -> usize  { 
119-         self . 0  as  usize 
120-     } 
121- 
122-     #[ inline]  
123-     pub  fn  from_array_index ( i :  usize )  -> DefIndex  { 
124-         DefIndex ( i as  u32 ) 
125-     } 
126- 
127113    // Proc macros from a proc-macro crate have a kind of virtual DefIndex. This 
128114    // function maps the index of the macro within the crate (which is also the 
129115    // index of the macro in the CrateMetadata::proc_macros array) to the 
@@ -132,7 +118,7 @@ impl DefIndex {
132118        // DefIndex for proc macros start from FIRST_FREE_DEF_INDEX, 
133119        // because the first FIRST_FREE_DEF_INDEX indexes are reserved 
134120        // for internal use. 
135-         let  def_index = DefIndex :: from_array_index ( 
121+         let  def_index = DefIndex :: from ( 
136122            proc_macro_index. checked_add ( FIRST_FREE_DEF_INDEX ) 
137123                . expect ( "integer overflow adding `proc_macro_index`" ) ) ; 
138124        assert ! ( def_index != CRATE_DEF_INDEX ) ; 
@@ -141,19 +127,11 @@ impl DefIndex {
141127
142128    // This function is the reverse of from_proc_macro_index() above. 
143129    pub  fn  to_proc_macro_index ( self :  DefIndex )  -> usize  { 
144-         self . as_array_index ( ) . checked_sub ( FIRST_FREE_DEF_INDEX ) 
130+         self . index ( ) . checked_sub ( FIRST_FREE_DEF_INDEX ) 
145131            . unwrap_or_else ( || { 
146132                bug ! ( "using local index {:?} as proc-macro index" ,  self ) 
147133            } ) 
148134    } 
149- 
150-     pub  fn  from_raw_u32 ( x :  u32 )  -> DefIndex  { 
151-         DefIndex ( x) 
152-     } 
153- 
154-     pub  fn  as_raw_u32 ( & self )  -> u32  { 
155-         self . 0 
156-     } 
157135} 
158136
159137impl  serialize:: UseSpecializedEncodable  for  DefIndex  { } 
@@ -169,7 +147,7 @@ pub struct DefId {
169147
170148impl  fmt:: Debug  for  DefId  { 
171149    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
172-         write ! ( f,  "DefId({}:{}" ,  self . krate,  self . index. as_array_index ( ) ) ?; 
150+         write ! ( f,  "DefId({}:{}" ,  self . krate,  self . index. index ( ) ) ?; 
173151
174152        ty:: tls:: with_opt ( |opt_tcx| { 
175153            if  let  Some ( tcx)  = opt_tcx { 
0 commit comments