1 /// A macro for triggering an ICE.
2 /// Calling `bug` instead of panicking will result in a nicer error message and should
3 /// therefore be preferred over `panic`/`unreachable` or others.
5 /// If you have a span available, you should use [`span_bug`] instead.
7 /// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
9 /// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
10 /// [`span_bug`]: crate::span_bug
13 () => ( $
crate::bug
!("impossible case reached") );
14 ($msg
:expr
) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) }
);
15 ($msg
:expr
,) => ({ $crate::bug!($msg) }
);
16 ($fmt
:expr
, $
($arg
:tt
)+) => ({
17 $
crate::util
::bug
::bug_fmt(::std
::format_args
!($fmt
, $
($arg
)+))
21 /// A macro for triggering an ICE with a span.
22 /// Calling `span_bug!` instead of panicking will result in a nicer error message and point
23 /// at the code the compiler was compiling when it ICEd. This is the preferred way to trigger
26 /// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
28 /// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
30 macro_rules
! span_bug
{
31 ($span
:expr
, $msg
:expr
) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) }
);
32 ($span
:expr
, $msg
:expr
,) => ({ $crate::span_bug!($span, $msg) }
);
33 ($span
:expr
, $fmt
:expr
, $
($arg
:tt
)+) => ({
34 $
crate::util
::bug
::span_bug_fmt($span
, ::std
::format_args
!($fmt
, $
($arg
)+))
38 ///////////////////////////////////////////////////////////////////////////
39 // Lift and TypeFoldable/TypeVisitable macros
41 // When possible, use one of these (relatively) convenient macros to write
45 macro_rules
! CloneLiftImpls
{
48 impl<'tcx
> $
crate::ty
::Lift
<'tcx
> for $ty
{
50 fn lift_to_tcx(self, _
: $
crate::ty
::TyCtxt
<'tcx
>) -> Option
<Self> {
58 /// Used for types that are `Copy` and which **do not care arena
59 /// allocated data** (i.e., don't need to be folded).
61 macro_rules
! TrivialTypeTraversalImpls
{
64 impl<'tcx
> $
crate::ty
::fold
::TypeFoldable
<$
crate::ty
::TyCtxt
<'tcx
>> for $ty
{
65 fn try_fold_with
<F
: $
crate::ty
::fold
::FallibleTypeFolder
<$
crate::ty
::TyCtxt
<'tcx
>>>(
68 ) -> ::std
::result
::Result
<Self, F
::Error
> {
73 fn fold_with
<F
: $
crate::ty
::fold
::TypeFolder
<$
crate::ty
::TyCtxt
<'tcx
>>>(
81 impl<'tcx
> $
crate::ty
::visit
::TypeVisitable
<$
crate::ty
::TyCtxt
<'tcx
>> for $ty
{
83 fn visit_with
<F
: $
crate::ty
::visit
::TypeVisitor
<$
crate::ty
::TyCtxt
<'tcx
>>>(
86 -> ::std
::ops
::ControlFlow
<F
::BreakTy
>
88 ::std
::ops
::ControlFlow
::Continue(())
96 macro_rules
! TrivialTypeTraversalAndLiftImpls
{
98 TrivialTypeTraversalImpls
! { $($t)* }
99 CloneLiftImpls
! { $($t)* }