@@ -40,9 +40,18 @@ pub struct PhysAddr(u64);
40
40
/// a valid sign extension and are not null either. So automatic sign extension would have
41
41
/// overwritten possibly meaningful bits. This likely indicates a bug, for example an invalid
42
42
/// address calculation.
43
- #[ derive( Debug ) ]
43
+ ///
44
+ /// Contains the invalid address.
44
45
pub struct VirtAddrNotValid ( pub u64 ) ;
45
46
47
+ impl core:: fmt:: Debug for VirtAddrNotValid {
48
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
49
+ f. debug_tuple ( "VirtAddrNotValid" )
50
+ . field ( & format_args ! ( "{:#x}" , self . 0 ) )
51
+ . finish ( )
52
+ }
53
+ }
54
+
46
55
impl VirtAddr {
47
56
/// Creates a new canonical virtual address.
48
57
///
@@ -70,7 +79,7 @@ impl VirtAddr {
70
79
match addr. get_bits ( 47 ..64 ) {
71
80
0 | 0x1ffff => Ok ( VirtAddr ( addr) ) , // address is canonical
72
81
1 => Ok ( VirtAddr :: new_truncate ( addr) ) , // address needs sign extension
73
- other => Err ( VirtAddrNotValid ( other ) ) ,
82
+ _ => Err ( VirtAddrNotValid ( addr ) ) ,
74
83
}
75
84
}
76
85
@@ -325,9 +334,18 @@ impl Sub<VirtAddr> for VirtAddr {
325
334
/// A passed `u64` was not a valid physical address.
326
335
///
327
336
/// This means that bits 52 to 64 were not all null.
328
- #[ derive( Debug ) ]
337
+ ///
338
+ /// Contains the invalid address.
329
339
pub struct PhysAddrNotValid ( pub u64 ) ;
330
340
341
+ impl core:: fmt:: Debug for PhysAddrNotValid {
342
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
343
+ f. debug_tuple ( "PhysAddrNotValid" )
344
+ . field ( & format_args ! ( "{:#x}" , self . 0 ) )
345
+ . finish ( )
346
+ }
347
+ }
348
+
331
349
impl PhysAddr {
332
350
/// Creates a new physical address.
333
351
///
@@ -367,7 +385,7 @@ impl PhysAddr {
367
385
pub fn try_new ( addr : u64 ) -> Result < PhysAddr , PhysAddrNotValid > {
368
386
match addr. get_bits ( 52 ..64 ) {
369
387
0 => Ok ( PhysAddr ( addr) ) , // address is valid
370
- other => Err ( PhysAddrNotValid ( other ) ) ,
388
+ _ => Err ( PhysAddrNotValid ( addr ) ) ,
371
389
}
372
390
}
373
391
0 commit comments