From 558871403d25ce0aea8ecfe89d13293d9fa06391 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 3 Apr 2022 06:15:26 -0500 Subject: [PATCH] Add lifetime to field::Visit Partially an exercise in "how bad would it be?" This allows the removal of the unsafety in tracing-log's LogVisitor (see next commit), as well as generalization of NormalizeEvent to more RecordField containers. --- examples/examples/counters.rs | 2 +- .../examples/sloggish/sloggish_collector.rs | 4 +- tracing-core/src/event.rs | 2 +- tracing-core/src/field.rs | 52 ++++++----- tracing-core/src/span.rs | 4 +- tracing-error/src/subscriber.rs | 4 +- tracing-journald/src/lib.rs | 4 +- tracing-log/src/lib.rs | 2 +- tracing-mock/src/field.rs | 4 +- tracing-opentelemetry/src/subscriber.rs | 4 +- tracing-serde/src/lib.rs | 4 +- tracing-subscriber/src/field/debug.rs | 22 ++--- tracing-subscriber/src/field/delimited.rs | 24 +++--- tracing-subscriber/src/field/display.rs | 22 ++--- tracing-subscriber/src/field/mod.rs | 86 +++++++++---------- tracing-subscriber/src/filter/env/field.rs | 2 +- tracing-subscriber/src/fmt/fmt_subscriber.rs | 20 ++--- tracing-subscriber/src/fmt/format/json.rs | 28 +++--- tracing-subscriber/src/fmt/format/mod.rs | 54 +++++++----- tracing-subscriber/src/fmt/format/pretty.rs | 24 +++--- tracing-subscriber/src/fmt/mod.rs | 16 ++-- tracing/benches/subscriber.rs | 2 +- tracing/src/lib.rs | 2 +- 23 files changed, 206 insertions(+), 182 deletions(-) diff --git a/examples/examples/counters.rs b/examples/examples/counters.rs index d5674e445d..ab6ceb228a 100644 --- a/examples/examples/counters.rs +++ b/examples/examples/counters.rs @@ -29,7 +29,7 @@ struct Count<'a> { counters: RwLockReadGuard<'a, HashMap>, } -impl<'a> Visit for Count<'a> { +impl<'a> Visit<'_> for Count<'a> { fn record_i64(&mut self, field: &Field, value: i64) { if let Some(counter) = self.counters.get(field.name()) { if value > 0 { diff --git a/examples/examples/sloggish/sloggish_collector.rs b/examples/examples/sloggish/sloggish_collector.rs index 91937fe05c..eb3b14ad62 100644 --- a/examples/examples/sloggish/sloggish_collector.rs +++ b/examples/examples/sloggish/sloggish_collector.rs @@ -101,13 +101,13 @@ impl Span { } } -impl Visit for Span { +impl Visit<'_> for Span { fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { self.kvs.push((field.name(), format!("{:?}", value))) } } -impl<'a> Visit for Event<'a> { +impl<'a> Visit<'_> for Event<'a> { fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { write!( &mut self.stderr, diff --git a/tracing-core/src/event.rs b/tracing-core/src/event.rs index 70bd6658ca..74869f12ae 100644 --- a/tracing-core/src/event.rs +++ b/tracing-core/src/event.rs @@ -83,7 +83,7 @@ impl<'a> Event<'a> { /// /// [visitor]: super::field::Visit #[inline] - pub fn record(&self, visitor: &mut dyn field::Visit) { + pub fn record(&self, visitor: &mut dyn field::Visit<'a>) { self.fields.record(visitor); } diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index 58f94d6c8e..2b763515c7 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -114,7 +114,7 @@ pub struct Iter { /// string: &'a mut String, /// } /// -/// impl<'a> Visit for StringVisitor<'a> { +/// impl<'a> Visit<'_> for StringVisitor<'a> { /// fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { /// write!(self.string, "{} = {:?}; ", field.name(), value).unwrap(); /// } @@ -145,7 +145,7 @@ pub struct Iter { /// sum: i64, /// } /// -/// impl Visit for SumVisitor { +/// impl Visit<'_> for SumVisitor { /// fn record_i64(&mut self, _field: &Field, value: i64) { /// self.sum += value; /// } @@ -178,7 +178,7 @@ pub struct Iter { /// [records an `Event`]: super::collect::Collect::event /// [set of `Value`s added to a `Span`]: super::collect::Collect::record /// [`Event`]: super::event::Event -pub trait Visit { +pub trait Visit<'a> { /// Visit a double-precision floating point value. fn record_f64(&mut self, field: &Field, value: f64) { self.record_debug(field, &value) @@ -200,7 +200,7 @@ pub trait Visit { } /// Visit a string value. - fn record_str(&mut self, field: &Field, value: &str) { + fn record_str(&mut self, field: &Field, value: &'a str) { self.record_debug(field, &value) } @@ -230,7 +230,7 @@ pub trait Visit { /// [visitor]: Visit pub trait Value: crate::sealed::Sealed { /// Visits this value with the given `Visitor`. - fn record(&self, key: &Field, visitor: &mut dyn Visit); + fn record<'a>(&'a self, key: &Field, visitor: &mut dyn Visit<'a>); } /// A `Value` which serializes using `fmt::Display`. @@ -264,19 +264,19 @@ where // ===== impl Visit ===== -impl<'a, 'b> Visit for fmt::DebugStruct<'a, 'b> { +impl<'a, 'b> Visit<'_> for fmt::DebugStruct<'a, 'b> { fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { self.field(field.name(), value); } } -impl<'a, 'b> Visit for fmt::DebugMap<'a, 'b> { +impl<'a, 'b> Visit<'_> for fmt::DebugMap<'a, 'b> { fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { self.entry(&format_args!("{}", field), value); } } -impl Visit for F +impl Visit<'_> for F where F: FnMut(&Field, &dyn fmt::Debug), { @@ -351,7 +351,11 @@ macro_rules! impl_one_value { (normal, $value_ty:tt, $op:expr, $record:ident) => { impl $crate::sealed::Sealed for $value_ty {} impl $crate::field::Value for $value_ty { - fn record(&self, key: &$crate::field::Field, visitor: &mut dyn $crate::field::Visit) { + fn record( + &self, + key: &$crate::field::Field, + visitor: &mut dyn $crate::field::Visit<'_>, + ) { visitor.$record(key, $op(*self)) } } @@ -366,7 +370,11 @@ macro_rules! impl_one_value { use num::*; impl $crate::sealed::Sealed for ty_to_nonzero!($value_ty) {} impl $crate::field::Value for ty_to_nonzero!($value_ty) { - fn record(&self, key: &$crate::field::Field, visitor: &mut dyn $crate::field::Visit) { + fn record( + &self, + key: &$crate::field::Field, + visitor: &mut dyn $crate::field::Visit<'_>, + ) { visitor.$record(key, $op(self.get())) } } @@ -399,7 +407,7 @@ impl_values! { impl crate::sealed::Sealed for Wrapping {} impl crate::field::Value for Wrapping { - fn record(&self, key: &crate::field::Field, visitor: &mut dyn crate::field::Visit) { + fn record<'a>(&'a self, key: &crate::field::Field, visitor: &mut dyn crate::field::Visit<'a>) { self.0.record(key, visitor) } } @@ -407,7 +415,7 @@ impl crate::field::Value for Wrapping { impl crate::sealed::Sealed for str {} impl Value for str { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record<'a>(&'a self, key: &Field, visitor: &mut dyn Visit<'a>) { visitor.record_str(key, self) } } @@ -418,7 +426,7 @@ impl crate::sealed::Sealed for dyn std::error::Error + 'static {} #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl Value for dyn std::error::Error + 'static { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record<'a>(&'a self, key: &Field, visitor: &mut dyn Visit<'a>) { visitor.record_error(key, self) } } @@ -429,7 +437,7 @@ impl<'a, T: ?Sized> Value for &'a T where T: Value + 'a, { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record<'visit>(&'visit self, key: &Field, visitor: &mut dyn Visit<'visit>) { (*self).record(key, visitor) } } @@ -440,7 +448,7 @@ impl<'a, T: ?Sized> Value for &'a mut T where T: Value + 'a, { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record<'visit>(&'visit self, key: &Field, visitor: &mut dyn Visit<'visit>) { // Don't use `(*self).record(key, visitor)`, otherwise would // cause stack overflow due to `unconditional_recursion`. T::record(self, key, visitor) @@ -450,7 +458,7 @@ where impl<'a> crate::sealed::Sealed for fmt::Arguments<'a> {} impl<'a> Value for fmt::Arguments<'a> { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record<'visit>(&'visit self, key: &Field, visitor: &mut dyn Visit<'visit>) { visitor.record_debug(key, self) } } @@ -498,7 +506,7 @@ impl Value for DisplayValue where T: fmt::Display, { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record(&self, key: &Field, visitor: &mut dyn Visit<'_>) { visitor.record_debug(key, self) } } @@ -523,7 +531,7 @@ impl Value for DebugValue where T: fmt::Debug, { - fn record(&self, key: &Field, visitor: &mut dyn Visit) { + fn record(&self, key: &Field, visitor: &mut dyn Visit<'_>) { visitor.record_debug(key, &self.0) } } @@ -537,7 +545,7 @@ impl fmt::Debug for DebugValue { impl crate::sealed::Sealed for Empty {} impl Value for Empty { #[inline] - fn record(&self, _: &Field, _: &mut dyn Visit) {} + fn record(&self, _: &Field, _: &mut dyn Visit<'_>) {} } // ===== impl Field ===== @@ -748,7 +756,7 @@ impl<'a> ValueSet<'a> { /// Visits all the fields in this `ValueSet` with the provided [visitor]. /// /// [visitor]: Visit - pub fn record(&self, visitor: &mut dyn Visit) { + pub fn record(&self, visitor: &mut dyn Visit<'a>) { let my_callsite = self.callsite(); for (field, value) in self.values { if field.callsite() != my_callsite { @@ -943,7 +951,7 @@ mod test { ]; struct MyVisitor; - impl Visit for MyVisitor { + impl Visit<'_> for MyVisitor { fn record_debug(&mut self, field: &Field, _: &dyn (core::fmt::Debug)) { assert_eq!(field.callsite(), TEST_META_1.callsite()) } @@ -962,7 +970,7 @@ mod test { ]; struct MyVisitor; - impl Visit for MyVisitor { + impl Visit<'_> for MyVisitor { fn record_debug(&mut self, field: &Field, _: &dyn (core::fmt::Debug)) { assert_eq!(field.name(), "bar") } diff --git a/tracing-core/src/span.rs b/tracing-core/src/span.rs index 1113eabe39..6dfcc72253 100644 --- a/tracing-core/src/span.rs +++ b/tracing-core/src/span.rs @@ -180,7 +180,7 @@ impl<'a> Attributes<'a> { /// [Visitor]. /// /// [visitor]: super::field::Visit - pub fn record(&self, visitor: &mut dyn field::Visit) { + pub fn record(&self, visitor: &mut dyn field::Visit<'a>) { self.values.record(visitor) } @@ -222,7 +222,7 @@ impl<'a> Record<'a> { /// Records all the fields in this `Record` with the provided [Visitor]. /// /// [visitor]: super::field::Visit - pub fn record(&self, visitor: &mut dyn field::Visit) { + pub fn record(&self, visitor: &mut dyn field::Visit<'a>) { self.values.record(visitor) } diff --git a/tracing-error/src/subscriber.rs b/tracing-error/src/subscriber.rs index f6840acc07..ddb98fca2f 100644 --- a/tracing-error/src/subscriber.rs +++ b/tracing-error/src/subscriber.rs @@ -39,7 +39,7 @@ pub(crate) struct WithContext( impl Subscribe for ErrorSubscriber where C: Collect + for<'span> LookupSpan<'span>, - F: for<'writer> FormatFields<'writer> + 'static, + F: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { /// Notifies this subscriber that a new span was constructed with the given /// `Attributes` and `Id`. @@ -72,7 +72,7 @@ where impl ErrorSubscriber where - F: for<'writer> FormatFields<'writer> + 'static, + F: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, C: Collect + for<'span> LookupSpan<'span>, { /// Returns a new `ErrorSubscriber` with the provided [field formatter]. diff --git a/tracing-journald/src/lib.rs b/tracing-journald/src/lib.rs index ef005ee47d..86e28af942 100644 --- a/tracing-journald/src/lib.rs +++ b/tracing-journald/src/lib.rs @@ -290,7 +290,7 @@ impl SpanVisitor<'_> { } } -impl Visit for SpanVisitor<'_> { +impl Visit<'_> for SpanVisitor<'_> { fn record_str(&mut self, field: &Field, value: &str) { self.put_span_prefix(); put_field_length_encoded(self.buf, field.name(), |buf| { @@ -329,7 +329,7 @@ impl<'a> EventVisitor<'a> { } } -impl Visit for EventVisitor<'_> { +impl Visit<'_> for EventVisitor<'_> { fn record_str(&mut self, field: &Field, value: &str) { self.put_prefix(field); put_field_length_encoded(self.buf, field.name(), |buf| { diff --git a/tracing-log/src/lib.rs b/tracing-log/src/lib.rs index 242784eb63..79fe945d73 100644 --- a/tracing-log/src/lib.rs +++ b/tracing-log/src/lib.rs @@ -516,7 +516,7 @@ impl<'a> LogVisitor<'a> { } } -impl<'a> Visit for LogVisitor<'a> { +impl<'a> Visit<'_> for LogVisitor<'a> { fn record_debug(&mut self, _field: &Field, _value: &dyn fmt::Debug) {} fn record_u64(&mut self, field: &Field, value: u64) { diff --git a/tracing-mock/src/field.rs b/tracing-mock/src/field.rs index 45a17bfa29..2e1d58d8b4 100644 --- a/tracing-mock/src/field.rs +++ b/tracing-mock/src/field.rs @@ -175,7 +175,7 @@ pub struct CheckVisitor<'a> { collector_name: &'a str, } -impl<'a> Visit for CheckVisitor<'a> { +impl<'a> Visit<'_> for CheckVisitor<'a> { fn record_f64(&mut self, field: &Field, value: f64) { self.expect .compare_or_panic(field.name(), &value, self.ctx, self.collector_name) @@ -229,7 +229,7 @@ impl<'a> From<&'a dyn Value> for MockValue { value: Option, } - impl Visit for MockValueBuilder { + impl Visit<'_> for MockValueBuilder { fn record_f64(&mut self, _: &Field, value: f64) { self.value = Some(MockValue::F64(value)); } diff --git a/tracing-opentelemetry/src/subscriber.rs b/tracing-opentelemetry/src/subscriber.rs index aac11b32f5..df922b4f05 100644 --- a/tracing-opentelemetry/src/subscriber.rs +++ b/tracing-opentelemetry/src/subscriber.rs @@ -108,7 +108,7 @@ fn str_to_status_code(s: &str) -> Option { struct SpanEventVisitor<'a>(&'a mut otel::Event); -impl<'a> field::Visit for SpanEventVisitor<'a> { +impl<'a> field::Visit<'_> for SpanEventVisitor<'a> { /// Record events on the underlying OpenTelemetry [`Span`] from `bool` values. /// /// [`Span`]: opentelemetry::trace::Span @@ -201,7 +201,7 @@ impl<'a> SpanAttributeVisitor<'a> { } } -impl<'a> field::Visit for SpanAttributeVisitor<'a> { +impl<'a> field::Visit<'_> for SpanAttributeVisitor<'a> { /// Set attributes on the underlying OpenTelemetry [`Span`] from `bool` values. /// /// [`Span`]: opentelemetry::trace::Span diff --git a/tracing-serde/src/lib.rs b/tracing-serde/src/lib.rs index 5a90ee5fa5..d1aecc8e51 100644 --- a/tracing-serde/src/lib.rs +++ b/tracing-serde/src/lib.rs @@ -371,7 +371,7 @@ where } } -impl Visit for SerdeMapVisitor +impl Visit<'_> for SerdeMapVisitor where S: SerializeMap, { @@ -423,7 +423,7 @@ pub struct SerdeStructVisitor { state: Result<(), S::Error>, } -impl Visit for SerdeStructVisitor +impl Visit<'_> for SerdeStructVisitor where S: SerializeStruct, { diff --git a/tracing-subscriber/src/field/debug.rs b/tracing-subscriber/src/field/debug.rs index cc67d29fe7..8e6ddd645c 100644 --- a/tracing-subscriber/src/field/debug.rs +++ b/tracing-subscriber/src/field/debug.rs @@ -22,9 +22,9 @@ impl Alt { } } -impl MakeVisitor for Alt +impl<'a, T, V> MakeVisitor<'a, T> for Alt where - V: MakeVisitor, + V: MakeVisitor<'a, T>, { type Visitor = Alt; @@ -34,9 +34,9 @@ where } } -impl Visit for Alt +impl<'a, V> Visit<'a> for Alt where - V: Visit, + V: Visit<'a>, { #[inline] fn record_f64(&mut self, field: &Field, value: f64) { @@ -59,7 +59,7 @@ where } /// Visit a string value. - fn record_str(&mut self, field: &Field, value: &str) { + fn record_str(&mut self, field: &Field, value: &'a str) { self.0.record_str(field, value) } @@ -74,9 +74,9 @@ where } } -impl VisitOutput for Alt +impl<'a, V, O> VisitOutput<'a, O> for Alt where - V: VisitOutput, + V: VisitOutput<'a, O>, { #[inline] fn finish(self) -> O { @@ -89,9 +89,9 @@ feature! { use super::VisitWrite; use std::io; - impl VisitWrite for Alt + impl<'a, V> VisitWrite<'a> for Alt where - V: VisitWrite, + V: VisitWrite<'a>, { #[inline] fn writer(&mut self) -> &mut dyn io::Write { @@ -100,9 +100,9 @@ feature! { } } -impl VisitFmt for Alt +impl<'a, V> VisitFmt<'a> for Alt where - V: VisitFmt, + V: VisitFmt<'a>, { #[inline] fn writer(&mut self) -> &mut dyn fmt::Write { diff --git a/tracing-subscriber/src/field/delimited.rs b/tracing-subscriber/src/field/delimited.rs index 98634cea9b..b3a8db33f6 100644 --- a/tracing-subscriber/src/field/delimited.rs +++ b/tracing-subscriber/src/field/delimited.rs @@ -24,11 +24,11 @@ pub struct VisitDelimited { // === impl Delimited === -impl MakeVisitor for Delimited +impl<'a, D, V, T> MakeVisitor<'a, T> for Delimited where D: AsRef + Clone, - V: MakeVisitor, - V::Visitor: VisitFmt, + V: MakeVisitor<'a, T>, + V::Visitor: VisitFmt<'a>, { type Visitor = VisitDelimited; fn make_visitor(&self, target: T) -> Self::Visitor { @@ -63,9 +63,9 @@ impl VisitDelimited { } } - fn delimit(&mut self) + fn delimit<'a>(&mut self) where - V: VisitFmt, + V: VisitFmt<'a>, D: AsRef, { if self.err.is_err() { @@ -80,9 +80,9 @@ impl VisitDelimited { } } -impl Visit for VisitDelimited +impl<'a, D, V> Visit<'a> for VisitDelimited where - V: VisitFmt, + V: VisitFmt<'a>, D: AsRef, { fn record_i64(&mut self, field: &Field, value: i64) { @@ -100,7 +100,7 @@ where self.inner.record_bool(field, value); } - fn record_str(&mut self, field: &Field, value: &str) { + fn record_str(&mut self, field: &Field, value: &'a str) { self.delimit(); self.inner.record_str(field, value); } @@ -111,9 +111,9 @@ where } } -impl VisitOutput for VisitDelimited +impl<'a, D, V> VisitOutput<'a, fmt::Result> for VisitDelimited where - V: VisitFmt, + V: VisitFmt<'a>, D: AsRef, { fn finish(self) -> fmt::Result { @@ -122,9 +122,9 @@ where } } -impl VisitFmt for VisitDelimited +impl<'a, D, V> VisitFmt<'a> for VisitDelimited where - V: VisitFmt, + V: VisitFmt<'a>, D: AsRef, { fn writer(&mut self) -> &mut dyn fmt::Write { diff --git a/tracing-subscriber/src/field/display.rs b/tracing-subscriber/src/field/display.rs index 78a039ce17..676b184bed 100644 --- a/tracing-subscriber/src/field/display.rs +++ b/tracing-subscriber/src/field/display.rs @@ -24,9 +24,9 @@ impl Messages { } } -impl MakeVisitor for Messages +impl<'a, T, V> MakeVisitor<'a, T> for Messages where - V: MakeVisitor, + V: MakeVisitor<'a, T>, { type Visitor = Messages; @@ -36,9 +36,9 @@ where } } -impl Visit for Messages +impl<'a, V> Visit<'a> for Messages where - V: Visit, + V: Visit<'a>, { #[inline] fn record_f64(&mut self, field: &Field, value: f64) { @@ -61,7 +61,7 @@ where } /// Visit a string value. - fn record_str(&mut self, field: &Field, value: &str) { + fn record_str(&mut self, field: &Field, value: &'a str) { if field.name() == "message" { self.0.record_debug(field, &format_args!("{}", value)) } else { @@ -80,9 +80,9 @@ where } } -impl VisitOutput for Messages +impl<'a, V, O> VisitOutput<'a, O> for Messages where - V: VisitOutput, + V: VisitOutput<'a, O>, { #[inline] fn finish(self) -> O { @@ -95,9 +95,9 @@ feature! { use super::VisitWrite; use std::io; - impl VisitWrite for Messages + impl<'a, V> VisitWrite<'a> for Messages where - V: VisitWrite, + V: VisitWrite<'a>, { #[inline] fn writer(&mut self) -> &mut dyn io::Write { @@ -106,9 +106,9 @@ feature! { } } -impl VisitFmt for Messages +impl<'a, V> VisitFmt<'a> for Messages where - V: VisitFmt, + V: VisitFmt<'a>, { #[inline] fn writer(&mut self) -> &mut dyn fmt::Write { diff --git a/tracing-subscriber/src/field/mod.rs b/tracing-subscriber/src/field/mod.rs index 705fa5841c..63b2611c95 100644 --- a/tracing-subscriber/src/field/mod.rs +++ b/tracing-subscriber/src/field/mod.rs @@ -23,9 +23,9 @@ pub mod display; /// `()` when no input is required to produce a visitor. /// /// [visitors]: tracing_core::field::Visit -pub trait MakeVisitor { +pub trait MakeVisitor<'a, T> { /// The visitor type produced by this `MakeVisitor`. - type Visitor: Visit; + type Visitor: Visit<'a>; /// Make a new visitor for the provided `target`. fn make_visitor(&self, target: T) -> Self::Visitor; @@ -34,7 +34,7 @@ pub trait MakeVisitor { /// A [visitor] that produces output once it has visited a set of fields. /// /// [visitor]: tracing_core::field::Visit -pub trait VisitOutput: Visit { +pub trait VisitOutput<'a, Out>: Visit<'a> { /// Completes the visitor, returning any output. /// /// This is called once a full set of fields has been visited. @@ -44,7 +44,7 @@ pub trait VisitOutput: Visit { /// once the fields have been visited. fn visit(mut self, fields: &R) -> Out where - R: RecordFields, + R: RecordFields<'a>, Self: Sized, { fields.record(&mut self); @@ -69,14 +69,14 @@ pub trait VisitOutput: Visit { /// // ... /// } /// # impl MyVisitor { fn new() -> Self { Self{} } } -/// impl Visit for MyVisitor { +/// impl Visit<'_> for MyVisitor { /// // ... /// # fn record_debug(&mut self, _: &Field, _: &dyn std::fmt::Debug) {} /// } /// -/// fn record_with_my_visitor(r: R) +/// fn record_with_my_visitor<'a, R>(r: R) /// where -/// R: RecordFields, +/// R: RecordFields<'a>, /// { /// let mut visitor = MyVisitor::new(); /// r.record(&mut visitor); @@ -86,23 +86,23 @@ pub trait VisitOutput: Visit { /// [attr]: tracing_core::span::Attributes /// [rec]: tracing_core::span::Record /// [event]: tracing_core::event::Event -pub trait RecordFields: crate::sealed::Sealed { +pub trait RecordFields<'a>: crate::sealed::Sealed { /// Record all the fields in `self` with the provided `visitor`. - fn record(&self, visitor: &mut dyn Visit); + fn record(&self, visitor: &mut dyn Visit<'a>); } /// Extension trait implemented for all `MakeVisitor` implementations that /// produce a visitor implementing `VisitOutput`. -pub trait MakeOutput +pub trait MakeOutput<'a, T, Out> where - Self: MakeVisitor + crate::sealed::Sealed<(T, Out)>, - Self::Visitor: VisitOutput, + Self: MakeVisitor<'a, T> + crate::sealed::Sealed<(T, Out)>, + Self::Visitor: VisitOutput<'a, Out>, { /// Visits all fields in `fields` with a new visitor constructed from /// `target`. fn visit_with(&self, target: T, fields: &F) -> Out where - F: RecordFields, + F: RecordFields<'a>, { self.make_visitor(target).visit(fields) } @@ -114,7 +114,7 @@ feature! { /// Extension trait implemented by visitors to indicate that they write to an /// `io::Write` instance, and allow access to that writer. - pub trait VisitWrite: VisitOutput> { + pub trait VisitWrite<'a>: VisitOutput<'a, Result<(), io::Error>> { /// Returns the writer that this visitor writes to. fn writer(&mut self) -> &mut dyn io::Write; } @@ -122,15 +122,15 @@ feature! { /// Extension trait implemented by visitors to indicate that they write to a /// `fmt::Write` instance, and allow access to that writer. -pub trait VisitFmt: VisitOutput { +pub trait VisitFmt<'a>: VisitOutput<'a, fmt::Result> { /// Returns the formatter that this visitor writes to. fn writer(&mut self) -> &mut dyn fmt::Write; } /// Extension trait providing `MakeVisitor` combinators. -pub trait MakeExt +pub trait MakeExt<'a, T> where - Self: MakeVisitor + Sized, + Self: MakeVisitor<'a, T> + Sized, Self: crate::sealed::Sealed>, { /// Wraps `self` so that any `fmt::Debug` fields are recorded using the @@ -150,7 +150,7 @@ where fn delimited(self, delimiter: D) -> delimited::Delimited where D: AsRef + Clone, - Self::Visitor: VisitFmt, + Self::Visitor: VisitFmt<'a>, { delimited::Delimited::new(delimiter, self) } @@ -159,42 +159,42 @@ where // === impl RecordFields === impl<'a> crate::sealed::Sealed for Event<'a> {} -impl<'a> RecordFields for Event<'a> { - fn record(&self, visitor: &mut dyn Visit) { +impl<'a> RecordFields<'a> for Event<'a> { + fn record(&self, visitor: &mut dyn Visit<'a>) { Event::record(self, visitor) } } impl<'a> crate::sealed::Sealed for Attributes<'a> {} -impl<'a> RecordFields for Attributes<'a> { - fn record(&self, visitor: &mut dyn Visit) { +impl<'a> RecordFields<'a> for Attributes<'a> { + fn record(&self, visitor: &mut dyn Visit<'a>) { Attributes::record(self, visitor) } } impl<'a> crate::sealed::Sealed for Record<'a> {} -impl<'a> RecordFields for Record<'a> { - fn record(&self, visitor: &mut dyn Visit) { +impl<'a> RecordFields<'a> for Record<'a> { + fn record(&self, visitor: &mut dyn Visit<'a>) { Record::record(self, visitor) } } -impl<'a, F> crate::sealed::Sealed for &'a F where F: RecordFields {} -impl<'a, F> RecordFields for &'a F +impl<'a, 'f, F> crate::sealed::Sealed for &'f F where F: RecordFields<'a> {} +impl<'a, 'f, F> RecordFields<'a> for &'f F where - F: RecordFields, + F: RecordFields<'a>, { - fn record(&self, visitor: &mut dyn Visit) { + fn record(&self, visitor: &mut dyn Visit<'a>) { F::record(*self, visitor) } } // === blanket impls === -impl MakeVisitor for F +impl<'a, T, V, F> MakeVisitor<'a, T> for F where F: Fn(T) -> V, - V: Visit, + V: Visit<'a>, { type Visitor = V; fn make_visitor(&self, target: T) -> Self::Visitor { @@ -202,25 +202,25 @@ where } } -impl crate::sealed::Sealed<(T, Out)> for M +impl<'a, T, Out, M> crate::sealed::Sealed<(T, Out)> for M where - M: MakeVisitor, - M::Visitor: VisitOutput, + M: MakeVisitor<'a, T>, + M::Visitor: VisitOutput<'a, Out>, { } -impl MakeOutput for M +impl<'a, T, Out, M> MakeOutput<'a, T, Out> for M where - M: MakeVisitor, - M::Visitor: VisitOutput, + M: MakeVisitor<'a, T>, + M::Visitor: VisitOutput<'a, Out>, { } -impl crate::sealed::Sealed> for M where M: MakeVisitor + Sized {} +impl<'a, T, M> crate::sealed::Sealed> for M where M: MakeVisitor<'a, T> + Sized {} -impl MakeExt for M +impl<'a, T, M> MakeExt<'a, T> for M where - M: MakeVisitor + Sized, + M: MakeVisitor<'a, T> + Sized, M: crate::sealed::Sealed>, { } @@ -339,25 +339,25 @@ pub(in crate::field) mod test_util { } } - impl<'a> Visit for DebugVisitor<'a> { + impl<'a> Visit<'_> for DebugVisitor<'a> { fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { write!(self.writer, "{}={:?}", field, value).unwrap(); } } - impl<'a> VisitOutput for DebugVisitor<'a> { + impl<'a> VisitOutput<'_, fmt::Result> for DebugVisitor<'a> { fn finish(self) -> fmt::Result { self.err } } - impl<'a> VisitFmt for DebugVisitor<'a> { + impl<'a> VisitFmt<'_> for DebugVisitor<'a> { fn writer(&mut self) -> &mut dyn fmt::Write { self.writer } } - impl<'a> MakeVisitor<&'a mut dyn fmt::Write> for MakeDebug { + impl<'a> MakeVisitor<'_, &'a mut dyn fmt::Write> for MakeDebug { type Visitor = DebugVisitor<'a>; fn make_visitor(&self, w: &'a mut dyn fmt::Write) -> DebugVisitor<'a> { DebugVisitor::new(w) diff --git a/tracing-subscriber/src/filter/env/field.rs b/tracing-subscriber/src/filter/env/field.rs index 211d2bded9..4f4ee22df1 100644 --- a/tracing-subscriber/src/filter/env/field.rs +++ b/tracing-subscriber/src/filter/env/field.rs @@ -500,7 +500,7 @@ impl SpanMatch { } } -impl<'a> Visit for MatchVisitor<'a> { +impl<'a> Visit<'_> for MatchVisitor<'a> { fn record_f64(&mut self, field: &Field, value: f64) { match self.inner.fields.get(field) { Some((ValueMatch::NaN, ref matched)) if value.is_nan() => { diff --git a/tracing-subscriber/src/fmt/fmt_subscriber.rs b/tracing-subscriber/src/fmt/fmt_subscriber.rs index 21df9d3c37..4ca4da7681 100644 --- a/tracing-subscriber/src/fmt/fmt_subscriber.rs +++ b/tracing-subscriber/src/fmt/fmt_subscriber.rs @@ -82,7 +82,7 @@ impl Subscriber { impl Subscriber where C: Collect + for<'a> LookupSpan<'a>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, W: for<'writer> MakeWriter<'writer> + 'static, { /// Sets the [event formatter][`FormatEvent`] that the subscriber will use to @@ -253,7 +253,7 @@ impl Subscriber { impl Subscriber, W> where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { /// Use the given [`timer`] for span and event timestamps. /// @@ -411,7 +411,7 @@ where /// Sets the subscriber being built to use a [less verbose formatter](format::Compact). pub fn compact(self) -> Subscriber, W> where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { Subscriber { fmt_event: self.fmt_event.compact(), @@ -520,7 +520,7 @@ impl Subscriber { /// fields. pub fn fmt_fields(self, fmt_fields: N2) -> Subscriber where - N2: for<'writer> FormatFields<'writer> + 'static, + N2: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { Subscriber { fmt_event: self.fmt_event, @@ -549,7 +549,7 @@ impl Default for Subscriber { impl Subscriber where C: Collect + for<'a> LookupSpan<'a>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, E: FormatEvent + 'static, W: for<'writer> MakeWriter<'writer> + 'static, { @@ -643,7 +643,7 @@ macro_rules! with_event_from_span { impl subscribe::Subscribe for Subscriber where C: Collect + for<'a> LookupSpan<'a>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, E: FormatEvent + 'static, W: for<'writer> MakeWriter<'writer> + 'static, { @@ -841,12 +841,12 @@ impl<'a, C, N> fmt::Debug for FmtContext<'a, C, N> { } } -impl<'cx, 'writer, C, N> FormatFields<'writer> for FmtContext<'cx, C, N> +impl<'cx, 'visit, 'writer, C, N> FormatFields<'visit, 'writer> for FmtContext<'cx, C, N> where C: Collect + for<'lookup> LookupSpan<'lookup>, - N: FormatFields<'writer> + 'static, + N: FormatFields<'visit, 'writer> + 'static, { - fn format_fields( + fn format_fields>( &self, writer: format::Writer<'writer>, fields: R, @@ -858,7 +858,7 @@ where impl<'a, C, N> FmtContext<'a, C, N> where C: Collect + for<'lookup> LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'f, 'writer> FormatFields<'f, 'writer> + 'static, { /// Visits every span in the current context with a closure. /// diff --git a/tracing-subscriber/src/fmt/format/json.rs b/tracing-subscriber/src/fmt/format/json.rs index 5dc32da9e5..6a70564f62 100644 --- a/tracing-subscriber/src/fmt/format/json.rs +++ b/tracing-subscriber/src/fmt/format/json.rs @@ -100,12 +100,12 @@ struct SerializableContext<'a, 'b, Span, N>( ) where Span: Collect + for<'lookup> crate::registry::LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static; + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static; impl<'a, 'b, Span, N> serde::ser::Serialize for SerializableContext<'a, 'b, Span, N> where Span: Collect + for<'lookup> crate::registry::LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { fn serialize(&self, serializer_o: Ser) -> Result where @@ -130,12 +130,12 @@ struct SerializableSpan<'a, 'b, Span, N>( ) where Span: for<'lookup> crate::registry::LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static; + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static; impl<'a, 'b, Span, N> serde::ser::Serialize for SerializableSpan<'a, 'b, Span, N> where Span: for<'lookup> crate::registry::LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { fn serialize(&self, serializer: Ser) -> Result where @@ -196,7 +196,7 @@ where impl FormatEvent for Format where C: Collect + for<'lookup> LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, T: FormatTime, { fn format_event( @@ -345,9 +345,13 @@ impl Default for JsonFields { } } -impl<'a> FormatFields<'a> for JsonFields { +impl<'visit, 'writer> FormatFields<'visit, 'writer> for JsonFields { /// Format the provided `fields` to the provided `writer`, returning a result. - fn format_fields(&self, mut writer: Writer<'_>, fields: R) -> fmt::Result { + fn format_fields>( + &self, + mut writer: Writer<'_>, + fields: R, + ) -> fmt::Result { let mut v = JsonVisitor::new(&mut writer); fields.record(&mut v); v.finish() @@ -360,8 +364,8 @@ impl<'a> FormatFields<'a> for JsonFields { /// required, the default implementation of this method can be overridden. fn add_fields( &self, - current: &'a mut FormattedFields, - fields: &Record<'_>, + current: &'writer mut FormattedFields, + fields: &Record<'visit>, ) -> fmt::Result { if current.is_empty() { // If there are no previously recorded fields, we can just reuse the @@ -430,13 +434,13 @@ impl<'a> JsonVisitor<'a> { } } -impl<'a> crate::field::VisitFmt for JsonVisitor<'a> { +impl<'a> crate::field::VisitFmt<'_> for JsonVisitor<'a> { fn writer(&mut self) -> &mut dyn fmt::Write { self.writer } } -impl<'a> crate::field::VisitOutput for JsonVisitor<'a> { +impl<'a> crate::field::VisitOutput<'_, fmt::Result> for JsonVisitor<'a> { fn finish(self) -> fmt::Result { let inner = || { let mut serializer = Serializer::new(WriteAdaptor::new(self.writer)); @@ -457,7 +461,7 @@ impl<'a> crate::field::VisitOutput for JsonVisitor<'a> { } } -impl<'a> field::Visit for JsonVisitor<'a> { +impl<'a> field::Visit<'_> for JsonVisitor<'a> { /// Visit a double precision floating point value. fn record_f64(&mut self, field: &Field, value: f64) { self.values diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index d866340dbc..5fb4f77d8a 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -128,7 +128,7 @@ use fmt::{Debug, Display}; /// impl FormatEvent for MyFormatter /// where /// C: Collect + for<'a> LookupSpan<'a>, -/// N: for<'a> FormatFields<'a> + 'static, +/// N: for<'visit, 'write> FormatFields<'visit, 'write> + 'static, /// { /// fn format_event( /// &self, @@ -197,7 +197,7 @@ use fmt::{Debug, Display}; pub trait FormatEvent where C: Collect + for<'a> LookupSpan<'a>, - N: for<'a> FormatFields<'a> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { /// Write a log message for `Event` in `Context` to the given [`Writer`]. fn format_event( @@ -212,7 +212,7 @@ impl FormatEvent for fn(ctx: &FmtContext<'_, C, N>, Writer<'_>, &Event<'_>) -> fmt::Result where C: Collect + for<'a> LookupSpan<'a>, - N: for<'a> FormatFields<'a> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { fn format_event( &self, @@ -231,9 +231,13 @@ where /// /// [set of fields]: RecordFields /// [`fmt::Subscriber`]: super::Subscriber -pub trait FormatFields<'writer> { +pub trait FormatFields<'visit, 'writer> { /// Format the provided `fields` to the provided [`Writer`], returning a result. - fn format_fields(&self, writer: Writer<'writer>, fields: R) -> fmt::Result; + fn format_fields>( + &self, + writer: Writer<'writer>, + fields: R, + ) -> fmt::Result; /// Record additional field(s) on an existing span. /// @@ -243,7 +247,7 @@ pub trait FormatFields<'writer> { fn add_fields( &self, current: &'writer mut FormattedFields, - fields: &span::Record<'_>, + fields: &span::Record<'visit>, ) -> fmt::Result { if !current.fields.is_empty() { current.fields.push(' '); @@ -913,7 +917,7 @@ impl Format { impl FormatEvent for Format where C: Collect + for<'a> LookupSpan<'a>, - N: for<'a> FormatFields<'a> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, T: FormatTime, { fn format_event( @@ -1028,7 +1032,7 @@ where impl FormatEvent for Format where C: Collect + for<'a> LookupSpan<'a>, - N: for<'a> FormatFields<'a> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, T: FormatTime, { fn format_event( @@ -1106,12 +1110,16 @@ where } // === impl FormatFields === -impl<'writer, M> FormatFields<'writer> for M +impl<'visit, 'writer, M> FormatFields<'visit, 'writer> for M where - M: MakeOutput, fmt::Result>, - M::Visitor: VisitFmt + VisitOutput, + M: MakeOutput<'visit, Writer<'writer>, fmt::Result>, + M::Visitor: VisitFmt<'visit> + VisitOutput<'visit, fmt::Result>, { - fn format_fields(&self, writer: Writer<'writer>, fields: R) -> fmt::Result { + fn format_fields>( + &self, + writer: Writer<'writer>, + fields: R, + ) -> fmt::Result { let mut v = self.make_visitor(writer); fields.record(&mut v); v.finish() @@ -1152,7 +1160,7 @@ impl Default for DefaultFields { } } -impl<'a> MakeVisitor> for DefaultFields { +impl<'a> MakeVisitor<'_, Writer<'a>> for DefaultFields { type Visitor = DefaultVisitor<'a>; #[inline] @@ -1187,7 +1195,7 @@ impl<'a> DefaultVisitor<'a> { } } -impl<'a> field::Visit for DefaultVisitor<'a> { +impl<'a> field::Visit<'_> for DefaultVisitor<'a> { fn record_str(&mut self, field: &Field, value: &str) { if self.result.is_err() { return; @@ -1248,13 +1256,13 @@ impl<'a> field::Visit for DefaultVisitor<'a> { } } -impl<'a> crate::field::VisitOutput for DefaultVisitor<'a> { +impl<'a> crate::field::VisitOutput<'_, fmt::Result> for DefaultVisitor<'a> { fn finish(self) -> fmt::Result { self.result } } -impl<'a> crate::field::VisitFmt for DefaultVisitor<'a> { +impl<'a> crate::field::VisitFmt<'_> for DefaultVisitor<'a> { fn writer(&mut self) -> &mut dyn fmt::Write { &mut self.writer } @@ -1423,13 +1431,13 @@ impl<'a, F: LevelNames> fmt::Display for FmtLevel { // === impl FieldFn === -impl<'a, F> MakeVisitor> for FieldFn +impl<'writer, F> MakeVisitor<'_, Writer<'writer>> for FieldFn where - F: Fn(&mut Writer<'a>, &Field, &dyn fmt::Debug) -> fmt::Result + Clone, + F: Fn(&mut Writer<'writer>, &Field, &dyn fmt::Debug) -> fmt::Result + Clone, { - type Visitor = FieldFnVisitor<'a, F>; + type Visitor = FieldFnVisitor<'writer, F>; - fn make_visitor(&self, writer: Writer<'a>) -> Self::Visitor { + fn make_visitor(&self, writer: Writer<'writer>) -> Self::Visitor { FieldFnVisitor { writer, f: self.0.clone(), @@ -1438,7 +1446,7 @@ where } } -impl<'a, F> Visit for FieldFnVisitor<'a, F> +impl<'a, F> Visit<'_> for FieldFnVisitor<'a, F> where F: Fn(&mut Writer<'a>, &Field, &dyn fmt::Debug) -> fmt::Result, { @@ -1449,7 +1457,7 @@ where } } -impl<'a, F> VisitOutput for FieldFnVisitor<'a, F> +impl<'a, F> VisitOutput<'_, fmt::Result> for FieldFnVisitor<'a, F> where F: Fn(&mut Writer<'a>, &Field, &dyn fmt::Debug) -> fmt::Result, { @@ -1458,7 +1466,7 @@ where } } -impl<'a, F> VisitFmt for FieldFnVisitor<'a, F> +impl<'a, F> VisitFmt<'_> for FieldFnVisitor<'a, F> where F: Fn(&mut Writer<'a>, &Field, &dyn fmt::Debug) -> fmt::Result, { diff --git a/tracing-subscriber/src/fmt/format/pretty.rs b/tracing-subscriber/src/fmt/format/pretty.rs index c2c6bbda6e..b1b2b9cffc 100644 --- a/tracing-subscriber/src/fmt/format/pretty.rs +++ b/tracing-subscriber/src/fmt/format/pretty.rs @@ -169,7 +169,7 @@ impl Pretty { impl FormatEvent for Format where C: Collect + for<'a> LookupSpan<'a>, - N: for<'a> FormatFields<'a> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, T: FormatTime, { fn format_event( @@ -322,8 +322,12 @@ where } } -impl<'writer> FormatFields<'writer> for Pretty { - fn format_fields(&self, writer: Writer<'writer>, fields: R) -> fmt::Result { +impl<'visit, 'writer> FormatFields<'visit, 'writer> for Pretty { + fn format_fields>( + &self, + writer: Writer<'writer>, + fields: R, + ) -> fmt::Result { let mut v = PrettyVisitor::new(writer, true); fields.record(&mut v); v.finish() @@ -332,7 +336,7 @@ impl<'writer> FormatFields<'writer> for Pretty { fn add_fields( &self, current: &'writer mut FormattedFields, - fields: &span::Record<'_>, + fields: &span::Record<'visit>, ) -> fmt::Result { let empty = current.is_empty(); let writer = current.as_writer(); @@ -372,11 +376,11 @@ impl PrettyFields { } } -impl<'a> MakeVisitor> for PrettyFields { - type Visitor = PrettyVisitor<'a>; +impl<'visit, 'writer> MakeVisitor<'visit, Writer<'writer>> for PrettyFields { + type Visitor = PrettyVisitor<'writer>; #[inline] - fn make_visitor(&self, mut target: Writer<'a>) -> Self::Visitor { + fn make_visitor(&self, mut target: Writer<'writer>) -> Self::Visitor { if let Some(ansi) = self.ansi { target = target.with_ansi(ansi); } @@ -425,7 +429,7 @@ impl<'a> PrettyVisitor<'a> { } } -impl<'a> field::Visit for PrettyVisitor<'a> { +impl<'a> field::Visit<'_> for PrettyVisitor<'a> { fn record_str(&mut self, field: &Field, value: &str) { if self.result.is_err() { return; @@ -485,14 +489,14 @@ impl<'a> field::Visit for PrettyVisitor<'a> { } } -impl<'a> VisitOutput for PrettyVisitor<'a> { +impl<'a> VisitOutput<'_, fmt::Result> for PrettyVisitor<'a> { fn finish(mut self) -> fmt::Result { write!(&mut self.writer, "{}", self.style.suffix())?; self.result } } -impl<'a> VisitFmt for PrettyVisitor<'a> { +impl<'a> VisitFmt<'_> for PrettyVisitor<'a> { fn writer(&mut self) -> &mut dyn fmt::Write { &mut self.writer } diff --git a/tracing-subscriber/src/fmt/mod.rs b/tracing-subscriber/src/fmt/mod.rs index c0f962544f..5f4f402feb 100644 --- a/tracing-subscriber/src/fmt/mod.rs +++ b/tracing-subscriber/src/fmt/mod.rs @@ -361,7 +361,7 @@ impl Default for Collector { impl tracing_core::Collect for Collector where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, E: FormatEvent + 'static, F: subscribe::Subscribe> + 'static, W: for<'writer> MakeWriter<'writer> + 'static, @@ -462,7 +462,7 @@ impl Default for CollectorBuilder { impl CollectorBuilder where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, E: FormatEvent + 'static, W: for<'writer> MakeWriter<'writer> + 'static, F: subscribe::Subscribe> + Send + Sync + 'static, @@ -509,7 +509,7 @@ where impl From> for tracing_core::Dispatch where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, E: FormatEvent + 'static, W: for<'writer> MakeWriter<'writer> + 'static, F: subscribe::Subscribe> + Send + Sync + 'static, @@ -523,7 +523,7 @@ where impl CollectorBuilder, F, W> where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { /// Use the given [`timer`] for log message timestamps. /// @@ -695,7 +695,7 @@ where /// See [`format::Compact`]. pub fn compact(self) -> CollectorBuilder, F, W> where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { CollectorBuilder { filter: self.filter, @@ -722,7 +722,7 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "json")))] pub fn json(self) -> CollectorBuilder, F, W> where - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { CollectorBuilder { filter: self.filter, @@ -810,7 +810,7 @@ impl CollectorBuilder { /// ``` pub fn fmt_fields(self, fmt_fields: N2) -> CollectorBuilder where - N2: for<'writer> FormatFields<'writer> + 'static, + N2: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, { CollectorBuilder { filter: self.filter, @@ -970,7 +970,7 @@ impl CollectorBuilder { pub fn event_format(self, fmt_event: E2) -> CollectorBuilder where E2: FormatEvent + 'static, - N: for<'writer> FormatFields<'writer> + 'static, + N: for<'visit, 'writer> FormatFields<'visit, 'writer> + 'static, W: for<'writer> MakeWriter<'writer> + 'static, { CollectorBuilder { diff --git a/tracing/benches/subscriber.rs b/tracing/benches/subscriber.rs index 3fda5283e0..29ed5dfe85 100644 --- a/tracing/benches/subscriber.rs +++ b/tracing/benches/subscriber.rs @@ -51,7 +51,7 @@ struct VisitingCollector(Mutex); struct Visitor<'a>(MutexGuard<'a, String>); -impl<'a> field::Visit for Visitor<'a> { +impl<'a> field::Visit<'_> for Visitor<'a> { fn record_debug(&mut self, _field: &field::Field, value: &dyn fmt::Debug) { use std::fmt::Write; let _ = write!(&mut *self.0, "{:?}", value); diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index 2d7198896c..af91f51d7d 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -1155,7 +1155,7 @@ pub mod __macro_support { } #[cfg(feature = "log")] - impl Visit for LogVisitor<'_, '_> { + impl Visit<'_> for LogVisitor<'_, '_> { fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { let res = if self.is_first { self.is_first = false;