2022-12-30 13:38:34 +01:00
|
|
|
/// A macro for triggering an ICE.
|
|
|
|
|
/// Calling `bug` instead of panicking will result in a nicer error message and should
|
2023-04-10 22:02:52 +02:00
|
|
|
/// therefore be preferred over `panic`/`unreachable` or others.
|
2022-12-30 13:38:34 +01:00
|
|
|
///
|
|
|
|
|
/// If you have a span available, you should use [`span_bug`] instead.
|
|
|
|
|
///
|
2025-01-31 09:00:58 +11:00
|
|
|
/// If the bug should only be emitted when compilation didn't fail,
|
|
|
|
|
/// [`DiagCtxtHandle::span_delayed_bug`] may be useful.
|
2022-12-30 13:38:34 +01:00
|
|
|
///
|
2024-06-18 10:35:56 +00:00
|
|
|
/// [`DiagCtxtHandle::span_delayed_bug`]: rustc_errors::DiagCtxtHandle::span_delayed_bug
|
2022-12-30 13:38:34 +01:00
|
|
|
/// [`span_bug`]: crate::span_bug
|
2016-03-24 00:35:26 +01:00
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! bug {
|
2024-03-21 11:24:02 -04:00
|
|
|
() => (
|
|
|
|
|
$crate::bug!("impossible case reached")
|
|
|
|
|
);
|
2025-01-31 09:00:58 +11:00
|
|
|
($($arg:tt)+) => (
|
|
|
|
|
$crate::util::bug::bug_fmt(::std::format_args!($($arg)+))
|
2024-03-21 11:24:02 -04:00
|
|
|
);
|
2016-03-24 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 13:38:34 +01: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.
|
|
|
|
|
///
|
2025-01-31 09:00:58 +11:00
|
|
|
/// If the bug should only be emitted when compilation didn't fail,
|
|
|
|
|
/// [`DiagCtxtHandle::span_delayed_bug`] may be useful.
|
2022-12-30 13:38:34 +01:00
|
|
|
///
|
2024-06-18 10:35:56 +00:00
|
|
|
/// [`DiagCtxtHandle::span_delayed_bug`]: rustc_errors::DiagCtxtHandle::span_delayed_bug
|
2016-03-24 00:35:26 +01:00
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! span_bug {
|
2025-01-31 09:00:58 +11:00
|
|
|
($span:expr, $($arg:tt)+) => (
|
|
|
|
|
$crate::util::bug::span_bug_fmt($span, ::std::format_args!($($arg)+))
|
2024-03-21 11:24:02 -04:00
|
|
|
);
|
2016-03-24 00:35:26 +01:00
|
|
|
}
|
2017-03-30 15:27:27 +02:00
|
|
|
|
2018-02-09 10:34:23 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2022-06-17 11:05:17 +01:00
|
|
|
// Lift and TypeFoldable/TypeVisitable macros
|
2018-02-09 10:34:23 -05:00
|
|
|
//
|
|
|
|
|
// When possible, use one of these (relatively) convenient macros to write
|
|
|
|
|
// the impls for you.
|
|
|
|
|
|
2023-09-14 12:03:56 +10:00
|
|
|
macro_rules! TrivialLiftImpls {
|
2023-07-24 22:02:52 +00:00
|
|
|
($($ty:ty),+ $(,)?) => {
|
2018-02-09 10:34:23 -05:00
|
|
|
$(
|
2024-05-10 14:27:48 -04:00
|
|
|
impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty {
|
2018-02-09 10:34:23 -05:00
|
|
|
type Lifted = Self;
|
2024-07-16 00:03:37 -04:00
|
|
|
fn lift_to_interner(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
|
2020-10-16 21:59:49 +02:00
|
|
|
Some(self)
|
2018-02-09 10:34:23 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)+
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 19:42:06 +08:00
|
|
|
/// Used for types that are `Copy` and which **do not care about arena
|
2018-02-09 10:34:23 -05:00
|
|
|
/// allocated data** (i.e., don't need to be folded).
|
2022-06-17 11:05:17 +01:00
|
|
|
macro_rules! TrivialTypeTraversalImpls {
|
2023-07-24 22:02:52 +00:00
|
|
|
($($ty:ty),+ $(,)?) => {
|
2018-02-09 10:34:23 -05:00
|
|
|
$(
|
2025-03-13 16:59:55 +00:00
|
|
|
impl<'tcx> $crate::ty::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
|
|
|
|
|
fn try_fold_with<F: $crate::ty::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
|
2020-10-24 02:21:18 +02:00
|
|
|
self,
|
2022-10-05 18:26:48 +02:00
|
|
|
_: &mut F,
|
|
|
|
|
) -> ::std::result::Result<Self, F::Error> {
|
2021-05-19 13:34:54 +02:00
|
|
|
Ok(self)
|
2018-02-09 10:34:23 -05:00
|
|
|
}
|
2022-10-05 18:26:48 +02:00
|
|
|
|
|
|
|
|
#[inline]
|
2025-03-13 16:59:55 +00:00
|
|
|
fn fold_with<F: $crate::ty::TypeFolder<$crate::ty::TyCtxt<'tcx>>>(
|
2022-10-05 18:26:48 +02:00
|
|
|
self,
|
|
|
|
|
_: &mut F,
|
|
|
|
|
) -> Self {
|
|
|
|
|
self
|
|
|
|
|
}
|
2022-06-17 11:05:17 +01:00
|
|
|
}
|
2018-02-09 10:34:23 -05:00
|
|
|
|
2025-03-13 17:09:25 +00:00
|
|
|
impl<'tcx> $crate::ty::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty {
|
2022-10-05 18:26:48 +02:00
|
|
|
#[inline]
|
2025-03-13 17:09:25 +00:00
|
|
|
fn visit_with<F: $crate::ty::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>(
|
2018-02-09 10:34:23 -05:00
|
|
|
&self,
|
|
|
|
|
_: &mut F)
|
2024-02-24 17:22:28 -05:00
|
|
|
-> F::Result
|
2018-02-09 10:34:23 -05:00
|
|
|
{
|
2025-03-13 17:09:25 +00:00
|
|
|
<F::Result as ::rustc_middle::ty::VisitorResult>::output()
|
2018-02-09 10:34:23 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)+
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 11:05:17 +01:00
|
|
|
macro_rules! TrivialTypeTraversalAndLiftImpls {
|
2018-02-09 10:34:23 -05:00
|
|
|
($($t:tt)*) => {
|
2022-06-17 11:05:17 +01:00
|
|
|
TrivialTypeTraversalImpls! { $($t)* }
|
2023-09-14 12:03:56 +10:00
|
|
|
TrivialLiftImpls! { $($t)* }
|
2018-02-09 10:34:23 -05:00
|
|
|
}
|
|
|
|
|
}
|