]> git.proxmox.com Git - rustc.git/blame - src/libcore/internal_macros.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / libcore / internal_macros.rs
CommitLineData
c30ab7b3
SL
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
14macro_rules! forward_ref_unop {
15 (impl $imp:ident, $method:ident for $t:ty) => {
8bb4bdeb
XL
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]
c30ab7b3
SL
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
34macro_rules! forward_ref_binop {
35 (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
8bb4bdeb
XL
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]
c30ab7b3
SL
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
8bb4bdeb 50 #[$attr]
c30ab7b3
SL
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
8bb4bdeb 60 #[$attr]
c30ab7b3
SL
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}