1 // implements the unary operator "op &T"
2 // based on "op T" where T is expected to be `Copy`able
3 macro_rules! forward_ref_unop {
4 (impl $imp:ident, $method:ident for $t:ty) => {
5 forward_ref_unop!(impl $imp, $method for $t,
6 #[stable(feature = "rust1", since = "1.0.0")]);
8 (impl const $imp:ident, $method:ident for $t:ty) => {
9 forward_ref_unop!(impl const $imp, $method for $t,
10 #[stable(feature = "rust1", since = "1.0.0")]);
12 // Equivalent to the non-const version, with the addition of `rustc_const_unstable`
13 (impl const $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
15 #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
16 impl const $imp for &$t {
17 type Output = <$t as $imp>::Output;
20 fn $method(self) -> <$t as $imp>::Output {
25 (impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
28 type Output = <$t as $imp>::Output;
31 fn $method(self) -> <$t as $imp>::Output {
38 // implements binary operators "&T op U", "T op &U", "&T op &U"
39 // based on "T op U" where T and U are expected to be `Copy`able
40 macro_rules! forward_ref_binop {
41 (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
42 forward_ref_binop!(impl $imp, $method for $t, $u,
43 #[stable(feature = "rust1", since = "1.0.0")]);
45 (impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
46 forward_ref_binop!(impl const $imp, $method for $t, $u,
47 #[stable(feature = "rust1", since = "1.0.0")]);
49 // Equivalent to the non-const version, with the addition of `rustc_const_unstable`
50 (impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
52 #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
53 impl<'a> const $imp<$u> for &'a $t {
54 type Output = <$t as $imp<$u>>::Output;
57 fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
58 $imp::$method(*self, other)
63 #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
64 impl const $imp<&$u> for $t {
65 type Output = <$t as $imp<$u>>::Output;
68 fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
69 $imp::$method(self, *other)
74 #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
75 impl const $imp<&$u> for &$t {
76 type Output = <$t as $imp<$u>>::Output;
79 fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
80 $imp::$method(*self, *other)
84 (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
86 impl<'a> $imp<$u> for &'a $t {
87 type Output = <$t as $imp<$u>>::Output;
90 fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
91 $imp::$method(*self, other)
96 impl $imp<&$u> for $t {
97 type Output = <$t as $imp<$u>>::Output;
100 fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
101 $imp::$method(self, *other)
106 impl $imp<&$u> for &$t {
107 type Output = <$t as $imp<$u>>::Output;
110 fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
111 $imp::$method(*self, *other)
117 // implements "T op= &U", based on "T op= U"
118 // where U is expected to be `Copy`able
119 macro_rules! forward_ref_op_assign {
120 (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
121 forward_ref_op_assign!(impl $imp, $method for $t, $u,
122 #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
124 (impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
125 forward_ref_op_assign!(impl const $imp, $method for $t, $u,
126 #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
128 // Equivalent to the non-const version, with the addition of `rustc_const_unstable`
129 (impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
131 #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
132 impl const $imp<&$u> for $t {
134 fn $method(&mut self, other: &$u) {
135 $imp::$method(self, *other);
139 (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
141 impl $imp<&$u> for $t {
143 fn $method(&mut self, other: &$u) {
144 $imp::$method(self, *other);
150 /// Create a zero-size type similar to a closure type, but named.
151 macro_rules! impl_fn_for_zst {
154 struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
155 |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
162 impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name {
164 extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
169 impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name {
171 extern "rust-call" fn call_mut(
173 ($( $arg, )*): ($( $ArgTy, )*)
175 Fn::call(&*self, ($( $arg, )*))
179 impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name {
180 type Output = $ReturnTy;
183 extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
184 Fn::call(&self, ($( $arg, )*))