mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-12-15 20:59:41 +00:00
This pull request adds support to the `#[instrument]` macro for destructured arguments. ## Motivation The `#[instrument]` macro automatically adds function arguments as fields on the `Span`. Previously, it would only do so for "plain" `Ident` argument types, but would ignore destructured arguments. ## Solution By recursively pattern matching each argument to find all identifiers it creates, we can construct an authoritative list of all input names. * attributes: extract param_names extractor To enable the recursion needed to extract all the various destructured parameter types. * attributes: support destructured tuple arguments * attributes: support destructured ref arguments * attributes: support destructured tuple struct arguments * attributes: support destructured struct arguments * attributes: add crazy destructuring test This is to test the combination of all the supported function argument destructuring types. * attributes: move destructuring tests to their own file * attributes: apply cargo fmt * attributes: add helpful comment to pattern pattern match Since function signatures can only use irrefutable patterns, we can be confident that no legal code will have any other variant of `syn::Pat` than the ones we match on. However, to prevent anyone else from going down the rabbit hole of wondering about it, we add a helpful comment. * attributes: support self argument as span field