Skip to main content

core/
internal_macros.rs

1// implements the unary operator "op &T"
2// based on "op T" where T is expected to be `Copy`able
3macro_rules! forward_ref_unop {
4    (impl $imp:ident, $method:ident for $t:ty, $(#[$attr:meta])+) => {
5        $(#[$attr])+
6        const impl $imp for &$t {
7            type Output = <$t as $imp>::Output;
8
9            #[inline]
10            #[ferrocene::prevalidated]
11            fn $method(self) -> <$t as $imp>::Output {
12                $imp::$method(*self)
13            }
14        }
15    }
16}
17
18// implements binary operators "&T op U", "T op &U", "&T op &U"
19// based on "T op U" where T and U are expected to be `Copy`able
20macro_rules! forward_ref_binop {
21    (impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+) => {
22        $(#[$attr])+
23        const impl $imp<$u> for &$t {
24            type Output = <$t as $imp<$u>>::Output;
25
26            #[inline]
27            #[track_caller]
28            #[ferrocene::prevalidated]
29            fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
30                $imp::$method(*self, other)
31            }
32        }
33
34        $(#[$attr])+
35        const impl $imp<&$u> for $t {
36            type Output = <$t as $imp<$u>>::Output;
37
38            #[inline]
39            #[track_caller]
40            #[ferrocene::prevalidated]
41            fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
42                $imp::$method(self, *other)
43            }
44        }
45
46        $(#[$attr])+
47        const impl $imp<&$u> for &$t {
48            type Output = <$t as $imp<$u>>::Output;
49
50            #[inline]
51            #[track_caller]
52            #[ferrocene::prevalidated]
53            fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
54                $imp::$method(*self, *other)
55            }
56        }
57    }
58}
59
60// implements "T op= &U", based on "T op= U"
61// where U is expected to be `Copy`able
62macro_rules! forward_ref_op_assign {
63    (impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+) => {
64        $(#[$attr])+
65        const impl $imp<&$u> for $t {
66            #[inline]
67            #[track_caller]
68            #[ferrocene::prevalidated]
69            fn $method(&mut self, other: &$u) {
70                $imp::$method(self, *other);
71            }
72        }
73    }
74}
75
76/// Creates a zero-size type similar to a closure type, but named.
77macro_rules! impl_fn_for_zst {
78    ($(
79        $( #[$attr: meta] )*
80        $vis:vis struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
81            |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
82            $body: block;
83    )+) => {
84        $(
85            #[ferrocene::prevalidated]
86            $( #[$attr] )*
87            $vis struct $Name;
88
89            impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name {
90                #[inline]
91                #[ferrocene::prevalidated]
92                extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
93                    $body
94                }
95            }
96
97            impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name {
98                #[inline]
99                #[ferrocene::prevalidated]
100                extern "rust-call" fn call_mut(
101                    &mut self,
102                    ($( $arg, )*): ($( $ArgTy, )*)
103                ) -> $ReturnTy {
104                    Fn::call(&*self, ($( $arg, )*))
105                }
106            }
107
108            impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name {
109                type Output = $ReturnTy;
110
111                #[inline]
112                #[ferrocene::prevalidated]
113                extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
114                    Fn::call(&self, ($( $arg, )*))
115                }
116            }
117        )+
118    }
119}
120
121/// Permanently unstable. Only used in internal rustc tests. Do not use.
122#[rustc_builtin_macro(test_binder_constraints)]
123#[unstable(feature = "test_binder_constraints", issue = "none")]
124#[macro_export]
125macro_rules! test_binder_constraints {
126    ($($arg:tt)*) => {
127        /* compiler built-in */
128    };
129}