diff --git a/tracing-attributes/CHANGELOG.md b/tracing-attributes/CHANGELOG.md index 3cb95f70f..7a9aa7783 100644 --- a/tracing-attributes/CHANGELOG.md +++ b/tracing-attributes/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.1.28 (Unreleased) + +### Fixed + +- Globally qualify attribute paths to avoid ambiguities ([#3119]) + # 0.1.27 (October 13, 2023) ### Changed diff --git a/tracing-attributes/Cargo.toml b/tracing-attributes/Cargo.toml index 6dff74311..fd469a7a5 100644 --- a/tracing-attributes/Cargo.toml +++ b/tracing-attributes/Cargo.toml @@ -8,7 +8,7 @@ name = "tracing-attributes" # - README.md # - Update CHANGELOG.md. # - Create "v0.1.x" git tag. -version = "0.1.27" +version = "0.1.28" authors = [ "Tokio Contributors ", "Eliza Weisman ", diff --git a/tracing-attributes/src/attr.rs b/tracing-attributes/src/attr.rs index 8b4526164..6d8013090 100644 --- a/tracing-attributes/src/attr.rs +++ b/tracing-attributes/src/attr.rs @@ -352,7 +352,7 @@ impl ToTokens for Field { // `instrument` produce empty field values, so changing it now // is a breaking change. agh. let name = &self.name; - tokens.extend(quote!(#name = tracing::field::Empty)) + tokens.extend(quote!(#name = ::tracing::field::Empty)) } else { self.kind.to_tokens(tokens); self.name.to_tokens(tokens); @@ -428,11 +428,11 @@ impl Parse for Level { impl ToTokens for Level { fn to_tokens(&self, tokens: &mut TokenStream) { match self { - Level::Trace => tokens.extend(quote!(tracing::Level::TRACE)), - Level::Debug => tokens.extend(quote!(tracing::Level::DEBUG)), - Level::Info => tokens.extend(quote!(tracing::Level::INFO)), - Level::Warn => tokens.extend(quote!(tracing::Level::WARN)), - Level::Error => tokens.extend(quote!(tracing::Level::ERROR)), + Level::Trace => tokens.extend(quote!(::tracing::Level::TRACE)), + Level::Debug => tokens.extend(quote!(::tracing::Level::DEBUG)), + Level::Info => tokens.extend(quote!(::tracing::Level::INFO)), + Level::Warn => tokens.extend(quote!(::tracing::Level::WARN)), + Level::Error => tokens.extend(quote!(::tracing::Level::ERROR)), Level::Path(ref pat) => tokens.extend(quote!(#pat)), } } diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index 864bace8e..8ff05589d 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -199,7 +199,7 @@ fn gen_block( }) .map(|(user_name, (real_name, record_type))| match record_type { RecordType::Value => quote!(#user_name = #real_name), - RecordType::Debug => quote!(#user_name = tracing::field::debug(&#real_name)), + RecordType::Debug => quote!(#user_name = ::tracing::field::debug(&#real_name)), }) .collect(); @@ -223,7 +223,7 @@ fn gen_block( let custom_fields = &args.fields; - quote!(tracing::span!( + quote!(::tracing::span!( target: #target, #(parent: #parent,)* #level, @@ -241,10 +241,10 @@ fn gen_block( let level_tokens = event_args.level(Level::Error); match event_args.mode { FormatMode::Default | FormatMode::Display => Some(quote!( - tracing::event!(target: #target, #level_tokens, error = %e) + ::tracing::event!(target: #target, #level_tokens, error = %e) )), FormatMode::Debug => Some(quote!( - tracing::event!(target: #target, #level_tokens, error = ?e) + ::tracing::event!(target: #target, #level_tokens, error = ?e) )), } } @@ -256,10 +256,10 @@ fn gen_block( let level_tokens = event_args.level(args_level); match event_args.mode { FormatMode::Display => Some(quote!( - tracing::event!(target: #target, #level_tokens, return = %x) + ::tracing::event!(target: #target, #level_tokens, return = %x) )), FormatMode::Default | FormatMode::Debug => Some(quote!( - tracing::event!(target: #target, #level_tokens, return = ?x) + ::tracing::event!(target: #target, #level_tokens, return = ?x) )), } } @@ -320,7 +320,7 @@ fn gen_block( let __tracing_instrument_future = #mk_fut; if !__tracing_attr_span.is_disabled() { #follows_from - tracing::Instrument::instrument( + ::tracing::Instrument::instrument( __tracing_instrument_future, __tracing_attr_span ) @@ -344,7 +344,7 @@ fn gen_block( // regression in case the level is enabled. let __tracing_attr_span; let __tracing_attr_guard; - if tracing::level_enabled!(#level) || tracing::if_log_enabled!(#level, {true} else {false}) { + if ::tracing::level_enabled!(#level) || ::tracing::if_log_enabled!(#level, {true} else {false}) { __tracing_attr_span = #span; #follows_from __tracing_attr_guard = __tracing_attr_span.enter(); @@ -724,7 +724,7 @@ impl<'block> AsyncInfo<'block> { let async_attrs = &async_expr.attrs; if pinned_box { quote! { - Box::pin(#(#async_attrs) * async move { #instrumented_block }) + ::std::boxed::Box::pin(#(#async_attrs) * async move { #instrumented_block }) } } else { quote! { diff --git a/tracing-attributes/tests/instrument.rs b/tracing-attributes/tests/instrument.rs index c5e816045..f47441cdf 100644 --- a/tracing-attributes/tests/instrument.rs +++ b/tracing-attributes/tests/instrument.rs @@ -252,3 +252,21 @@ fn impl_trait_return_type() { handle.assert_finished(); } + +#[test] +fn user_tracing_module() { + use ::tracing::field::Empty; + + // Reproduces https://github.com/tokio-rs/tracing/issues/3119 + #[instrument(fields(f = Empty))] + fn my_fn() { + assert_eq!("test", tracing::my_other_fn()); + } + + mod tracing { + #[allow(dead_code)] + pub fn my_other_fn() -> &'static str { + "test" + } + } +}