@@ -78,23 +78,18 @@ fn dummy_const_trick<T: quote::ToTokens>(
7878 Span :: call_site ( ) ,
7979 ) ;
8080 quote ! {
81- #[ allow( non_upper_case_globals, unused_attributes , unused_qualifications) ]
81+ #[ allow( non_upper_case_globals, unused_qualifications) ]
8282 const #dummy_const: ( ) = {
83- #[ allow( unknown_lints) ]
84- #[ cfg_attr( feature = "cargo-clippy" , allow( useless_attribute) ) ]
83+ #[ allow( clippy:: useless_attribute) ]
8584 #[ allow( rust_2018_idioms) ]
8685 extern crate num_traits as _num_traits;
8786 #exp
8887 } ;
8988 }
9089}
9190
92- #[ allow( deprecated) ]
9391fn unraw ( ident : & proc_macro2:: Ident ) -> String {
94- // str::trim_start_matches was added in 1.30, trim_left_matches deprecated
95- // in 1.33. We currently support rustc back to 1.15 so we need to continue
96- // to use the deprecated one.
97- ident. to_string ( ) . trim_left_matches ( "r#" ) . to_owned ( )
92+ ident. to_string ( ) . trim_start_matches ( "r#" ) . to_owned ( )
9893}
9994
10095// If `data` is a newtype, return the type it's wrapping.
@@ -177,19 +172,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
177172 let name = & ast. ident ;
178173
179174 let impl_ = if let Some ( inner_ty) = newtype_inner ( & ast. data ) {
180- let i128_fns = if cfg ! ( has_i128) {
181- quote ! {
182- fn from_i128( n: i128 ) -> Option <Self > {
183- <#inner_ty as _num_traits:: FromPrimitive >:: from_i128( n) . map( #name)
184- }
185- fn from_u128( n: u128 ) -> Option <Self > {
186- <#inner_ty as _num_traits:: FromPrimitive >:: from_u128( n) . map( #name)
187- }
188- }
189- } else {
190- quote ! { }
191- } ;
192-
193175 quote ! {
194176 impl _num_traits:: FromPrimitive for #name {
195177 fn from_i64( n: i64 ) -> Option <Self > {
@@ -210,6 +192,9 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
210192 fn from_i32( n: i32 ) -> Option <Self > {
211193 <#inner_ty as _num_traits:: FromPrimitive >:: from_i32( n) . map( #name)
212194 }
195+ fn from_i128( n: i128 ) -> Option <Self > {
196+ <#inner_ty as _num_traits:: FromPrimitive >:: from_i128( n) . map( #name)
197+ }
213198 fn from_usize( n: usize ) -> Option <Self > {
214199 <#inner_ty as _num_traits:: FromPrimitive >:: from_usize( n) . map( #name)
215200 }
@@ -222,13 +207,15 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
222207 fn from_u32( n: u32 ) -> Option <Self > {
223208 <#inner_ty as _num_traits:: FromPrimitive >:: from_u32( n) . map( #name)
224209 }
210+ fn from_u128( n: u128 ) -> Option <Self > {
211+ <#inner_ty as _num_traits:: FromPrimitive >:: from_u128( n) . map( #name)
212+ }
225213 fn from_f32( n: f32 ) -> Option <Self > {
226214 <#inner_ty as _num_traits:: FromPrimitive >:: from_f32( n) . map( #name)
227215 }
228216 fn from_f64( n: f64 ) -> Option <Self > {
229217 <#inner_ty as _num_traits:: FromPrimitive >:: from_f64( n) . map( #name)
230218 }
231- #i128_fns
232219 }
233220 }
234221 } else {
@@ -341,19 +328,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
341328 let name = & ast. ident ;
342329
343330 let impl_ = if let Some ( inner_ty) = newtype_inner ( & ast. data ) {
344- let i128_fns = if cfg ! ( has_i128) {
345- quote ! {
346- fn to_i128( & self ) -> Option <i128 > {
347- <#inner_ty as _num_traits:: ToPrimitive >:: to_i128( & self . 0 )
348- }
349- fn to_u128( & self ) -> Option <u128 > {
350- <#inner_ty as _num_traits:: ToPrimitive >:: to_u128( & self . 0 )
351- }
352- }
353- } else {
354- quote ! { }
355- } ;
356-
357331 quote ! {
358332 impl _num_traits:: ToPrimitive for #name {
359333 fn to_i64( & self ) -> Option <i64 > {
@@ -374,6 +348,9 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
374348 fn to_i32( & self ) -> Option <i32 > {
375349 <#inner_ty as _num_traits:: ToPrimitive >:: to_i32( & self . 0 )
376350 }
351+ fn to_i128( & self ) -> Option <i128 > {
352+ <#inner_ty as _num_traits:: ToPrimitive >:: to_i128( & self . 0 )
353+ }
377354 fn to_usize( & self ) -> Option <usize > {
378355 <#inner_ty as _num_traits:: ToPrimitive >:: to_usize( & self . 0 )
379356 }
@@ -386,13 +363,15 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
386363 fn to_u32( & self ) -> Option <u32 > {
387364 <#inner_ty as _num_traits:: ToPrimitive >:: to_u32( & self . 0 )
388365 }
366+ fn to_u128( & self ) -> Option <u128 > {
367+ <#inner_ty as _num_traits:: ToPrimitive >:: to_u128( & self . 0 )
368+ }
389369 fn to_f32( & self ) -> Option <f32 > {
390370 <#inner_ty as _num_traits:: ToPrimitive >:: to_f32( & self . 0 )
391371 }
392372 fn to_f64( & self ) -> Option <f64 > {
393373 <#inner_ty as _num_traits:: ToPrimitive >:: to_f64( & self . 0 )
394374 }
395- #i128_fns
396375 }
397376 }
398377 } else {
@@ -452,9 +431,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
452431 dummy_const_trick ( "ToPrimitive" , & name, impl_) . into ( )
453432}
454433
455- #[ allow( renamed_and_removed_lints) ]
456- #[ cfg_attr( feature = "cargo-clippy" , allow( const_static_lifetime) ) ]
457- const NEWTYPE_ONLY : & ' static str = "This trait can only be derived for newtypes" ;
434+ const NEWTYPE_ONLY : & str = "This trait can only be derived for newtypes" ;
458435
459436/// Derives [`num_traits::NumOps`][num_ops] for newtypes. The inner type must already implement
460437/// `NumOps`.
0 commit comments