Skip to content

Commit e22ddfd

Browse files
committed
Don't print leading zeros on hex dumps constants
1 parent 4ddb4bd commit e22ddfd

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,7 @@ pub trait PrettyPrinter<'tcx>:
982982
p!(write("{{null reference to "), print(ty), write("}}"))
983983
}
984984
(Scalar::Raw { data, .. }, ty::Ref(..)) | (Scalar::Raw { data, .. }, ty::RawPtr(_)) => {
985-
let pointer_width = self.tcx().data_layout.pointer_size.bytes();
986-
p!(write("0x{:01$x}", data, pointer_width as usize * 2))
985+
p!(write("0x{:x}", data))
987986
}
988987
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
989988
let instance = {
@@ -995,9 +994,9 @@ pub trait PrettyPrinter<'tcx>:
995994
// For zsts just print their type as their value gives no extra information
996995
(Scalar::Raw { size: 0, .. }, _) => p!(print(ty)),
997996
// Nontrivial types with scalar bit representation
998-
(Scalar::Raw { data, size }, _) => {
997+
(Scalar::Raw { data, .. }, _) => {
999998
let print = |mut this: Self| {
1000-
write!(this, "0x{:01$x}", data, size as usize * 2)?;
999+
write!(this, "transmute(0x{:x})", data)?;
10011000
Ok(this)
10021001
};
10031002
self = if print_ty {

src/test/mir-opt/const_prop/discriminant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
// START rustc.main.ConstProp.after.mir
3232
// bb0: {
3333
// ...
34-
// _3 = const {0x01: std::option::Option<bool>};
34+
// _3 = const {transmute(0x1): std::option::Option<bool>};
3535
// _4 = const 1isize;
3636
// switchInt(const 1isize) -> [1isize: bb2, otherwise: bb1];
3737
// }

src/test/mir-opt/simplify-locals-removes-unused-consts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// compile-flags: -C overflow-checks=no
22

3-
fn use_zst(_: ((), ())) { }
3+
fn use_zst(_: ((), ())) {}
44

55
struct Temp {
6-
x: u8
6+
x: u8,
77
}
88

9-
fn use_u8(_: u8) { }
9+
fn use_u8(_: u8) {}
1010

1111
fn main() {
1212
let ((), ()) = ((), ());
1313
use_zst(((), ()));
1414

15-
use_u8((Temp { x : 40 }).x + 2);
15+
use_u8((Temp { x: 40 }).x + 2);
1616
}
1717

1818
// END RUST SOURCE
@@ -56,7 +56,7 @@ fn main() {
5656
// StorageLive(_8);
5757
// StorageLive(_10);
5858
// StorageLive(_11);
59-
// _11 = const {0x28 : Temp};
59+
// _11 = const {transmute(0x28) : Temp};
6060
// _10 = const 40u8;
6161
// StorageDead(_10);
6262
// _8 = const use_u8(const 42u8) -> bb2;
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// normalize-stderr-64bit "0x00000000" -> "0x[PREFIX]"
2-
// normalize-stderr-32bit "0x" -> "0x[PREFIX]"
3-
41
#![feature(const_generics, const_compare_raw_pointers)]
52
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
63

74
struct Const<const P: *const u32>;
85

96
fn main() {
10-
let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; //~ mismatched types
11-
let _: Const<{10 as *const _}> = Const::<{10 as *const _}>;
7+
let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; //~ mismatched types
8+
let _: Const<{ 10 as *const _ }> = Const::<{ 10 as *const _ }>;
129
}

src/test/ui/const-generics/raw-ptr-const-param.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/raw-ptr-const-param.rs:4:12
2+
--> $DIR/raw-ptr-const-param.rs:1:12
33
|
44
LL | #![feature(const_generics, const_compare_raw_pointers)]
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

99
error[E0308]: mismatched types
10-
--> $DIR/raw-ptr-const-param.rs:10:38
10+
--> $DIR/raw-ptr-const-param.rs:7:40
1111
|
12-
LL | let _: Const<{15 as *const _}> = Const::<{10 as *const _}>;
13-
| ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0x[PREFIX]0000000f`, found `0x[PREFIX]0000000a`
12+
LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>;
13+
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0xf`, found `0xa`
1414
| |
1515
| expected due to this
1616
|
17-
= note: expected struct `Const<0x[PREFIX]0000000f>`
18-
found struct `Const<0x[PREFIX]0000000a>`
17+
= note: expected struct `Const<0xf>`
18+
found struct `Const<0xa>`
1919

2020
error: aborting due to previous error
2121

0 commit comments

Comments
 (0)