You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot tell apart panic!() and assert!(false, "") in macro_backtrace() #82157
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Used to result in distinct macro_backtrace(). After updating to nightly-2021-02-14 (and I guess since #80851), the backtrace for both is identical, both listing the calls ["std::panic::panic_2015", "std::panic"].
IIUC, the latter should contain an additional core::assert or std::assert item in the backtrace.
Agreed as of rustc 1.96.1 (31fca3a 2026-06-26) the backtrace for panic! and assert! is very hard (if not impossible) to tell apart but isn't that what the "msg" in assert!(expr, "msg") is for? So suggestions to close this issue:
Just close it, assuming people who need to highlight the assertion failure will add an appropriate message
Or add a default message to assert!(expr) so it acts like assert!(expr, "Assert failed!") (we can discuss actual default message), this will highlight for those who forget to add their own message.
Or add the default message (when required) then call std::assert(expr: bool, msg: &str) which can then print the message and panic if expr is false. (This may not be the best way to do this maybe deal with expr in the macro before calling assert). This inserts the call to std:assert into the backtrace of course, which was the original requirement,
Note that the context for the requirement is in program verification. A tool (in our case Prusti) will look through the program (mostly the MIR), figuring out which assertions can be violated. When reporting a verification error at a panic!(...) vs at an assert!(...) we want to report something else to the user -- "panic statement might be reachable" vs "assertion might not hold", respectively.
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
jyn514 commentedon Feb 16, 2021
@Aurel300 what do you mean by
macro_backtrace? I can't find it in the docs for the standard library.jyn514 commentedon Feb 16, 2021
Do you mean https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/span_encoding/struct.Span.html#method.macro_backtrace?
AureaNoire commentedon Feb 16, 2021
@jyn514 Yep, sorry, I should have linked to it. Yes, it is the
Span::macro_backtraceyou linked.jyn514 commentedon Feb 16, 2021
cc @m-ou-se
RodBurman commentedon Jul 7, 2026
Agreed as of rustc 1.96.1 (31fca3a 2026-06-26) the backtrace for panic! and assert! is very hard (if not impossible) to tell apart but isn't that what the "msg" in assert!(expr, "msg") is for? So suggestions to close this issue:
AureaNoire commentedon Jul 15, 2026
Note that the context for the requirement is in program verification. A tool (in our case Prusti) will look through the program (mostly the MIR), figuring out which assertions can be violated. When reporting a verification error at a
panic!(...)vs at anassert!(...)we want to report something else to the user -- "panic statement might be reachable" vs "assertion might not hold", respectively.