@@ -78,23 +78,18 @@ fn dummy_const_trick<T: quote::ToTokens>(
78
78
Span :: call_site ( ) ,
79
79
) ;
80
80
quote ! {
81
- #[ allow( non_upper_case_globals, unused_attributes , unused_qualifications) ]
81
+ #[ allow( non_upper_case_globals, unused_qualifications) ]
82
82
const #dummy_const: ( ) = {
83
- #[ allow( unknown_lints) ]
84
- #[ cfg_attr( feature = "cargo-clippy" , allow( useless_attribute) ) ]
83
+ #[ allow( clippy:: useless_attribute) ]
85
84
#[ allow( rust_2018_idioms) ]
86
85
extern crate num_traits as _num_traits;
87
86
#exp
88
87
} ;
89
88
}
90
89
}
91
90
92
- #[ allow( deprecated) ]
93
91
fn 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 ( )
98
93
}
99
94
100
95
// If `data` is a newtype, return the type it's wrapping.
@@ -177,19 +172,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
177
172
let name = & ast. ident ;
178
173
179
174
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
-
193
175
quote ! {
194
176
impl _num_traits:: FromPrimitive for #name {
195
177
fn from_i64( n: i64 ) -> Option <Self > {
@@ -210,6 +192,9 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
210
192
fn from_i32( n: i32 ) -> Option <Self > {
211
193
<#inner_ty as _num_traits:: FromPrimitive >:: from_i32( n) . map( #name)
212
194
}
195
+ fn from_i128( n: i128 ) -> Option <Self > {
196
+ <#inner_ty as _num_traits:: FromPrimitive >:: from_i128( n) . map( #name)
197
+ }
213
198
fn from_usize( n: usize ) -> Option <Self > {
214
199
<#inner_ty as _num_traits:: FromPrimitive >:: from_usize( n) . map( #name)
215
200
}
@@ -222,13 +207,15 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
222
207
fn from_u32( n: u32 ) -> Option <Self > {
223
208
<#inner_ty as _num_traits:: FromPrimitive >:: from_u32( n) . map( #name)
224
209
}
210
+ fn from_u128( n: u128 ) -> Option <Self > {
211
+ <#inner_ty as _num_traits:: FromPrimitive >:: from_u128( n) . map( #name)
212
+ }
225
213
fn from_f32( n: f32 ) -> Option <Self > {
226
214
<#inner_ty as _num_traits:: FromPrimitive >:: from_f32( n) . map( #name)
227
215
}
228
216
fn from_f64( n: f64 ) -> Option <Self > {
229
217
<#inner_ty as _num_traits:: FromPrimitive >:: from_f64( n) . map( #name)
230
218
}
231
- #i128_fns
232
219
}
233
220
}
234
221
} else {
@@ -341,19 +328,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
341
328
let name = & ast. ident ;
342
329
343
330
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
-
357
331
quote ! {
358
332
impl _num_traits:: ToPrimitive for #name {
359
333
fn to_i64( & self ) -> Option <i64 > {
@@ -374,6 +348,9 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
374
348
fn to_i32( & self ) -> Option <i32 > {
375
349
<#inner_ty as _num_traits:: ToPrimitive >:: to_i32( & self . 0 )
376
350
}
351
+ fn to_i128( & self ) -> Option <i128 > {
352
+ <#inner_ty as _num_traits:: ToPrimitive >:: to_i128( & self . 0 )
353
+ }
377
354
fn to_usize( & self ) -> Option <usize > {
378
355
<#inner_ty as _num_traits:: ToPrimitive >:: to_usize( & self . 0 )
379
356
}
@@ -386,13 +363,15 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
386
363
fn to_u32( & self ) -> Option <u32 > {
387
364
<#inner_ty as _num_traits:: ToPrimitive >:: to_u32( & self . 0 )
388
365
}
366
+ fn to_u128( & self ) -> Option <u128 > {
367
+ <#inner_ty as _num_traits:: ToPrimitive >:: to_u128( & self . 0 )
368
+ }
389
369
fn to_f32( & self ) -> Option <f32 > {
390
370
<#inner_ty as _num_traits:: ToPrimitive >:: to_f32( & self . 0 )
391
371
}
392
372
fn to_f64( & self ) -> Option <f64 > {
393
373
<#inner_ty as _num_traits:: ToPrimitive >:: to_f64( & self . 0 )
394
374
}
395
- #i128_fns
396
375
}
397
376
}
398
377
} else {
@@ -452,9 +431,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
452
431
dummy_const_trick ( "ToPrimitive" , & name, impl_) . into ( )
453
432
}
454
433
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" ;
458
435
459
436
/// Derives [`num_traits::NumOps`][num_ops] for newtypes. The inner type must already implement
460
437
/// `NumOps`.
0 commit comments