3 () => ( bug!("impossible case reached") );
4 ($($message:tt)*) => ({
5 $crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
10 macro_rules! span_bug {
11 ($span:expr, $($message:tt)*) => ({
12 $crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
16 ///////////////////////////////////////////////////////////////////////////
17 // Lift and TypeFoldable macros
19 // When possible, use one of these (relatively) convenient macros to write
23 macro_rules! CloneLiftImpls {
24 (for <$tcx:lifetime> { $($ty:ty,)+ }) => {
26 impl<$tcx> $crate::ty::Lift<$tcx> for $ty {
28 fn lift_to_tcx(&self, _: $crate::ty::TyCtxt<$tcx>) -> Option<Self> {
29 Some(Clone::clone(self))
44 /// Used for types that are `Copy` and which **do not care arena
45 /// allocated data** (i.e., don't need to be folded).
47 macro_rules! CloneTypeFoldableImpls {
48 (for <$tcx:lifetime> { $($ty:ty,)+ }) => {
50 impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
51 fn super_fold_with<F: $crate::ty::fold::TypeFolder<$tcx>>(
58 fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
70 CloneTypeFoldableImpls! {
79 macro_rules! CloneTypeFoldableAndLiftImpls {
81 CloneTypeFoldableImpls! { $($t)* }
82 CloneLiftImpls! { $($t)* }
87 macro_rules! EnumTypeFoldableImpl {
88 (impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
90 } $(where $($wc:tt)*)*) => {
91 impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
94 fn super_fold_with<V: $crate::ty::fold::TypeFolder<$tcx>>(
98 EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())
101 fn super_visit_with<V: $crate::ty::fold::TypeVisitor<$tcx>>(
105 EnumTypeFoldableImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
110 (@FoldVariants($this:expr, $folder:expr) input() output($($output:tt)*)) => {
116 (@FoldVariants($this:expr, $folder:expr)
117 input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
118 output( $($output:tt)*) ) => {
119 EnumTypeFoldableImpl!(
120 @FoldVariants($this, $folder)
123 $variant ( $($variant_arg),* ) => {
125 $($crate::ty::fold::TypeFoldable::fold_with($variant_arg, $folder)),*
133 (@FoldVariants($this:expr, $folder:expr)
134 input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
135 output( $($output:tt)*) ) => {
136 EnumTypeFoldableImpl!(
137 @FoldVariants($this, $folder)
140 $variant { $($variant_arg),* } => {
142 $($variant_arg: $crate::ty::fold::TypeFoldable::fold_with(
143 $variant_arg, $folder
151 (@FoldVariants($this:expr, $folder:expr)
152 input( ($variant:path), $($input:tt)*)
153 output( $($output:tt)*) ) => {
154 EnumTypeFoldableImpl!(
155 @FoldVariants($this, $folder)
158 $variant => { $variant }
164 (@VisitVariants($this:expr, $visitor:expr) input() output($($output:tt)*)) => {
170 (@VisitVariants($this:expr, $visitor:expr)
171 input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
172 output( $($output:tt)*) ) => {
173 EnumTypeFoldableImpl!(
174 @VisitVariants($this, $visitor)
177 $variant ( $($variant_arg),* ) => {
178 false $(|| $crate::ty::fold::TypeFoldable::visit_with(
179 $variant_arg, $visitor
187 (@VisitVariants($this:expr, $visitor:expr)
188 input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
189 output( $($output:tt)*) ) => {
190 EnumTypeFoldableImpl!(
191 @VisitVariants($this, $visitor)
194 $variant { $($variant_arg),* } => {
195 false $(|| $crate::ty::fold::TypeFoldable::visit_with(
196 $variant_arg, $visitor
204 (@VisitVariants($this:expr, $visitor:expr)
205 input( ($variant:path), $($input:tt)*)
206 output( $($output:tt)*) ) => {
207 EnumTypeFoldableImpl!(
208 @VisitVariants($this, $visitor)
211 $variant => { false }