2022-12-30 12:38:34 +00:00
|
|
|
/// A macro for triggering an ICE.
|
|
|
|
/// Calling `bug` instead of panicking will result in a nicer error message and should
|
2023-04-10 20:02:52 +00:00
|
|
|
/// therefore be preferred over `panic`/`unreachable` or others.
|
2022-12-30 12:38:34 +00:00
|
|
|
///
|
|
|
|
/// If you have a span available, you should use [`span_bug`] instead.
|
|
|
|
///
|
|
|
|
/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
|
|
|
|
///
|
|
|
|
/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
|
|
|
|
/// [`span_bug`]: crate::span_bug
|
2016-03-23 23:35:26 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! bug {
|
2020-06-15 14:17:58 +00:00
|
|
|
() => ( $crate::bug!("impossible case reached") );
|
|
|
|
($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) });
|
|
|
|
($msg:expr,) => ({ $crate::bug!($msg) });
|
|
|
|
($fmt:expr, $($arg:tt)+) => ({
|
|
|
|
$crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+))
|
|
|
|
});
|
2016-03-23 23:35:26 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 12:38:34 +00:00
|
|
|
/// A macro for triggering an ICE with a span.
|
|
|
|
/// Calling `span_bug!` instead of panicking will result in a nicer error message and point
|
|
|
|
/// at the code the compiler was compiling when it ICEd. This is the preferred way to trigger
|
|
|
|
/// ICEs.
|
|
|
|
///
|
|
|
|
/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
|
|
|
|
///
|
|
|
|
/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
|
2016-03-23 23:35:26 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! span_bug {
|
2020-06-15 14:17:58 +00:00
|
|
|
($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });
|
|
|
|
($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) });
|
|
|
|
($span:expr, $fmt:expr, $($arg:tt)+) => ({
|
|
|
|
$crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+))
|
|
|
|
});
|
2016-03-23 23:35:26 +00:00
|
|
|
}
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2018-02-09 15:34:23 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2022-06-17 10:05:17 +00:00
|
|
|
// Lift and TypeFoldable/TypeVisitable macros
|
2018-02-09 15:34:23 +00:00
|
|
|
//
|
|
|
|
// When possible, use one of these (relatively) convenient macros to write
|
|
|
|
// the impls for you.
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! CloneLiftImpls {
|
2023-04-16 04:01:43 +00:00
|
|
|
($($ty:ty,)+) => {
|
2018-02-09 15:34:23 +00:00
|
|
|
$(
|
2023-04-16 04:01:43 +00:00
|
|
|
impl<'tcx> $crate::ty::Lift<'tcx> for $ty {
|
2018-02-09 15:34:23 +00:00
|
|
|
type Lifted = Self;
|
2023-04-16 04:01:43 +00:00
|
|
|
fn lift_to_tcx(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
|
2020-10-16 19:59:49 +00:00
|
|
|
Some(self)
|
2018-02-09 15:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Used for types that are `Copy` and which **do not care arena
|
|
|
|
/// allocated data** (i.e., don't need to be folded).
|
|
|
|
#[macro_export]
|
2022-06-17 10:05:17 +00:00
|
|
|
macro_rules! TrivialTypeTraversalImpls {
|
2023-04-16 04:01:43 +00:00
|
|
|
($($ty:ty,)+) => {
|
2018-02-09 15:34:23 +00:00
|
|
|
$(
|
2023-04-16 04:01:43 +00:00
|
|
|
impl<'tcx> $crate::ty::fold::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
|
|
|
|
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
|
2020-10-24 00:21:18 +00:00
|
|
|
self,
|
2022-10-05 16:26:48 +00:00
|
|
|
_: &mut F,
|
|
|
|
) -> ::std::result::Result<Self, F::Error> {
|
2021-05-19 11:34:54 +00:00
|
|
|
Ok(self)
|
2018-02-09 15:34:23 +00:00
|
|
|
}
|
2022-10-05 16:26:48 +00:00
|
|
|
|
|
|
|
#[inline]
|
2023-04-16 04:01:43 +00:00
|
|
|
fn fold_with<F: $crate::ty::fold::TypeFolder<$crate::ty::TyCtxt<'tcx>>>(
|
2022-10-05 16:26:48 +00:00
|
|
|
self,
|
|
|
|
_: &mut F,
|
|
|
|
) -> Self {
|
|
|
|
self
|
|
|
|
}
|
2022-06-17 10:05:17 +00:00
|
|
|
}
|
2018-02-09 15:34:23 +00:00
|
|
|
|
2023-04-16 04:01:43 +00:00
|
|
|
impl<'tcx> $crate::ty::visit::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty {
|
2022-10-05 16:26:48 +00:00
|
|
|
#[inline]
|
2023-04-16 04:01:43 +00:00
|
|
|
fn visit_with<F: $crate::ty::visit::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>(
|
2018-02-09 15:34:23 +00:00
|
|
|
&self,
|
|
|
|
_: &mut F)
|
2020-11-05 16:30:39 +00:00
|
|
|
-> ::std::ops::ControlFlow<F::BreakTy>
|
2018-02-09 15:34:23 +00:00
|
|
|
{
|
2023-01-18 07:17:13 +00:00
|
|
|
::std::ops::ControlFlow::Continue(())
|
2018-02-09 15:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-06-17 10:05:17 +00:00
|
|
|
macro_rules! TrivialTypeTraversalAndLiftImpls {
|
2018-02-09 15:34:23 +00:00
|
|
|
($($t:tt)*) => {
|
2022-06-17 10:05:17 +00:00
|
|
|
TrivialTypeTraversalImpls! { $($t)* }
|
2018-02-09 15:34:23 +00:00
|
|
|
CloneLiftImpls! { $($t)* }
|
|
|
|
}
|
|
|
|
}
|