diff options
| author | bors <bors@rust-lang.org> | 2015-07-01 03:35:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-01 03:35:46 +0000 |
| commit | 1fc0f685488ecf7590cfd85ffc67d5904d912d43 (patch) | |
| tree | 33e13af58ae5230c7077510856332db3f480535c /src | |
| parent | bf3c979ec31300e38c1607d605cf47f231bf6480 (diff) | |
| parent | 98566ea951fec6d359e2d98367d34c06e2243ee2 (diff) | |
| download | rust-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')
| -rw-r--r-- | src/libcore/fmt/mod.rs | 9 | ||||
| -rw-r--r-- | src/libcoretest/fmt/mod.rs | 2 |
2 files changed, 10 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) + } } } diff --git a/src/libcoretest/fmt/mod.rs b/src/libcoretest/fmt/mod.rs index cdb9c38f027..42872589bb0 100644 --- a/src/libcoretest/fmt/mod.rs +++ b/src/libcoretest/fmt/mod.rs @@ -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"); } |
