Skip to content

Commit 90c8ad8

Browse files
committed
Don't use dummy_const_trick for NumOps
1 parent d4cc8f7 commit 90c8ad8

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

src/lib.rs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -512,43 +512,39 @@ pub fn num_ops(input: TokenStream) -> TokenStream {
512512
let ast: syn::DeriveInput = syn::parse(input).unwrap();
513513
let name = &ast.ident;
514514
let inner_ty = newtype_inner(&ast.data).expect(NEWTYPE_ONLY);
515-
dummy_const_trick(
516-
"NumOps",
517-
&name,
518-
quote! {
519-
impl ::std::ops::Add for #name {
520-
type Output = Self;
521-
fn add(self, other: Self) -> Self {
522-
#name(<#inner_ty as ::std::ops::Add>::add(self.0, other.0))
523-
}
515+
let impl_ = quote! {
516+
impl ::std::ops::Add for #name {
517+
type Output = Self;
518+
fn add(self, other: Self) -> Self {
519+
#name(<#inner_ty as ::std::ops::Add>::add(self.0, other.0))
524520
}
525-
impl ::std::ops::Sub for #name {
526-
type Output = Self;
527-
fn sub(self, other: Self) -> Self {
528-
#name(<#inner_ty as ::std::ops::Sub>::sub(self.0, other.0))
529-
}
521+
}
522+
impl ::std::ops::Sub for #name {
523+
type Output = Self;
524+
fn sub(self, other: Self) -> Self {
525+
#name(<#inner_ty as ::std::ops::Sub>::sub(self.0, other.0))
530526
}
531-
impl ::std::ops::Mul for #name {
532-
type Output = Self;
533-
fn mul(self, other: Self) -> Self {
534-
#name(<#inner_ty as ::std::ops::Mul>::mul(self.0, other.0))
535-
}
527+
}
528+
impl ::std::ops::Mul for #name {
529+
type Output = Self;
530+
fn mul(self, other: Self) -> Self {
531+
#name(<#inner_ty as ::std::ops::Mul>::mul(self.0, other.0))
536532
}
537-
impl ::std::ops::Div for #name {
538-
type Output = Self;
539-
fn div(self, other: Self) -> Self {
540-
#name(<#inner_ty as ::std::ops::Div>::div(self.0, other.0))
541-
}
533+
}
534+
impl ::std::ops::Div for #name {
535+
type Output = Self;
536+
fn div(self, other: Self) -> Self {
537+
#name(<#inner_ty as ::std::ops::Div>::div(self.0, other.0))
542538
}
543-
impl ::std::ops::Rem for #name {
544-
type Output = Self;
545-
fn rem(self, other: Self) -> Self {
546-
#name(<#inner_ty as ::std::ops::Rem>::rem(self.0, other.0))
547-
}
539+
}
540+
impl ::std::ops::Rem for #name {
541+
type Output = Self;
542+
fn rem(self, other: Self) -> Self {
543+
#name(<#inner_ty as ::std::ops::Rem>::rem(self.0, other.0))
548544
}
549-
},
550-
)
551-
.into()
545+
}
546+
};
547+
impl_.into()
552548
}
553549

554550
/// Derives [`num_traits::NumCast`][num_cast] for newtypes. The inner type must already implement

0 commit comments

Comments
 (0)