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> {
33 Some(Clone
::clone(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
! CloneTypeFoldableImpls
{
52 (for <$tcx
:lifetime
> { $($ty:ty,)+ }
) => {
54 impl<$tcx
> $
crate::ty
::fold
::TypeFoldable
<$tcx
> for $ty
{
55 fn super_fold_with
<F
: $
crate::ty
::fold
::TypeFolder
<$tcx
>>(
62 fn super_visit_with
<F
: $
crate::ty
::fold
::TypeVisitor
<$tcx
>>(
74 CloneTypeFoldableImpls
! {
83 macro_rules
! CloneTypeFoldableAndLiftImpls
{
85 CloneTypeFoldableImpls
! { $($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 super_fold_with
<V
: $
crate::ty
::fold
::TypeFolder
<$tcx
>>(
102 EnumTypeFoldableImpl
!(@
FoldVariants(self, folder
) input($
($variants
)*) output())
105 fn super_visit_with
<V
: $
crate::ty
::fold
::TypeVisitor
<$tcx
>>(
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
::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 false $
(|| $
crate::ty
::fold
::TypeFoldable
::visit_with(
183 $variant_arg
, $visitor
191 (@
VisitVariants($this
:expr
, $visitor
:expr
)
192 input( ($variant
:path
) { $($variant_arg:ident),* $(,)? }
, $
($input
:tt
)*)
193 output( $
($output
:tt
)*) ) => {
194 EnumTypeFoldableImpl
!(
195 @
VisitVariants($this
, $visitor
)
198 $variant { $($variant_arg),* }
=> {
199 false $
(|| $
crate::ty
::fold
::TypeFoldable
::visit_with(
200 $variant_arg
, $visitor
208 (@
VisitVariants($this
:expr
, $visitor
:expr
)
209 input( ($variant
:path
), $
($input
:tt
)*)
210 output( $
($output
:tt
)*) ) => {
211 EnumTypeFoldableImpl
!(
212 @
VisitVariants($this
, $visitor
)
215 $variant
=> { false }