`::std::unreachable!()` doesn't work with `#[no_implicit_prelude]`?

I was testing one of my macros with #[no_implicit_prelude] (I don't use it myself, but I don't want my macros to break if a downstream crate uses it), and I noticed that ::std::unreachable!() doesn't work, giving the error error: cannot find macro `panic` in this scope.

I found some related discussion in https://github.com/rust-lang/rust/pull/61629. The discussion mentioned panic being a special case, but the pull request does hygenize some calls to panic! as $crate::panic! inside std; is it possible that the call in unreachable! was simply an oversight?

Sounds like a bug to me, I guess you should open an issue on Github.

For context, I believe that this is because unlike other items, panic! is actually different in core and std. So macros in core cannot just blindly use core::panic! instead of <{local}>::panic!, or semantics might change.

Specifically, core::panic! only supports the format!-like form, whereas you can pass an arbitrary payload structure to std::panic!. (i.e. panic!(()) is valid with std::panic! but not core::panic!.)

unreachable! does not have this requirement, however, so could use $crate::panic just fine, IIUC.

1 Like

As I understand it, unreachable is also defined in core, and also accepts format arguments when the underlying panic call does. Wouldn't this mean it exactly fits the things you've described?