mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 03:57:37 +00:00
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.
This commit is contained in:
parent
8801d891c4
commit
d3c831ba4a
@ -117,14 +117,16 @@ macro_rules! assert(
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! assert_eq(
|
macro_rules! assert_eq(
|
||||||
($given:expr , $expected:expr) => ({
|
($given:expr , $expected:expr) => ({
|
||||||
let given_val = &($given);
|
match (&($given), &($expected)) {
|
||||||
let expected_val = &($expected);
|
(given_val, expected_val) => {
|
||||||
// check both directions of equality....
|
// check both directions of equality....
|
||||||
if !((*given_val == *expected_val) &&
|
if !((*given_val == *expected_val) &&
|
||||||
(*expected_val == *given_val)) {
|
(*expected_val == *given_val)) {
|
||||||
fail!("assertion failed: `(left == right) && (right == left)` \
|
fail!("assertion failed: `(left == right) && (right == left)` \
|
||||||
(left: `{}`, right: `{}`)", *given_val, *expected_val)
|
(left: `{}`, right: `{}`)", *given_val, *expected_val)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user