about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-07-01 03:35:46 +0000
committerbors <bors@rust-lang.org>2015-07-01 03:35:46 +0000
commit1fc0f685488ecf7590cfd85ffc67d5904d912d43 (patch)
tree33e13af58ae5230c7077510856332db3f480535c /src/libcore
parentbf3c979ec31300e38c1607d605cf47f231bf6480 (diff)
parent98566ea951fec6d359e2d98367d34c06e2243ee2 (diff)
downloadrust-1fc0f685488ecf7590cfd85ffc67d5904d912d43.tar.gz
rust-1fc0f685488ecf7590cfd85ffc67d5904d912d43.zip
Auto merge of #26698 - alexcrichton:char-fmt, r=huonw
This recently regressed in #24689, and this updates the `Display` implementation
to take formatting flags into account.

Closes #26625
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/fmt/mod.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index 35dea6d15f0..f735ed7b78b 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -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)
+        }
     }
 }