@@ -88,14 +88,19 @@ impl VirtAddr {
88
88
}
89
89
90
90
/// Creates a virtual address from the given pointer
91
+ // cfg(target_pointer_width = "32") is only here for backwards
92
+ // compatibility: Earlier versions of this crate did not have any `cfg()`
93
+ // on this function. At least for 32- and 64-bit we know the `as u64` cast
94
+ // doesn't truncate.
95
+ #[ cfg( any( target_pointer_width = "32" , target_pointer_width = "64" ) ) ]
91
96
pub fn from_ptr < T > ( ptr : * const T ) -> Self {
92
- Self :: new ( cast :: u64 ( ptr as usize ) )
97
+ Self :: new ( ptr as u64 )
93
98
}
94
99
95
100
/// Converts the address to a raw pointer.
96
101
#[ cfg( target_pointer_width = "64" ) ]
97
102
pub fn as_ptr < T > ( self ) -> * const T {
98
- cast :: usize ( self . as_u64 ( ) ) as * const T
103
+ self . as_u64 ( ) as * const T
99
104
}
100
105
101
106
/// Converts the address to a mutable raw pointer.
@@ -181,14 +186,14 @@ impl AddAssign<u64> for VirtAddr {
181
186
impl Add < usize > for VirtAddr {
182
187
type Output = Self ;
183
188
fn add ( self , rhs : usize ) -> Self :: Output {
184
- self + cast :: u64 ( rhs)
189
+ self + rhs as u64
185
190
}
186
191
}
187
192
188
193
#[ cfg( target_pointer_width = "64" ) ]
189
194
impl AddAssign < usize > for VirtAddr {
190
195
fn add_assign ( & mut self , rhs : usize ) {
191
- self . add_assign ( cast :: u64 ( rhs) )
196
+ self . add_assign ( rhs as u64 )
192
197
}
193
198
}
194
199
@@ -209,14 +214,14 @@ impl SubAssign<u64> for VirtAddr {
209
214
impl Sub < usize > for VirtAddr {
210
215
type Output = Self ;
211
216
fn sub ( self , rhs : usize ) -> Self :: Output {
212
- self - cast :: u64 ( rhs)
217
+ self - rhs as u64
213
218
}
214
219
}
215
220
216
221
#[ cfg( target_pointer_width = "64" ) ]
217
222
impl SubAssign < usize > for VirtAddr {
218
223
fn sub_assign ( & mut self , rhs : usize ) {
219
- self . sub_assign ( cast :: u64 ( rhs) )
224
+ self . sub_assign ( rhs as u64 )
220
225
}
221
226
}
222
227
@@ -347,14 +352,14 @@ impl AddAssign<u64> for PhysAddr {
347
352
impl Add < usize > for PhysAddr {
348
353
type Output = Self ;
349
354
fn add ( self , rhs : usize ) -> Self :: Output {
350
- self + cast :: u64 ( rhs)
355
+ self + rhs as u64
351
356
}
352
357
}
353
358
354
359
#[ cfg( target_pointer_width = "64" ) ]
355
360
impl AddAssign < usize > for PhysAddr {
356
361
fn add_assign ( & mut self , rhs : usize ) {
357
- self . add_assign ( cast :: u64 ( rhs) )
362
+ self . add_assign ( rhs as u64 )
358
363
}
359
364
}
360
365
@@ -375,14 +380,14 @@ impl SubAssign<u64> for PhysAddr {
375
380
impl Sub < usize > for PhysAddr {
376
381
type Output = Self ;
377
382
fn sub ( self , rhs : usize ) -> Self :: Output {
378
- self - cast :: u64 ( rhs)
383
+ self - rhs as u64
379
384
}
380
385
}
381
386
382
387
#[ cfg( target_pointer_width = "64" ) ]
383
388
impl SubAssign < usize > for PhysAddr {
384
389
fn sub_assign ( & mut self , rhs : usize ) {
385
- self . sub_assign ( cast :: u64 ( rhs) )
390
+ self . sub_assign ( rhs as u64 )
386
391
}
387
392
}
388
393
0 commit comments