@@ -120,21 +120,21 @@ macro_rules! newtype_index {
120120 impl $type {
121121 $v const MAX_AS_U32 : u32 = $max;
122122
123- $v const MAX : $type = $type :: from_u32_const( $max) ;
123+ $v const MAX : Self = Self :: from_u32_const( $max) ;
124124
125125 #[ inline]
126126 $v fn from_usize( value: usize ) -> Self {
127127 assert!( value <= ( $max as usize ) ) ;
128128 unsafe {
129- $type :: from_u32_unchecked( value as u32 )
129+ Self :: from_u32_unchecked( value as u32 )
130130 }
131131 }
132132
133133 #[ inline]
134134 $v fn from_u32( value: u32 ) -> Self {
135135 assert!( value <= $max) ;
136136 unsafe {
137- $type :: from_u32_unchecked( value)
137+ Self :: from_u32_unchecked( value)
138138 }
139139 }
140140
@@ -152,13 +152,13 @@ macro_rules! newtype_index {
152152 ] ;
153153
154154 unsafe {
155- $type { private: value }
155+ Self { private: value }
156156 }
157157 }
158158
159159 #[ inline]
160160 $v const unsafe fn from_u32_unchecked( value: u32 ) -> Self {
161- $type { private: value }
161+ Self { private: value }
162162 }
163163
164164 /// Extracts the value of this index as an integer.
@@ -184,14 +184,14 @@ macro_rules! newtype_index {
184184 type Output = Self ;
185185
186186 fn add( self , other: usize ) -> Self {
187- Self :: new ( self . index( ) + other)
187+ Self :: from_usize ( self . index( ) + other)
188188 }
189189 }
190190
191- impl Idx for $type {
191+ impl $crate :: vec :: Idx for $type {
192192 #[ inline]
193193 fn new( value: usize ) -> Self {
194- Self :: from ( value)
194+ Self :: from_usize ( value)
195195 }
196196
197197 #[ inline]
@@ -204,39 +204,39 @@ macro_rules! newtype_index {
204204 #[ inline]
205205 fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
206206 <usize as :: std:: iter:: Step >:: steps_between(
207- & Idx :: index( * start) ,
208- & Idx :: index( * end) ,
207+ & Self :: index( * start) ,
208+ & Self :: index( * end) ,
209209 )
210210 }
211211
212212 #[ inline]
213213 fn replace_one( & mut self ) -> Self {
214- :: std:: mem:: replace( self , Self :: new ( 1 ) )
214+ :: std:: mem:: replace( self , Self :: from_u32 ( 1 ) )
215215 }
216216
217217 #[ inline]
218218 fn replace_zero( & mut self ) -> Self {
219- :: std:: mem:: replace( self , Self :: new ( 0 ) )
219+ :: std:: mem:: replace( self , Self :: from_u32 ( 0 ) )
220220 }
221221
222222 #[ inline]
223223 fn add_one( & self ) -> Self {
224- Self :: new ( Idx :: index( * self ) + 1 )
224+ Self :: from_usize ( Self :: index( * self ) + 1 )
225225 }
226226
227227 #[ inline]
228228 fn sub_one( & self ) -> Self {
229- Self :: new ( Idx :: index( * self ) - 1 )
229+ Self :: from_usize ( Self :: index( * self ) - 1 )
230230 }
231231
232232 #[ inline]
233233 fn add_usize( & self , u: usize ) -> Option <Self > {
234- Idx :: index( * self ) . checked_add( u) . map( Self :: new )
234+ Self :: index( * self ) . checked_add( u) . map( Self :: from_usize )
235235 }
236236
237237 #[ inline]
238238 fn sub_usize( & self , u: usize ) -> Option <Self > {
239- Idx :: index( * self ) . checked_sub( u) . map( Self :: new )
239+ Self :: index( * self ) . checked_sub( u) . map( Self :: from_usize )
240240 }
241241 }
242242
@@ -257,14 +257,14 @@ macro_rules! newtype_index {
257257 impl From <usize > for $type {
258258 #[ inline]
259259 fn from( value: usize ) -> Self {
260- $type :: from_usize( value)
260+ Self :: from_usize( value)
261261 }
262262 }
263263
264264 impl From <u32 > for $type {
265265 #[ inline]
266266 fn from( value: u32 ) -> Self {
267- $type :: from_u32( value)
267+ Self :: from_u32( value)
268268 }
269269 }
270270
@@ -409,7 +409,7 @@ macro_rules! newtype_index {
409409 ( @decodable $type: ident) => (
410410 impl :: rustc_serialize:: Decodable for $type {
411411 fn decode<D : :: rustc_serialize:: Decoder >( d: & mut D ) -> Result <Self , D :: Error > {
412- d. read_u32( ) . map( Self :: from )
412+ d. read_u32( ) . map( Self :: from_u32 )
413413 }
414414 }
415415 ) ;
@@ -500,7 +500,7 @@ macro_rules! newtype_index {
500500 const $name: ident = $constant: expr,
501501 $( $tokens: tt) * ) => (
502502 $( #[ doc = $doc] ) *
503- pub const $name: $type = $type:: from_u32_const( $constant) ;
503+ $v const $name: $type = $type:: from_u32_const( $constant) ;
504504 $crate:: newtype_index!(
505505 @derives [ $( $derives, ) * ]
506506 @attrs [ $( #[ $attrs] ) * ]
@@ -839,3 +839,6 @@ impl<I: Idx> FnMut<(usize,)> for IntoIdx<I> {
839839 I :: new ( n)
840840 }
841841}
842+
843+ #[ cfg( test) ]
844+ mod tests;
0 commit comments