File tree Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 1
- use std:: convert:: TryInto ;
2
1
use std:: iter;
3
2
4
3
use proc_macro2:: TokenStream ;
@@ -682,7 +681,7 @@ impl<'block> AsyncInfo<'block> {
682
681
out_stmts[ iter] = match self . kind {
683
682
// `Box::pin(immediately_invoked_async_fn())`
684
683
AsyncKind :: Function ( fun) => {
685
- let fun: MaybeItemFn = fun. clone ( ) . try_into ( ) ? ;
684
+ let fun = MaybeItemFn :: from ( fun. clone ( ) ) ;
686
685
gen_function (
687
686
fun. as_ref ( ) ,
688
687
args,
Original file line number Diff line number Diff line change 80
80
while_true
81
81
) ]
82
82
83
- use std:: convert:: { TryFrom , TryInto } ;
84
-
85
83
use proc_macro2:: TokenStream ;
86
84
use quote:: ToTokens ;
87
85
use syn:: parse:: { Parse , ParseStream } ;
@@ -393,7 +391,7 @@ fn instrument_precise(
393
391
return async_like. gen_async ( args, instrumented_function_name. as_str ( ) ) ;
394
392
}
395
393
396
- let input: MaybeItemFn = input . try_into ( ) ? ;
394
+ let input = MaybeItemFn :: from ( input ) ;
397
395
398
396
Ok ( expand:: gen_function (
399
397
input. as_ref ( ) ,
@@ -446,6 +444,28 @@ impl Parse for MaybeItemFn {
446
444
}
447
445
}
448
446
447
+ impl From < ItemFn > for MaybeItemFn {
448
+ fn from (
449
+ ItemFn {
450
+ attrs,
451
+ vis,
452
+ sig,
453
+ block,
454
+ } : ItemFn ,
455
+ ) -> Self {
456
+ let ( outer_attrs, inner_attrs) = attrs
457
+ . into_iter ( )
458
+ . partition ( |attr| attr. style == syn:: AttrStyle :: Outer ) ;
459
+ Self {
460
+ outer_attrs,
461
+ inner_attrs,
462
+ vis,
463
+ sig,
464
+ block : block. to_token_stream ( ) ,
465
+ }
466
+ }
467
+ }
468
+
449
469
/// A generic reference type for `MaybeItemFn`,
450
470
/// that takes a generic block type `B` that implements `ToTokens` (eg. `TokenStream`, `Block`).
451
471
#[ derive( Debug , Clone ) ]
@@ -456,11 +476,3 @@ struct MaybeItemFnRef<'a, B: ToTokens> {
456
476
sig : & ' a Signature ,
457
477
block : & ' a B ,
458
478
}
459
-
460
- impl TryFrom < ItemFn > for MaybeItemFn {
461
- type Error = syn:: Error ;
462
-
463
- fn try_from ( value : ItemFn ) -> Result < Self , Self :: Error > {
464
- syn:: parse2 ( value. into_token_stream ( ) )
465
- }
466
- }
You can’t perform that action at this time.
0 commit comments