diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:12:43 +0000 |
commit | cf94bdc0742c13e2a0cac864c478b8626b266e1b (patch) | |
tree | 044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /vendor/tracing-attributes/src/lib.rs | |
parent | Adding debian version 1.65.0+dfsg1-2. (diff) | |
download | rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/tracing-attributes/src/lib.rs | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/vendor/tracing-attributes/src/lib.rs b/vendor/tracing-attributes/src/lib.rs index 49b3c794a..f5974e4e5 100644 --- a/vendor/tracing-attributes/src/lib.rs +++ b/vendor/tracing-attributes/src/lib.rs @@ -16,7 +16,7 @@ //! //! ```toml //! [dependencies] -//! tracing-attributes = "0.1.22" +//! tracing-attributes = "0.1.23" //! ``` //! //! The [`#[instrument]`][instrument] attribute can now be added to a function @@ -52,7 +52,7 @@ //! supported compiler version is not considered a semver breaking change as //! long as doing so complies with this policy. //! -#![doc(html_root_url = "https://docs.rs/tracing-attributes/0.1.22")] +#![doc(html_root_url = "https://docs.rs/tracing-attributes/0.1.23")] #![doc( html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png", issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/" @@ -86,7 +86,7 @@ extern crate proc_macro; use proc_macro2::TokenStream; use quote::ToTokens; use syn::parse::{Parse, ParseStream}; -use syn::{Attribute, Block, ItemFn, Signature, Visibility}; +use syn::{Attribute, ItemFn, Signature, Visibility}; mod attr; mod expand; @@ -587,11 +587,13 @@ fn instrument_precise( // check for async_trait-like patterns in the block, and instrument // the future instead of the wrapper if let Some(async_like) = expand::AsyncInfo::from_fn(&input) { - return Ok(async_like.gen_async(args, instrumented_function_name.as_str())); + return async_like.gen_async(args, instrumented_function_name.as_str()); } + let input = MaybeItemFn::from(input); + Ok(expand::gen_function( - (&input).into(), + input.as_ref(), args, instrumented_function_name.as_str(), None, @@ -603,7 +605,8 @@ fn instrument_precise( /// which's block is just a `TokenStream` (it may contain invalid code). #[derive(Debug, Clone)] struct MaybeItemFn { - attrs: Vec<Attribute>, + outer_attrs: Vec<Attribute>, + inner_attrs: Vec<Attribute>, vis: Visibility, sig: Signature, block: TokenStream, @@ -612,7 +615,8 @@ struct MaybeItemFn { impl MaybeItemFn { fn as_ref(&self) -> MaybeItemFnRef<'_, TokenStream> { MaybeItemFnRef { - attrs: &self.attrs, + outer_attrs: &self.outer_attrs, + inner_attrs: &self.inner_attrs, vis: &self.vis, sig: &self.sig, block: &self.block, @@ -624,12 +628,14 @@ impl MaybeItemFn { /// (just like `ItemFn`, but skips parsing the body). impl Parse for MaybeItemFn { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { - let attrs = input.call(syn::Attribute::parse_outer)?; + let outer_attrs = input.call(Attribute::parse_outer)?; let vis: Visibility = input.parse()?; let sig: Signature = input.parse()?; + let inner_attrs = input.call(Attribute::parse_inner)?; let block: TokenStream = input.parse()?; Ok(Self { - attrs, + outer_attrs, + inner_attrs, vis, sig, block, @@ -637,23 +643,35 @@ impl Parse for MaybeItemFn { } } +impl From<ItemFn> for MaybeItemFn { + fn from( + ItemFn { + attrs, + vis, + sig, + block, + }: ItemFn, + ) -> Self { + let (outer_attrs, inner_attrs) = attrs + .into_iter() + .partition(|attr| attr.style == syn::AttrStyle::Outer); + Self { + outer_attrs, + inner_attrs, + vis, + sig, + block: block.to_token_stream(), + } + } +} + /// A generic reference type for `MaybeItemFn`, /// that takes a generic block type `B` that implements `ToTokens` (eg. `TokenStream`, `Block`). #[derive(Debug, Clone)] struct MaybeItemFnRef<'a, B: ToTokens> { - attrs: &'a Vec<Attribute>, + outer_attrs: &'a Vec<Attribute>, + inner_attrs: &'a Vec<Attribute>, vis: &'a Visibility, sig: &'a Signature, block: &'a B, } - -impl<'a> From<&'a ItemFn> for MaybeItemFnRef<'a, Box<Block>> { - fn from(val: &'a ItemFn) -> Self { - MaybeItemFnRef { - attrs: &val.attrs, - vis: &val.vis, - sig: &val.sig, - block: &val.block, - } - } -} |