Skip to content

Commit d3c831b

Browse files
committed
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.
1 parent 8801d89 commit d3c831b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/libstd/macros.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ macro_rules! assert(
117117
#[macro_export]
118118
macro_rules! assert_eq(
119119
($given:expr , $expected:expr) => ({
120-
let given_val = &($given);
121-
let expected_val = &($expected);
122-
// check both directions of equality....
123-
if !((*given_val == *expected_val) &&
124-
(*expected_val == *given_val)) {
125-
fail!("assertion failed: `(left == right) && (right == left)` \
126-
(left: `{}`, right: `{}`)", *given_val, *expected_val)
120+
match (&($given), &($expected)) {
121+
(given_val, expected_val) => {
122+
// check both directions of equality....
123+
if !((*given_val == *expected_val) &&
124+
(*expected_val == *given_val)) {
125+
fail!("assertion failed: `(left == right) && (right == left)` \
126+
(left: `{}`, right: `{}`)", *given_val, *expected_val)
127+
}
128+
}
127129
}
128130
})
129131
)

0 commit comments

Comments
 (0)