From 02882fbd7edcb8d0d152afcdc8571216efcbd664 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 28 Feb 2014 01:23:06 -0800 Subject: 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. --- src/doc/guide-container.md | 2 +- src/doc/tutorial.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/doc') diff --git a/src/doc/guide-container.md b/src/doc/guide-container.md index 543b77ccdb9..dbf8c6512d4 100644 --- a/src/doc/guide-container.md +++ b/src/doc/guide-container.md @@ -384,7 +384,7 @@ the trailing underscore is a workaround for issue #5898 and will be removed. ~~~ let mut ys = [1, 2, 3, 4, 5]; ys.mut_iter().reverse_(); -assert_eq!(ys, [5, 4, 3, 2, 1]); +assert!(ys == [5, 4, 3, 2, 1]); ~~~ ## Random-access iterators diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 339e5552d7f..d6ef241b458 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -1688,7 +1688,7 @@ let x = Rc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); let y = x.clone(); // a new owner let z = x; // this moves `x` into `z`, rather than creating a new owner -assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); +assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // the variable is mutable, but not the contents of the box let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); @@ -1707,7 +1707,7 @@ let x = Gc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); let y = x; // does not perform a move, unlike with `Rc` let z = x; -assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); +assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); ~~~ With shared ownership, mutability cannot be inherited so the boxes are always immutable. However, -- cgit 1.4.1-3-g733a5