From 90c8ad8147aa09161a5c07413f203dee695ca8f0 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 26 Jun 2020 17:47:49 -0700 Subject: [PATCH] Don't use dummy_const_trick for NumOps --- src/lib.rs | 60 +++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5901fbc..138b752 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -512,43 +512,39 @@ pub fn num_ops(input: TokenStream) -> TokenStream { let ast: syn::DeriveInput = syn::parse(input).unwrap(); let name = &ast.ident; let inner_ty = newtype_inner(&ast.data).expect(NEWTYPE_ONLY); - dummy_const_trick( - "NumOps", - &name, - quote! { - impl ::std::ops::Add for #name { - type Output = Self; - fn add(self, other: Self) -> Self { - #name(<#inner_ty as ::std::ops::Add>::add(self.0, other.0)) - } + let impl_ = quote! { + impl ::std::ops::Add for #name { + type Output = Self; + fn add(self, other: Self) -> Self { + #name(<#inner_ty as ::std::ops::Add>::add(self.0, other.0)) } - impl ::std::ops::Sub for #name { - type Output = Self; - fn sub(self, other: Self) -> Self { - #name(<#inner_ty as ::std::ops::Sub>::sub(self.0, other.0)) - } + } + impl ::std::ops::Sub for #name { + type Output = Self; + fn sub(self, other: Self) -> Self { + #name(<#inner_ty as ::std::ops::Sub>::sub(self.0, other.0)) } - impl ::std::ops::Mul for #name { - type Output = Self; - fn mul(self, other: Self) -> Self { - #name(<#inner_ty as ::std::ops::Mul>::mul(self.0, other.0)) - } + } + impl ::std::ops::Mul for #name { + type Output = Self; + fn mul(self, other: Self) -> Self { + #name(<#inner_ty as ::std::ops::Mul>::mul(self.0, other.0)) } - impl ::std::ops::Div for #name { - type Output = Self; - fn div(self, other: Self) -> Self { - #name(<#inner_ty as ::std::ops::Div>::div(self.0, other.0)) - } + } + impl ::std::ops::Div for #name { + type Output = Self; + fn div(self, other: Self) -> Self { + #name(<#inner_ty as ::std::ops::Div>::div(self.0, other.0)) } - impl ::std::ops::Rem for #name { - type Output = Self; - fn rem(self, other: Self) -> Self { - #name(<#inner_ty as ::std::ops::Rem>::rem(self.0, other.0)) - } + } + impl ::std::ops::Rem for #name { + type Output = Self; + fn rem(self, other: Self) -> Self { + #name(<#inner_ty as ::std::ops::Rem>::rem(self.0, other.0)) } - }, - ) - .into() + } + }; + impl_.into() } /// Derives [`num_traits::NumCast`][num_cast] for newtypes. The inner type must already implement