@@ -92,17 +92,12 @@ fn gen_block<B: ToTokens>(
92
92
let span = ( || {
93
93
// Pull out the arguments-to-be-skipped first, so we can filter results
94
94
// below.
95
- let param_names: Vec < ( Ident , ( Ident , RecordType ) ) > = params
95
+ let param_names: Vec < ( Ident , Ident ) > = params
96
96
. clone ( )
97
97
. into_iter ( )
98
98
. flat_map ( |param| match param {
99
- FnArg :: Typed ( PatType { pat, ty, .. } ) => {
100
- param_names ( * pat, RecordType :: parse_from_ty ( & * ty) )
101
- }
102
- FnArg :: Receiver ( _) => Box :: new ( iter:: once ( (
103
- Ident :: new ( "self" , param. span ( ) ) ,
104
- RecordType :: Debug ,
105
- ) ) ) ,
99
+ FnArg :: Typed ( PatType { pat, .. } ) => param_names ( * pat) ,
100
+ FnArg :: Receiver ( _) => Box :: new ( iter:: once ( Ident :: new ( "self" , param. span ( ) ) ) ) ,
106
101
} )
107
102
// Little dance with new (user-exposed) names and old (internal)
108
103
// names of identifiers. That way, we could do the following
@@ -114,13 +109,13 @@ fn gen_block<B: ToTokens>(
114
109
// async fn foo(&self, v: usize) {}
115
110
// }
116
111
// ```
117
- . map ( |( x , record_type ) | {
112
+ . map ( |x | {
118
113
// if we are inside a function generated by async-trait <=0.1.43, we need to
119
114
// take care to rewrite "_self" as "self" for 'user convenience'
120
115
if self_type. is_some ( ) && x == "_self" {
121
- ( Ident :: new ( "self" , x. span ( ) ) , ( x , record_type ) )
116
+ ( Ident :: new ( "self" , x. span ( ) ) , x )
122
117
} else {
123
- ( x. clone ( ) , ( x , record_type ) )
118
+ ( x. clone ( ) , x )
124
119
}
125
120
} )
126
121
. collect ( ) ;
@@ -154,16 +149,13 @@ fn gen_block<B: ToTokens>(
154
149
true
155
150
}
156
151
} )
157
- . map ( |( user_name, ( real_name, record_type) ) | match record_type {
158
- RecordType :: Value => quote ! ( #user_name = #real_name) ,
159
- RecordType :: Debug => quote ! ( #user_name = tracing:: field:: debug( & #real_name) ) ,
160
- } )
152
+ . map ( |( user_name, real_name) | quote ! ( #user_name = tracing:: __tracing_capture_value!( #real_name) ) )
161
153
. collect ( ) ;
162
154
163
155
// replace every use of a variable with its original name
164
156
if let Some ( Fields ( ref mut fields) ) = args. fields {
165
157
let mut replacer = IdentAndTypesRenamer {
166
- idents : param_names. into_iter ( ) . map ( | ( a , ( b , _ ) ) | ( a , b ) ) . collect ( ) ,
158
+ idents : param_names,
167
159
types : Vec :: new ( ) ,
168
160
} ;
169
161
@@ -284,95 +276,24 @@ fn gen_block<B: ToTokens>(
284
276
)
285
277
}
286
278
287
- /// Indicates whether a field should be recorded as `Value` or `Debug`.
288
- enum RecordType {
289
- /// The field should be recorded using its `Value` implementation.
290
- Value ,
291
- /// The field should be recorded using `tracing::field::debug()`.
292
- Debug ,
293
- }
294
-
295
- impl RecordType {
296
- /// Array of primitive types which should be recorded as [RecordType::Value].
297
- const TYPES_FOR_VALUE : & ' static [ & ' static str ] = & [
298
- "bool" ,
299
- "str" ,
300
- "u8" ,
301
- "i8" ,
302
- "u16" ,
303
- "i16" ,
304
- "u32" ,
305
- "i32" ,
306
- "u64" ,
307
- "i64" ,
308
- "f32" ,
309
- "f64" ,
310
- "usize" ,
311
- "isize" ,
312
- "NonZeroU8" ,
313
- "NonZeroI8" ,
314
- "NonZeroU16" ,
315
- "NonZeroI16" ,
316
- "NonZeroU32" ,
317
- "NonZeroI32" ,
318
- "NonZeroU64" ,
319
- "NonZeroI64" ,
320
- "NonZeroUsize" ,
321
- "NonZeroIsize" ,
322
- "Wrapping" ,
323
- ] ;
324
-
325
- /// Parse `RecordType` from [syn::Type] by looking up
326
- /// the [RecordType::TYPES_FOR_VALUE] array.
327
- fn parse_from_ty ( ty : & syn:: Type ) -> Self {
328
- match ty {
329
- syn:: Type :: Path ( syn:: TypePath { path, .. } )
330
- if path
331
- . segments
332
- . iter ( )
333
- . last ( )
334
- . map ( |path_segment| {
335
- let ident = path_segment. ident . to_string ( ) ;
336
- Self :: TYPES_FOR_VALUE . iter ( ) . any ( |& t| t == ident)
337
- } )
338
- . unwrap_or ( false ) =>
339
- {
340
- RecordType :: Value
341
- }
342
- syn:: Type :: Reference ( syn:: TypeReference { elem, .. } ) => {
343
- RecordType :: parse_from_ty ( & * elem)
344
- }
345
- _ => RecordType :: Debug ,
346
- }
347
- }
348
- }
349
-
350
- fn param_names ( pat : Pat , record_type : RecordType ) -> Box < dyn Iterator < Item = ( Ident , RecordType ) > > {
279
+ fn param_names ( pat : Pat ) -> Box < dyn Iterator < Item = Ident > > {
351
280
match pat {
352
- Pat :: Ident ( PatIdent { ident, .. } ) => Box :: new ( iter:: once ( ( ident, record_type ) ) ) ,
353
- Pat :: Reference ( PatReference { pat, .. } ) => param_names ( * pat, record_type ) ,
281
+ Pat :: Ident ( PatIdent { ident, .. } ) => Box :: new ( iter:: once ( ident) ) ,
282
+ Pat :: Reference ( PatReference { pat, .. } ) => param_names ( * pat) ,
354
283
// We can't get the concrete type of fields in the struct/tuple
355
284
// patterns by using `syn`. e.g. `fn foo(Foo { x, y }: Foo) {}`.
356
285
// Therefore, the struct/tuple patterns in the arguments will just
357
286
// always be recorded as `RecordType::Debug`.
358
287
Pat :: Struct ( PatStruct { fields, .. } ) => Box :: new (
359
288
fields
360
289
. into_iter ( )
361
- . flat_map ( |FieldPat { pat, .. } | param_names ( * pat, RecordType :: Debug ) ) ,
362
- ) ,
363
- Pat :: Tuple ( PatTuple { elems, .. } ) => Box :: new (
364
- elems
365
- . into_iter ( )
366
- . flat_map ( |p| param_names ( p, RecordType :: Debug ) ) ,
290
+ . flat_map ( |FieldPat { pat, .. } | param_names ( * pat) ) ,
367
291
) ,
292
+ Pat :: Tuple ( PatTuple { elems, .. } ) => Box :: new ( elems. into_iter ( ) . flat_map ( param_names) ) ,
368
293
Pat :: TupleStruct ( PatTupleStruct {
369
294
pat : PatTuple { elems, .. } ,
370
295
..
371
- } ) => Box :: new (
372
- elems
373
- . into_iter ( )
374
- . flat_map ( |p| param_names ( p, RecordType :: Debug ) ) ,
375
- ) ,
296
+ } ) => Box :: new ( elems. into_iter ( ) . flat_map ( param_names) ) ,
376
297
377
298
// The above *should* cover all cases of irrefutable patterns,
378
299
// but we purposefully don't do any funny business here
0 commit comments