3 () => ( $crate::bug!("impossible case reached") );
4 ($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) });
5 ($msg:expr,) => ({ $crate::bug!($msg) });
6 ($fmt:expr, $($arg:tt)+) => ({
7 $crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+))
12 macro_rules! span_bug {
13 ($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });
14 ($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) });
15 ($span:expr, $fmt:expr, $($arg:tt)+) => ({
16 $crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+))
20 ///////////////////////////////////////////////////////////////////////////
21 // Lift and TypeFoldable macros
23 // When possible, use one of these (relatively) convenient macros to write
27 macro_rules! CloneLiftImpls {
28 (for <$tcx:lifetime> { $($ty:ty,)+ }) => {
30 impl<$tcx> $crate::ty::Lift<$tcx> for $ty {
32 fn lift_to_tcx(self, _: $crate::ty::TyCtxt<$tcx>) -> Option<Self> {
48 /// Used for types that are `Copy` and which **do not care arena
49 /// allocated data** (i.e., don't need to be folded).
51 macro_rules! TrivialTypeFoldableImpls {
52 (for <$tcx:lifetime> { $($ty:ty,)+ }) => {
54 impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
55 fn try_super_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
58 ) -> ::std::result::Result<$ty, F::Error> {
62 fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
65 -> ::std::ops::ControlFlow<F::BreakTy>
67 ::std::ops::ControlFlow::CONTINUE
74 TrivialTypeFoldableImpls! {
83 macro_rules! TrivialTypeFoldableAndLiftImpls {
85 TrivialTypeFoldableImpls! { $($t)* }
86 CloneLiftImpls! { $($t)* }
91 macro_rules! EnumTypeFoldableImpl {
92 (impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
94 } $(where $($wc:tt)*)*) => {
95 impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
98 fn try_super_fold_with<V: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
101 ) -> ::std::result::Result<Self, V::Error> {
102 EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())
105 fn super_visit_with<V: $crate::ty::fold::TypeVisitor<$tcx>>(
108 ) -> ::std::ops::ControlFlow<V::BreakTy> {
109 EnumTypeFoldableImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
114 (@FoldVariants($this:expr, $folder:expr) input() output($($output:tt)*)) => {
120 (@FoldVariants($this:expr, $folder:expr)
121 input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
122 output( $($output:tt)*) ) => {
123 EnumTypeFoldableImpl!(
124 @FoldVariants($this, $folder)
127 $variant ( $($variant_arg),* ) => {
129 $($crate::ty::fold::TypeFoldable::try_fold_with($variant_arg, $folder)?),*
137 (@FoldVariants($this:expr, $folder:expr)
138 input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
139 output( $($output:tt)*) ) => {
140 EnumTypeFoldableImpl!(
141 @FoldVariants($this, $folder)
144 $variant { $($variant_arg),* } => {
146 $($variant_arg: $crate::ty::fold::TypeFoldable::fold_with(
147 $variant_arg, $folder
155 (@FoldVariants($this:expr, $folder:expr)
156 input( ($variant:path), $($input:tt)*)
157 output( $($output:tt)*) ) => {
158 EnumTypeFoldableImpl!(
159 @FoldVariants($this, $folder)
162 $variant => { $variant }
168 (@VisitVariants($this:expr, $visitor:expr) input() output($($output:tt)*)) => {
174 (@VisitVariants($this:expr, $visitor:expr)
175 input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
176 output( $($output:tt)*) ) => {
177 EnumTypeFoldableImpl!(
178 @VisitVariants($this, $visitor)
181 $variant ( $($variant_arg),* ) => {
182 $($crate::ty::fold::TypeFoldable::visit_with(
183 $variant_arg, $visitor
185 ::std::ops::ControlFlow::CONTINUE
192 (@VisitVariants($this:expr, $visitor:expr)
193 input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
194 output( $($output:tt)*) ) => {
195 EnumTypeFoldableImpl!(
196 @VisitVariants($this, $visitor)
199 $variant { $($variant_arg),* } => {
200 $($crate::ty::fold::TypeFoldable::visit_with(
201 $variant_arg, $visitor
203 ::std::ops::ControlFlow::CONTINUE
210 (@VisitVariants($this:expr, $visitor:expr)
211 input( ($variant:path), $($input:tt)*)
212 output( $($output:tt)*) ) => {
213 EnumTypeFoldableImpl!(
214 @VisitVariants($this, $visitor)
217 $variant => { ::std::ops::ControlFlow::CONTINUE }