diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-07 22:32:49 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-09 09:57:49 +1000 |
| commit | d3c831ba4a4a2284f73e4f9147aa4900cab56815 (patch) | |
| tree | bfd1846f8959003af8cec15f0275bebe62750221 /src/libstd/macros.rs | |
| parent | 8801d891c4674f335fcdc67cb34237902d89a5ec (diff) | |
| download | rust-d3c831ba4a4a2284f73e4f9147aa4900cab56815.tar.gz rust-d3c831ba4a4a2284f73e4f9147aa4900cab56815.zip | |
std: use a `match` in `assert_eq!` to extend the lifetime of the args.
This enables
assert_eq!(foo.collect::<Vec<...>>().as_slice(), &[1,2,3,4]);
to work, by extending the lifetime of the .as_slice() rvalue.
Diffstat (limited to 'src/libstd/macros.rs')
| -rw-r--r-- | src/libstd/macros.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index fbb48f2ebcb..9d06e38dd8e 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -117,13 +117,15 @@ macro_rules! assert( #[macro_export] macro_rules! assert_eq( ($given:expr , $expected:expr) => ({ - let given_val = &($given); - let expected_val = &($expected); - // check both directions of equality.... - if !((*given_val == *expected_val) && - (*expected_val == *given_val)) { - fail!("assertion failed: `(left == right) && (right == left)` \ - (left: `{}`, right: `{}`)", *given_val, *expected_val) + match (&($given), &($expected)) { + (given_val, expected_val) => { + // check both directions of equality.... + if !((*given_val == *expected_val) && + (*expected_val == *given_val)) { + fail!("assertion failed: `(left == right) && (right == left)` \ + (left: `{}`, right: `{}`)", *given_val, *expected_val) + } + } } }) ) |
