diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index 7005b4423e..cb12ad87e4 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -134,7 +134,7 @@ fn gen_block( .into_iter() .flat_map(|param| match param { FnArg::Typed(PatType { pat, ty, .. }) => { - param_names(*pat, RecordType::parse_from_ty(&*ty)) + param_names(*pat, RecordType::parse_from_ty(&ty)) } FnArg::Receiver(_) => Box::new(iter::once(( Ident::new("self", param.span()), diff --git a/tracing-core/src/dispatcher.rs b/tracing-core/src/dispatcher.rs index 36b3cfd85f..7f2f4060aa 100644 --- a/tracing-core/src/dispatcher.rs +++ b/tracing-core/src/dispatcher.rs @@ -368,7 +368,7 @@ where CURRENT_STATE .try_with(|state| { if let Some(entered) = state.enter() { - return f(&*entered.current()); + return f(&entered.current()); } f(&Dispatch::none()) @@ -390,7 +390,7 @@ pub fn get_current(f: impl FnOnce(&Dispatch) -> T) -> Option { CURRENT_STATE .try_with(|state| { let entered = state.enter()?; - Some(f(&*entered.current())) + Some(f(&entered.current())) }) .ok()? } diff --git a/tracing-futures/src/executor/mod.rs b/tracing-futures/src/executor/mod.rs index 442b523b84..ced3b5a460 100644 --- a/tracing-futures/src/executor/mod.rs +++ b/tracing-futures/src/executor/mod.rs @@ -1,7 +1,5 @@ #[cfg(feature = "futures-01")] mod futures_01; -#[cfg(feature = "futures-01")] -pub use self::futures_01::*; #[cfg(feature = "futures_preview")] mod futures_preview; diff --git a/tracing-subscriber/benches/support/mod.rs b/tracing-subscriber/benches/support/mod.rs index 25e9e7e229..3abaa807aa 100644 --- a/tracing-subscriber/benches/support/mod.rs +++ b/tracing-subscriber/benches/support/mod.rs @@ -33,7 +33,7 @@ impl MultithreadedBench { thread::spawn(move || { let dispatch = this.dispatch.clone(); tracing::dispatcher::with_default(&dispatch, move || { - f(&*this.start); + f(&this.start); this.end.wait(); }) }); diff --git a/tracing-subscriber/src/filter/layer_filters/mod.rs b/tracing-subscriber/src/filter/layer_filters/mod.rs index e50ee6f007..74f56e8ae6 100644 --- a/tracing-subscriber/src/filter/layer_filters/mod.rs +++ b/tracing-subscriber/src/filter/layer_filters/mod.rs @@ -478,6 +478,36 @@ macro_rules! filter_impl_body { fn max_level_hint(&self) -> Option { self.deref().max_level_hint() } + + #[inline] + fn event_enabled(&self, event: &Event<'_>, cx: &Context<'_, S>) -> bool { + self.deref().event_enabled(event, cx) + } + + #[inline] + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_new_span(attrs, id, ctx) + } + + #[inline] + fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) { + self.deref().on_record(id, values, ctx) + } + + #[inline] + fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_enter(id, ctx) + } + + #[inline] + fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_exit(id, ctx) + } + + #[inline] + fn on_close(&self, id: span::Id, ctx: Context<'_, S>) { + self.deref().on_close(id, ctx) + } }; } @@ -493,6 +523,75 @@ impl layer::Filter for Box + Send + Sync + 'static> { filter_impl_body!(); } +// Implement Filter for Option where None => allow +#[cfg(feature = "registry")] +#[cfg_attr(docsrs, doc(cfg(feature = "registry")))] +impl layer::Filter for Option +where + F: layer::Filter, +{ + #[inline] + fn enabled(&self, meta: &Metadata<'_>, ctx: &Context<'_, S>) -> bool { + self.as_ref() + .map(|inner| inner.enabled(meta, ctx)) + .unwrap_or(true) + } + + #[inline] + fn callsite_enabled(&self, meta: &'static Metadata<'static>) -> Interest { + self.as_ref() + .map(|inner| inner.callsite_enabled(meta)) + .unwrap_or_else(Interest::sometimes) + } + + #[inline] + fn max_level_hint(&self) -> Option { + self.as_ref().and_then(|inner| inner.max_level_hint()) + } + + #[inline] + fn event_enabled(&self, event: &Event<'_>, ctx: &Context<'_, S>) -> bool { + self.as_ref() + .map(|inner| inner.event_enabled(event, ctx)) + .unwrap_or(true) + } + + #[inline] + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_new_span(attrs, id, ctx) + } + } + + #[inline] + fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_record(id, values, ctx) + } + } + + #[inline] + fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_enter(id, ctx) + } + } + + #[inline] + fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_exit(id, ctx) + } + } + + #[inline] + fn on_close(&self, id: span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_close(id, ctx) + } + } +} + // === impl Filtered === impl Filtered { diff --git a/tracing-subscriber/src/fmt/format/json.rs b/tracing-subscriber/src/fmt/format/json.rs index c2f4d37553..bf32f7c9a8 100644 --- a/tracing-subscriber/src/fmt/format/json.rs +++ b/tracing-subscriber/src/fmt/format/json.rs @@ -720,7 +720,7 @@ mod test { ); let span = tracing::info_span!("the span", na = tracing::field::Empty); - span.record("na", &"value"); + span.record("na", "value"); let _enter = span.enter(); tracing::info!("an event inside the root span"); diff --git a/tracing-subscriber/src/layer/mod.rs b/tracing-subscriber/src/layer/mod.rs index bdc154301a..33d5bf6569 100644 --- a/tracing-subscriber/src/layer/mod.rs +++ b/tracing-subscriber/src/layer/mod.rs @@ -462,11 +462,13 @@ //! //! This crate's [`filter`] module provides a number of types which implement //! the [`Filter`] trait, such as [`LevelFilter`], [`Targets`], and -//! [`FilterFn`]. These [`Filter`]s provide ready-made implementations of -//! common forms of filtering. For custom filtering policies, the [`FilterFn`] -//! and [`DynFilterFn`] types allow implementing a [`Filter`] with a closure or +//! [`FilterFn`]. These [`Filter`]s provide ready-made implementations of common +//! forms of filtering. For custom filtering policies, the [`FilterFn`] and +//! [`DynFilterFn`] types allow implementing a [`Filter`] with a closure or //! function pointer. In addition, when more control is required, the [`Filter`] -//! trait may also be implemented for user-defined types. +//! trait may also be implemented for user-defined types. [`Option`] +//! also implements [`Filter`], where [`None`](Option::None) doesn't filter +//! anything (that is, it allows everything). //! //!
 //!     Warning: Currently, the 
diff --git a/tracing-subscriber/src/registry/sharded.rs b/tracing-subscriber/src/registry/sharded.rs
index 7978997678..88520a2a66 100644
--- a/tracing-subscriber/src/registry/sharded.rs
+++ b/tracing-subscriber/src/registry/sharded.rs
@@ -422,7 +422,7 @@ impl<'a> SpanData<'a> for Data<'a> {
     }
 
     fn metadata(&self) -> &'static Metadata<'static> {
-        (*self).inner.metadata
+        self.inner.metadata
     }
 
     fn parent(&self) -> Option<&Id> {
@@ -902,7 +902,7 @@ mod tests {
 
             drop(span3);
 
-            state.assert_closed_in_order(&["child", "parent", "grandparent"]);
+            state.assert_closed_in_order(["child", "parent", "grandparent"]);
         });
     }
 }
diff --git a/tracing-subscriber/tests/field_filter.rs b/tracing-subscriber/tests/field_filter.rs
index f14a0626d3..385d024f65 100644
--- a/tracing-subscriber/tests/field_filter.rs
+++ b/tracing-subscriber/tests/field_filter.rs
@@ -103,7 +103,7 @@ fn record_after_created() {
             tracing::debug!("i'm disabled!");
         });
 
-        span.record("enabled", &true);
+        span.record("enabled", true);
         span.in_scope(|| {
             tracing::debug!("i'm enabled!");
         });
diff --git a/tracing-subscriber/tests/layer_filters/main.rs b/tracing-subscriber/tests/layer_filters/main.rs
index 10f06c24c6..0dc605a6d2 100644
--- a/tracing-subscriber/tests/layer_filters/main.rs
+++ b/tracing-subscriber/tests/layer_filters/main.rs
@@ -5,6 +5,7 @@ use self::support::*;
 mod boxed;
 mod downcast_raw;
 mod filter_scopes;
+mod option;
 mod per_event;
 mod targets;
 mod trees;
diff --git a/tracing-subscriber/tests/layer_filters/option.rs b/tracing-subscriber/tests/layer_filters/option.rs
new file mode 100644
index 0000000000..bcb980aab3
--- /dev/null
+++ b/tracing-subscriber/tests/layer_filters/option.rs
@@ -0,0 +1,40 @@
+use super::*;
+use tracing_subscriber::{filter, prelude::*, Layer};
+
+fn filter() -> filter::DynFilterFn {
+    // Use dynamic filter fn to disable interest caching and max-level hints,
+    // allowing us to put all of these tests in the same file.
+    filter::dynamic_filter_fn(|_, _| false)
+}
+
+#[test]
+fn option_some() {
+    let (layer, handle) = layer::mock().done().run_with_handle();
+    let layer = Box::new(layer.with_filter(Some(filter())));
+
+    let _guard = tracing_subscriber::registry().with(layer).set_default();
+
+    for i in 0..2 {
+        tracing::info!(i);
+    }
+
+    handle.assert_finished();
+}
+
+#[test]
+fn option_none() {
+    let (layer, handle) = layer::mock()
+        .event(event::mock())
+        .event(event::mock())
+        .done()
+        .run_with_handle();
+    let layer = Box::new(layer.with_filter(None::>));
+
+    let _guard = tracing_subscriber::registry().with(layer).set_default();
+
+    for i in 0..2 {
+        tracing::info!(i);
+    }
+
+    handle.assert_finished();
+}
diff --git a/tracing/src/span.rs b/tracing/src/span.rs
index 58822f4d9b..7be56abdf5 100644
--- a/tracing/src/span.rs
+++ b/tracing/src/span.rs
@@ -1617,7 +1617,7 @@ mod test {
 
     #[test]
     fn test_record_backwards_compat() {
-        Span::current().record("some-key", &"some text");
-        Span::current().record("some-key", &false);
+        Span::current().record("some-key", "some text");
+        Span::current().record("some-key", false);
     }
 }
diff --git a/tracing/tests/span.rs b/tracing/tests/span.rs
index 4ed6500235..b148f7317b 100644
--- a/tracing/tests/span.rs
+++ b/tracing/tests/span.rs
@@ -563,7 +563,7 @@ fn record_new_value_for_field() {
 
     with_default(subscriber, || {
         let span = tracing::span!(Level::TRACE, "foo", bar = 5, baz = false);
-        span.record("baz", &true);
+        span.record("baz", true);
         span.in_scope(|| {})
     });
 
@@ -598,8 +598,8 @@ fn record_new_values_for_fields() {
 
     with_default(subscriber, || {
         let span = tracing::span!(Level::TRACE, "foo", bar = 4, baz = false);
-        span.record("bar", &5);
-        span.record("baz", &true);
+        span.record("bar", 5);
+        span.record("baz", true);
         span.in_scope(|| {})
     });