std: Change assert_eq!() to use {} instead of {:?}
Formatting via reflection has been a little questionable for some time now, and
it's a little unfortunate that one of the standard macros will silently use
reflection when you weren't expecting it. This adds small bits of code bloat to
libraries, as well as not always being necessary. In light of this information,
this commit switches assert_eq!() to using {} in the error message instead of
{:?}.
In updating existing code, there were a few error cases that I encountered:
* It's impossible to define Show for [T, ..N]. I think DST will alleviate this
because we can define Show for [T].
* A few types here and there just needed a #[deriving(Show)]
* Type parameters needed a Show bound, I often moved this to `assert!(a == b)`
* `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths.
I don't think this is much of a regression though because {:?} on paths looks
awful (it's a byte array).
Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime
significant for smaller binaries.
This commit is contained in:
parent
123eb4ebea
commit
02882fbd7e
97 changed files with 354 additions and 301 deletions
|
|
@ -64,7 +64,7 @@ mod imp {
|
|||
/// A record specifying a time value in seconds and nanoseconds.
|
||||
|
||||
|
||||
#[deriving(Clone, DeepClone, Eq, Encodable, Decodable)]
|
||||
#[deriving(Clone, DeepClone, Eq, Encodable, Decodable, Show)]
|
||||
pub struct Timespec { sec: i64, nsec: i32 }
|
||||
/*
|
||||
* Timespec assumes that pre-epoch Timespecs have negative sec and positive
|
||||
|
|
@ -191,7 +191,7 @@ pub fn tzset() {
|
|||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, DeepClone, Eq, Encodable, Decodable)]
|
||||
#[deriving(Clone, DeepClone, Eq, Encodable, Decodable, Show)]
|
||||
pub struct Tm {
|
||||
tm_sec: i32, // seconds after the minute ~[0-60]
|
||||
tm_min: i32, // minutes after the hour ~[0-59]
|
||||
|
|
@ -1138,7 +1138,7 @@ mod tests {
|
|||
let time = Timespec::new(1234567890, 54321);
|
||||
let local = at(time);
|
||||
|
||||
error!("time_at: {:?}", local);
|
||||
debug!("time_at: {:?}", local);
|
||||
|
||||
assert_eq!(local.tm_sec, 30_i32);
|
||||
assert_eq!(local.tm_min, 31_i32);
|
||||
|
|
@ -1355,7 +1355,7 @@ mod tests {
|
|||
let utc = at_utc(time);
|
||||
let local = at(time);
|
||||
|
||||
error!("test_ctime: {:?} {:?}", utc.ctime(), local.ctime());
|
||||
debug!("test_ctime: {:?} {:?}", utc.ctime(), local.ctime());
|
||||
|
||||
assert_eq!(utc.ctime(), ~"Fri Feb 13 23:31:30 2009");
|
||||
assert_eq!(local.ctime(), ~"Fri Feb 13 15:31:30 2009");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue