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
const functions can assert! but cannot assert_eq! #119826
I believe this is due to the fact that assert_eq (and other assert_* macros) end up calling core::panicking::assert_fail_inner. Which in turn uses formatting macros (println! with a {:?} placeholder) that are currently not usable in a const context which is known but I couldn't find any issue tracking progress on this front.
Yeah, I think this is blocked on const traits. assert_eq! can only be used when the Debug impls or the tail are guaranteed to work in const, and we don't have any way to express that yet.
We don't need hacks, we can start marking Debug as const_trait and making impls const as we go. Then we need to figure out how to make more Formatter methods const
Activity
krtab commentedon Jan 11, 2024
Hi!
I believe this is due to the fact that
assert_eq(and otherassert_*macros) end up calling core::panicking::assert_fail_inner. Which in turn uses formatting macros (println!with a{:?}placeholder) that are currently not usable in a const context which is known but I couldn't find any issue tracking progress on this front.saethlin commentedon Jan 27, 2024
Yeah, I think this is blocked on const traits.
assert_eq!can only be used when theDebugimpls or the tail are guaranteed to work in const, and we don't have any way to express that yet.Randl commentedon Jul 8, 2025
We could use
const_panicmeanwhile?rust/library/core/src/panic.rs
Lines 193 to 203 in 2783fc4
oli-obk commentedon Jul 8, 2025
We don't need hacks, we can start marking Debug as const_trait and making impls const as we go. Then we need to figure out how to make more Formatter methods const