Auto merge of - alexcrichton:char-fmt, r=huonw

This recently regressed in , and this updates the `Display` implementation
to take formatting flags into account.

Closes 
This commit is contained in:
bors 2015-07-01 03:35:46 +00:00
commit 1fc0f68548
2 changed files with 10 additions and 1 deletions
src
libcore/fmt
libcoretest/fmt

@ -983,7 +983,14 @@ impl Debug for char {
#[stable(feature = "rust1", since = "1.0.0")]
impl Display for char {
fn fmt(&self, f: &mut Formatter) -> Result {
f.write_char(*self)
if f.width.is_none() && f.precision.is_none() {
f.write_char(*self)
} else {
let mut utf8 = [0; 4];
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
let s: &str = unsafe { mem::transmute(&utf8[..amt]) };
f.pad(s)
}
}
}

@ -16,4 +16,6 @@ fn test_format_flags() {
// No residual flags left by pointer formatting
let p = "".as_ptr();
assert_eq!(format!("{:p} {:x}", p, 16), format!("{:p} 10", p));
assert_eq!(format!("{: >3}", 'a'), " a");
}