]> git.lizzy.rs Git - rust.git/blob - src/libcore/internal_macros.rs
Rollup merge of #50849 - est31:visit_closure_args, r=michaelwoerister
[rust.git] / src / libcore / internal_macros.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 // implements the unary operator "op &T"
13 // based on "op T" where T is expected to be `Copy`able
14 macro_rules! forward_ref_unop {
15     (impl $imp:ident, $method:ident for $t:ty) => {
16         forward_ref_unop!(impl $imp, $method for $t,
17                 #[stable(feature = "rust1", since = "1.0.0")]);
18     };
19     (impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
20         #[$attr]
21         impl<'a> $imp for &'a $t {
22             type Output = <$t as $imp>::Output;
23
24             #[inline]
25             fn $method(self) -> <$t as $imp>::Output {
26                 $imp::$method(*self)
27             }
28         }
29     }
30 }
31
32 // implements binary operators "&T op U", "T op &U", "&T op &U"
33 // based on "T op U" where T and U are expected to be `Copy`able
34 macro_rules! forward_ref_binop {
35     (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
36         forward_ref_binop!(impl $imp, $method for $t, $u,
37                 #[stable(feature = "rust1", since = "1.0.0")]);
38     };
39     (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
40         #[$attr]
41         impl<'a> $imp<$u> for &'a $t {
42             type Output = <$t as $imp<$u>>::Output;
43
44             #[inline]
45             fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
46                 $imp::$method(*self, other)
47             }
48         }
49
50         #[$attr]
51         impl<'a> $imp<&'a $u> for $t {
52             type Output = <$t as $imp<$u>>::Output;
53
54             #[inline]
55             fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
56                 $imp::$method(self, *other)
57             }
58         }
59
60         #[$attr]
61         impl<'a, 'b> $imp<&'a $u> for &'b $t {
62             type Output = <$t as $imp<$u>>::Output;
63
64             #[inline]
65             fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
66                 $imp::$method(*self, *other)
67             }
68         }
69     }
70 }
71
72 // implements "T op= &U", based on "T op= U"
73 // where U is expected to be `Copy`able
74 macro_rules! forward_ref_op_assign {
75     (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
76         forward_ref_op_assign!(impl $imp, $method for $t, $u,
77                 #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
78     };
79     (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
80         #[$attr]
81         impl<'a> $imp<&'a $u> for $t {
82             #[inline]
83             fn $method(&mut self, other: &'a $u) {
84                 $imp::$method(self, *other);
85             }
86         }
87     }
88 }