@@ -409,17 +409,12 @@ fn gen_block(
409
409
let span = ( || {
410
410
// Pull out the arguments-to-be-skipped first, so we can filter results
411
411
// below.
412
- let param_names: Vec < ( Ident , ( Ident , RecordType ) ) > = params
412
+ let param_names: Vec < ( Ident , Ident ) > = params
413
413
. clone ( )
414
414
. into_iter ( )
415
415
. flat_map ( |param| match param {
416
- FnArg :: Typed ( PatType { pat, ty, .. } ) => {
417
- param_names ( * pat, RecordType :: parse_from_ty ( & * ty) )
418
- }
419
- FnArg :: Receiver ( _) => Box :: new ( iter:: once ( (
420
- Ident :: new ( "self" , param. span ( ) ) ,
421
- RecordType :: Debug ,
422
- ) ) ) ,
416
+ FnArg :: Typed ( PatType { pat, .. } ) => param_names ( * pat) ,
417
+ FnArg :: Receiver ( _) => Box :: new ( iter:: once ( Ident :: new ( "self" , param. span ( ) ) ) ) ,
423
418
} )
424
419
// Little dance with new (user-exposed) names and old (internal)
425
420
// names of identifiers. That way, we could do the following
@@ -431,13 +426,13 @@ fn gen_block(
431
426
// async fn foo(&self, v: usize) {}
432
427
// }
433
428
// ```
434
- . map ( |( x , record_type ) | {
429
+ . map ( |x | {
435
430
// if we are inside a function generated by async-trait <=0.1.43, we need to
436
431
// take care to rewrite "_self" as "self" for 'user convenience'
437
432
if self_type. is_some ( ) && x == "_self" {
438
- ( Ident :: new ( "self" , x. span ( ) ) , ( x, record_type ) )
433
+ ( Ident :: new ( "self" , x. span ( ) ) , ( x) )
439
434
} else {
440
- ( x. clone ( ) , ( x, record_type ) )
435
+ ( x. clone ( ) , ( x) )
441
436
}
442
437
} )
443
438
. collect ( ) ;
@@ -471,16 +466,13 @@ fn gen_block(
471
466
true
472
467
}
473
468
} )
474
- . map ( |( user_name, ( real_name, record_type) ) | match record_type {
475
- RecordType :: Value => quote ! ( #user_name = #real_name) ,
476
- RecordType :: Debug => quote ! ( #user_name = tracing:: field:: debug( & #real_name) ) ,
477
- } )
469
+ . map ( |( user_name, real_name) | quote ! ( #user_name = tracing:: __tracing_capture_value!( #real_name) ) )
478
470
. collect ( ) ;
479
471
480
472
// replace every use of a variable with its original name
481
473
if let Some ( Fields ( ref mut fields) ) = args. fields {
482
474
let mut replacer = IdentAndTypesRenamer {
483
- idents : param_names. into_iter ( ) . map ( |( a, ( b , _ ) ) | ( a, b) ) . collect ( ) ,
475
+ idents : param_names. into_iter ( ) . map ( |( a, b ) | ( a, b) ) . collect ( ) ,
484
476
types : Vec :: new ( ) ,
485
477
} ;
486
478
@@ -897,95 +889,20 @@ impl Parse for Level {
897
889
}
898
890
}
899
891
900
- /// Indicates whether a field should be recorded as `Value` or `Debug`.
901
- enum RecordType {
902
- /// The field should be recorded using its `Value` implementation.
903
- Value ,
904
- /// The field should be recorded using `tracing::field::debug()`.
905
- Debug ,
906
- }
907
-
908
- impl RecordType {
909
- /// Array of primitive types which should be recorded as [RecordType::Value].
910
- const TYPES_FOR_VALUE : & ' static [ & ' static str ] = & [
911
- "bool" ,
912
- "str" ,
913
- "u8" ,
914
- "i8" ,
915
- "u16" ,
916
- "i16" ,
917
- "u32" ,
918
- "i32" ,
919
- "u64" ,
920
- "i64" ,
921
- "f32" ,
922
- "f64" ,
923
- "usize" ,
924
- "isize" ,
925
- "NonZeroU8" ,
926
- "NonZeroI8" ,
927
- "NonZeroU16" ,
928
- "NonZeroI16" ,
929
- "NonZeroU32" ,
930
- "NonZeroI32" ,
931
- "NonZeroU64" ,
932
- "NonZeroI64" ,
933
- "NonZeroUsize" ,
934
- "NonZeroIsize" ,
935
- "Wrapping" ,
936
- ] ;
937
-
938
- /// Parse `RecordType` from [syn::Type] by looking up
939
- /// the [RecordType::TYPES_FOR_VALUE] array.
940
- fn parse_from_ty ( ty : & syn:: Type ) -> Self {
941
- match ty {
942
- syn:: Type :: Path ( syn:: TypePath { path, .. } )
943
- if path
944
- . segments
945
- . iter ( )
946
- . last ( )
947
- . map ( |path_segment| {
948
- let ident = path_segment. ident . to_string ( ) ;
949
- Self :: TYPES_FOR_VALUE . iter ( ) . any ( |& t| t == ident)
950
- } )
951
- . unwrap_or ( false ) =>
952
- {
953
- RecordType :: Value
954
- }
955
- syn:: Type :: Reference ( syn:: TypeReference { elem, .. } ) => {
956
- RecordType :: parse_from_ty ( & * elem)
957
- }
958
- _ => RecordType :: Debug ,
959
- }
960
- }
961
- }
962
-
963
- fn param_names ( pat : Pat , record_type : RecordType ) -> Box < dyn Iterator < Item = ( Ident , RecordType ) > > {
892
+ fn param_names ( pat : Pat ) -> Box < dyn Iterator < Item = Ident > > {
964
893
match pat {
965
- Pat :: Ident ( PatIdent { ident, .. } ) => Box :: new ( iter:: once ( ( ident, record_type) ) ) ,
966
- Pat :: Reference ( PatReference { pat, .. } ) => param_names ( * pat, record_type) ,
967
- // We can't get the concrete type of fields in the struct/tuple
968
- // patterns by using `syn`. e.g. `fn foo(Foo { x, y }: Foo) {}`.
969
- // Therefore, the struct/tuple patterns in the arguments will just
970
- // always be recorded as `RecordType::Debug`.
894
+ Pat :: Ident ( PatIdent { ident, .. } ) => Box :: new ( iter:: once ( ident) ) ,
895
+ Pat :: Reference ( PatReference { pat, .. } ) => param_names ( * pat) ,
971
896
Pat :: Struct ( PatStruct { fields, .. } ) => Box :: new (
972
897
fields
973
898
. into_iter ( )
974
- . flat_map ( |FieldPat { pat, .. } | param_names ( * pat, RecordType :: Debug ) ) ,
975
- ) ,
976
- Pat :: Tuple ( PatTuple { elems, .. } ) => Box :: new (
977
- elems
978
- . into_iter ( )
979
- . flat_map ( |p| param_names ( p, RecordType :: Debug ) ) ,
899
+ . flat_map ( |FieldPat { pat, .. } | param_names ( * pat) ) ,
980
900
) ,
901
+ Pat :: Tuple ( PatTuple { elems, .. } ) => Box :: new ( elems. into_iter ( ) . flat_map ( param_names) ) ,
981
902
Pat :: TupleStruct ( PatTupleStruct {
982
903
pat : PatTuple { elems, .. } ,
983
904
..
984
- } ) => Box :: new (
985
- elems
986
- . into_iter ( )
987
- . flat_map ( |p| param_names ( p, RecordType :: Debug ) ) ,
988
- ) ,
905
+ } ) => Box :: new ( elems. into_iter ( ) . flat_map ( param_names) ) ,
989
906
990
907
// The above *should* cover all cases of irrefutable patterns,
991
908
// but we purposefully don't do any funny business here
0 commit comments