-
Notifications
You must be signed in to change notification settings - Fork 13.3k
allow attaching strings to assert messages #2761
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
Comments
I like the macro idea. The error message could be optional. At that point we could remove |
whoa, are you sure it's a good idea to have people write "!condition" to mean "condition must hold"? c.c |
I did think it was a good idea, but it is clearly not. |
I think we can already write this with the existing macro system. Does this work?
|
It should still also print the file and line number, and ideally also the containing function, in either case (with message or not). (this is me being demanding without knowing how to do macros on my own.) Oh yeah, also the macro hygiene issue. It should be wrapped in whatever rust's equivalent of C's "do { .. } while (0)" is. |
This does most of what you want. Unfortunately, it shows you the line number where the macro was defined, rather than where the macro was invoked. There's a case to be made that this is wrong behavior for
|
This macro has been added to Servo, btw. I was looking for an NS_ASSERT equivalent. |
A great C idiom is:
In rust, I keep writing:
I'd be pretty happy with an #assert macro that took a condition and a failure message and generated appropriate code (easy), or perhaps changing the grammar of assert itself (less feasible).
The text was updated successfully, but these errors were encountered: