Skip to content

Commit 1de4b65

Browse files
committed
Updates with core::fmt changes
1. Wherever the `buf` field of a `Formatter` was used, the `Formatter` is used instead. 2. The usage of `write_fmt` is minimized as much as possible, the `write!` macro is preferred wherever possible. 3. Usage of `fmt::write` is minimized, favoring the `write!` macro instead.
1 parent 8767093 commit 1de4b65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+275
-291
lines changed

src/libcollections/btree.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ impl<K: fmt::Show + TotalOrd, V: fmt::Show> fmt::Show for Leaf<K, V> {
425425
///Returns a string representation of a Leaf.
426426
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
427427
for (i, s) in self.elts.iter().enumerate() {
428-
if i != 0 { try!(write!(f.buf, " // ")) }
429-
try!(write!(f.buf, "{}", *s))
428+
if i != 0 { try!(write!(f, " // ")) }
429+
try!(write!(f, "{}", *s))
430430
}
431431
Ok(())
432432
}
@@ -654,10 +654,10 @@ impl<K: fmt::Show + TotalOrd, V: fmt::Show> fmt::Show for Branch<K, V> {
654654
///Returns a string representation of a Branch.
655655
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
656656
for (i, s) in self.elts.iter().enumerate() {
657-
if i != 0 { try!(write!(f.buf, " // ")) }
658-
try!(write!(f.buf, "{}", *s))
657+
if i != 0 { try!(write!(f, " // ")) }
658+
try!(write!(f, "{}", *s))
659659
}
660-
write!(f.buf, " // rightmost child: ({}) ", *self.rightmost_child)
660+
write!(f, " // rightmost child: ({}) ", *self.rightmost_child)
661661
}
662662
}
663663

@@ -715,7 +715,7 @@ impl<K: TotalOrd, V: TotalEq> TotalOrd for LeafElt<K, V> {
715715
impl<K: fmt::Show + TotalOrd, V: fmt::Show> fmt::Show for LeafElt<K, V> {
716716
///Returns a string representation of a LeafElt.
717717
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
718-
write!(f.buf, "Key: {}, value: {};", self.key, self.value)
718+
write!(f, "Key: {}, value: {};", self.key, self.value)
719719
}
720720
}
721721

@@ -765,7 +765,7 @@ impl<K: fmt::Show + TotalOrd, V: fmt::Show> fmt::Show for BranchElt<K, V> {
765765
/// Returns string containing key, value, and child (which should recur to a
766766
/// leaf) Consider changing in future to be more readable.
767767
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
768-
write!(f.buf, "Key: {}, value: {}, (child: {})",
768+
write!(f, "Key: {}, value: {}, (child: {})",
769769
self.key, self.value, *self.left)
770770
}
771771
}

src/libcollections/hashmap.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,14 +1418,14 @@ impl<K: TotalEq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {
14181418

14191419
impl<K: TotalEq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H> {
14201420
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1421-
try!(write!(f.buf, r"\{"));
1421+
try!(write!(f, r"\{"));
14221422

14231423
for (i, (k, v)) in self.iter().enumerate() {
1424-
if i != 0 { try!(write!(f.buf, ", ")); }
1425-
try!(write!(f.buf, "{}: {}", *k, *v));
1424+
if i != 0 { try!(write!(f, ", ")); }
1425+
try!(write!(f, "{}: {}", *k, *v));
14261426
}
14271427

1428-
write!(f.buf, r"\}")
1428+
write!(f, r"\}")
14291429
}
14301430
}
14311431

@@ -1605,14 +1605,14 @@ impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
16051605

16061606
impl<T: TotalEq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
16071607
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1608-
try!(write!(f.buf, r"\{"));
1608+
try!(write!(f, r"\{"));
16091609

16101610
for (i, x) in self.iter().enumerate() {
1611-
if i != 0 { try!(write!(f.buf, ", ")); }
1612-
try!(write!(f.buf, "{}", *x));
1611+
if i != 0 { try!(write!(f, ", ")); }
1612+
try!(write!(f, "{}", *x));
16131613
}
16141614

1615-
write!(f.buf, r"\}")
1615+
write!(f, r"\}")
16161616
}
16171617
}
16181618

src/libcollections/lru_cache.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,20 @@ impl<A: fmt::Show + Hash + TotalEq, B: fmt::Show> fmt::Show for LruCache<A, B> {
205205
/// Return a string that lists the key-value pairs from most-recently
206206
/// used to least-recently used.
207207
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
208-
try!(write!(f.buf, r"\{"));
208+
try!(write!(f, r"\{"));
209209
let mut cur = self.head;
210210
for i in range(0, self.len()) {
211-
if i > 0 { try!(write!(f.buf, ", ")) }
211+
if i > 0 { try!(write!(f, ", ")) }
212212
unsafe {
213213
cur = (*cur).next;
214-
try!(write!(f.buf, "{}", (*cur).key));
214+
try!(write!(f, "{}", (*cur).key));
215215
}
216-
try!(write!(f.buf, ": "));
216+
try!(write!(f, ": "));
217217
unsafe {
218-
try!(write!(f.buf, "{}", (*cur).value));
218+
try!(write!(f, "{}", (*cur).value));
219219
}
220220
}
221-
write!(f.buf, r"\}")
221+
write!(f, r"\}")
222222
}
223223
}
224224

src/libcore/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub use iter::{FromIterator, Extendable};
3535
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
3636
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
3737
pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
38-
pub use num::{Signed, Unsigned};
38+
pub use num::{Signed, Unsigned, Float};
3939
pub use num::{Primitive, Int, ToPrimitive, FromPrimitive};
4040
pub use ptr::RawPtr;
4141
pub use str::{Str, StrSlice};

src/libgreen/macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ macro_rules! rtabort (
5151
)
5252

5353
pub fn dumb_println(args: &fmt::Arguments) {
54-
use std::io;
5554
use std::rt;
56-
5755
let mut w = rt::Stderr;
58-
let _ = fmt::writeln(&mut w as &mut io::Writer, args);
56+
let _ = writeln!(&mut w, "{}", args);
5957
}
6058

6159
pub fn abort(msg: &str) -> ! {

src/liblog/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl fmt::Show for LogLevel {
188188
impl fmt::Signed for LogLevel {
189189
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
190190
let LogLevel(level) = *self;
191-
write!(fmt.buf, "{}", level)
191+
write!(fmt, "{}", level)
192192
}
193193
}
194194

src/libnum/bigint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Default for BigUint {
120120

121121
impl fmt::Show for BigUint {
122122
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
123-
write!(f.buf, "{}", self.to_str_radix(10))
123+
write!(f, "{}", self.to_str_radix(10))
124124
}
125125
}
126126

@@ -843,7 +843,7 @@ impl Default for BigInt {
843843

844844
impl fmt::Show for BigInt {
845845
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
846-
write!(f.buf, "{}", self.to_str_radix(10))
846+
write!(f, "{}", self.to_str_radix(10))
847847
}
848848
}
849849

src/libnum/complex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ impl<T: Clone + Num> One for Complex<T> {
171171
impl<T: fmt::Show + Num + Ord> fmt::Show for Complex<T> {
172172
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
173173
if self.im < Zero::zero() {
174-
write!(f.buf, "{}-{}i", self.re, -self.im)
174+
write!(f, "{}-{}i", self.re, -self.im)
175175
} else {
176-
write!(f.buf, "{}+{}i", self.re, self.im)
176+
write!(f, "{}+{}i", self.re, self.im)
177177
}
178178
}
179179
}

src/libnum/rational.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<T: Clone + Integer + Ord>
276276
impl<T: fmt::Show> fmt::Show for Ratio<T> {
277277
/// Renders as `numer/denom`.
278278
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
279-
write!(f.buf, "{}/{}", self.numer, self.denom)
279+
write!(f, "{}/{}", self.numer, self.denom)
280280
}
281281
}
282282
impl<T: ToStrRadix> ToStrRadix for Ratio<T> {

src/libregex/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Error {
3737

3838
impl fmt::Show for Error {
3939
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40-
write!(f.buf, "Regex syntax error near position {}: {}",
40+
write!(f, "Regex syntax error near position {}: {}",
4141
self.pos, self.msg)
4242
}
4343
}

0 commit comments

Comments
 (0)