-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve assert_eq
message
#73968
Improve assert_eq
message
#73968
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
I am afraid that the current impl may cause a pretty noticable slowdown + binary bloat. While I agree that the better error messages are nice, we really should do a perf run before landing this. |
If you want to check out the difference (it is not that huge, but you have to consider how often https://rust.godbolt.org/z/zUc6wc edit: Something like this may still give most of the benefit without a big perf impact, will still slightly increase binary sizes though... ($left:expr, $right:expr) => ({
match (&$left, &$right) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
panic!(concat!(r#"assertion failed: `(", stringify!($left), ") == (", stringify!($right), ")`",
left: `{:?}`,
right: `{:?}`"#), &*left_val, &*right_val)
}
}
}
}); |
What happens if the line is very long? Let's say assert_eq!(
"the quick brown fox jumps over the lazy dog.",
"The wizard quickly jinxed the gnomes before they vaporized."
); Won't the error message be too long? Do we need some kind of truncation here? Also, I find it quite redundant to have |
They are several things here that can be noticed:
Maybe we should do some benchmarks ?
I tested that too, but there where issues because
IMHO truncating the message would be more confusing than helpful.
We could match on literals to print them differently. It would complicate the macro, though. |
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 4105abb with merge f28fc8b1abbb9968879d04458b6fa25b74a7ba89... |
@a1phyr In any case, can we keep the original
The original reason is to improve debugging experience, it would just be as weird for developer (me personally) to suddenly see |
☀️ Try build successful - checks-actions, checks-azure |
Queued f28fc8b1abbb9968879d04458b6fa25b74a7ba89 with parent f844ea1, future comparison URL. |
I wonder if we could have the nicer messages if debug assertions are on and the existing assertions otherwise? |
Does not seem clearer to me either. left/right are a fine convention for the current version. I would appreciate better assertion failure messages but I would rather have the ability to provide my own context for my assertion failure rather than this, because this is very much in the field of "a tool trying to guess what the user wants rather than letting the user say exactly what". |
Finished benchmarking try commit (f28fc8b1abbb9968879d04458b6fa25b74a7ba89): comparison url. |
Given the terrible benchmark results, I think we can close this anyway. |
Thanks anyway @a1phyr! I run into this sort of problem every once in a while... |
Improve error message for
assert_eq
andassert_ne
macros, by printing the expressions instead ofleft
andright
.Example:
now gives
instead of
This may greatly improve debugging experience.