core::panic! and std::panic! are different, which forces the assert! macro to be unhygienic (see issues 56389 and 61567 which were closed as wont-fix).
I'm currently working on implementing improved messaging for assert! but while working on it I had the question: is it possible for assert! to expand to if ... { $crate::panic!(...) }? This would make core::assert! use core::panic! and std::assert! use std::panic!.
Normally this could be done by just having two different assert! implementations in each crate, but since assert! is a builtin I'm not sure if this is possible/feasible. To summarize:
- Is it possible/feasible for the builtin
assert!to use$crate(or something like it) that expands tocoreif callingcore::assert!(and expanding tostdif callingstd::assert!)? This might be simplest to implement by makingassert!a real macro that forwards its$cratemetavariable to the builtin (and renaming the builtin macro), assuming that can be done. - Are there any drawbacks to doing this? This might result in someone using
core::assert!in situations wherestd::assert!is available (and thus usingcore::panic!instead ofstd::panic!), but I'm not sure how bad that would be.
*Side question: what is the difference between core::panic! and std::panic!? It would be nice to document the difference because it's not obvious how core::panicking::panic and std::rt::begin_panic behave (I assume the difference is something like std printing to stderr but core not doing that?)