Skip to content

Tidy up const_ops, rename to const_arith_ops #143949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions library/core/src/internal_macros.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// implements the unary operator "op &T"
// based on "op T" where T is expected to be `Copy`able
macro_rules! forward_ref_unop {
(impl $imp:ident, $method:ident for $t:ty) => {
forward_ref_unop!(impl $imp, $method for $t,
#[stable(feature = "rust1", since = "1.0.0")]);
};
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
#[$attr]
impl $imp for &$t {
// FIXME: use macro_named_capture_groups to directly do impl $const(const)? instead
(impl $imp:ident, $method:ident for $t:ty, $(#[$attr:meta])+ $(, $const:tt)?) => {
$(#[$attr])+
impl $($const)? $imp for &$t {
type Output = <$t as $imp>::Output;

#[inline]
Expand All @@ -21,13 +18,10 @@ macro_rules! forward_ref_unop {
// implements binary operators "&T op U", "T op &U", "&T op &U"
// based on "T op U" where T and U are expected to be `Copy`able
macro_rules! forward_ref_binop {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
forward_ref_binop!(impl $imp, $method for $t, $u,
#[stable(feature = "rust1", since = "1.0.0")]);
};
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
#[$attr]
impl<'a> $imp<$u> for &'a $t {
// FIXME: use macro_named_capture_groups to directly do impl $const(const)? instead
(impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+ $(, $const:tt)?) => {
$(#[$attr])+
impl<'a> $($const)? $imp<$u> for &'a $t {
type Output = <$t as $imp<$u>>::Output;

#[inline]
Expand All @@ -37,8 +31,8 @@ macro_rules! forward_ref_binop {
}
}

#[$attr]
impl $imp<&$u> for $t {
$(#[$attr])+
impl $($const)? $imp<&$u> for $t {
type Output = <$t as $imp<$u>>::Output;

#[inline]
Expand All @@ -48,8 +42,8 @@ macro_rules! forward_ref_binop {
}
}

#[$attr]
impl $imp<&$u> for &$t {
$(#[$attr])+
impl $($const)? $imp<&$u> for &$t {
type Output = <$t as $imp<$u>>::Output;

#[inline]
Expand All @@ -64,13 +58,10 @@ macro_rules! forward_ref_binop {
// implements "T op= &U", based on "T op= U"
// where U is expected to be `Copy`able
macro_rules! forward_ref_op_assign {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
forward_ref_op_assign!(impl $imp, $method for $t, $u,
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
};
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
#[$attr]
impl $imp<&$u> for $t {
// FIXME: use macro_named_capture_groups to directly do impl $const(const)? instead
(impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+ $(, $const:tt)?) => {
$(#[$attr])+
impl $($const)? $imp<&$u> for $t {
#[inline]
#[track_caller]
fn $method(&mut self, other: &$u) {
Expand Down
Loading
Loading