Skip to content

Commit 1456b85

Browse files
committed
Rollup merge of #22901 - thepowersgang:patch-1, r=eddyb
A misplaced uint->u32 instead of usize in fmt::Pointer. Added a basic test.
2 parents 5ec9938 + c22d026 commit 1456b85

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/libcore/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ impl Display for char {
700700
impl<T> Pointer for *const T {
701701
fn fmt(&self, f: &mut Formatter) -> Result {
702702
f.flags |= 1 << (FlagV1::Alternate as u32);
703-
let ret = LowerHex::fmt(&(*self as u32), f);
703+
let ret = LowerHex::fmt(&(*self as usize), f);
704704
f.flags &= !(1 << (FlagV1::Alternate as u32));
705705
ret
706706
}

src/test/run-pass/ifmt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ pub fn main() {
137137
t!(format!("{:+10.3e}", 1.2345e6f64), " +1.234e6");
138138
t!(format!("{:+10.3e}", -1.2345e6f64), " -1.234e6");
139139

140+
// Test that pointers don't get truncated.
141+
{
142+
let val = usize::MAX;
143+
let exp = format!("{:#x}", val);
144+
t!(format!("{:p}", val as *const isize), exp);
145+
}
146+
140147
// Escaping
141148
t!(format!("{{"), "{");
142149
t!(format!("}}"), "}");

0 commit comments

Comments
 (0)