Skip to content

Commit

Permalink
Merge branch 'master' into docs/decrusting-by-jonhoo
Browse files Browse the repository at this point in the history
  • Loading branch information
hds authored Nov 30, 2024
2 parents 130e093 + c8049f6 commit 07a5a15
Show file tree
Hide file tree
Showing 45 changed files with 499 additions and 227 deletions.
2 changes: 1 addition & 1 deletion examples/examples/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Count<'a> {
counters: RwLockReadGuard<'a, HashMap<String, AtomicUsize>>,
}

impl<'a> Visit for Count<'a> {
impl Visit for Count<'_> {
fn record_i64(&mut self, field: &Field, value: i64) {
if let Some(counter) = self.counters.get(field.name()) {
if value > 0 {
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/sloggish/sloggish_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct Event<'a> {

struct ColorLevel<'a>(&'a Level);

impl<'a> fmt::Display for ColorLevel<'a> {
impl fmt::Display for ColorLevel<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self.0 {
Level::TRACE => Color::Purple.paint("TRACE"),
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Visit for Span {
}
}

impl<'a> Visit for Event<'a> {
impl Visit for Event<'_> {
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
write!(
&mut self.stderr,
Expand Down
2 changes: 1 addition & 1 deletion tracing-appender/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl NoOpWriter {
}
}

impl<'a> MakeWriter<'a> for NoOpWriter {
impl MakeWriter<'_> for NoOpWriter {
type Writer = NoOpWriter;

fn make_writer(&self) -> Self::Writer {
Expand Down
2 changes: 1 addition & 1 deletion tracing-appender/src/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub use builder::{Builder, InitError};
///
/// // Log all events to a rolling log file.
/// let logfile = tracing_appender::rolling::hourly("/logs", "myapp-logs");
///
/// // Log `INFO` and above to stdout.
/// let stdout = std::io::stdout.with_max_level(tracing::Level::INFO);
///
Expand Down
4 changes: 2 additions & 2 deletions tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ struct IdentAndTypesRenamer<'a> {
idents: Vec<(Ident, Ident)>,
}

impl<'a> VisitMut for IdentAndTypesRenamer<'a> {
impl VisitMut for IdentAndTypesRenamer<'_> {
// we deliberately compare strings because we want to ignore the spans
// If we apply clippy's lint, the behavior changes
#[allow(clippy::cmp_owned)]
Expand Down Expand Up @@ -802,7 +802,7 @@ struct AsyncTraitBlockReplacer<'a> {
patched_block: Block,
}

impl<'a> VisitMut for AsyncTraitBlockReplacer<'a> {
impl VisitMut for AsyncTraitBlockReplacer<'_> {
fn visit_block_mut(&mut self, i: &mut Block) {
if i == self.block {
*i = self.patched_block.clone();
Expand Down
4 changes: 2 additions & 2 deletions tracing-core/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ where
// the default dispatcher will not be able to access the dispatch context.
// Dropping the guard will allow the dispatch context to be re-entered.
struct Entered<'a>(&'a Cell<bool>);
impl<'a> Drop for Entered<'a> {
impl Drop for Entered<'_> {
#[inline]
fn drop(&mut self) {
self.0.set(true);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ impl<'a> Entered<'a> {
}

#[cfg(feature = "std")]
impl<'a> Drop for Entered<'a> {
impl Drop for Entered<'_> {
#[inline]
fn drop(&mut self) {
self.0.can_enter.set(true);
Expand Down
34 changes: 25 additions & 9 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ where

struct HexBytes<'a>(&'a [u8]);

impl<'a> fmt::Debug for HexBytes<'a> {
impl fmt::Debug for HexBytes<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_char('[')?;

Expand All @@ -310,13 +310,13 @@ impl<'a> fmt::Debug for HexBytes<'a> {

// ===== impl Visit =====

impl<'a, 'b> Visit for fmt::DebugStruct<'a, 'b> {
impl Visit for fmt::DebugStruct<'_, '_> {
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 Visit for fmt::DebugMap<'_, '_> {
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
self.entry(&format_args!("{}", field), value);
}
Expand Down Expand Up @@ -544,9 +544,9 @@ where
}
}

impl<'a> crate::sealed::Sealed for fmt::Arguments<'a> {}
impl crate::sealed::Sealed for fmt::Arguments<'_> {}

impl<'a> Value for fmt::Arguments<'a> {
impl Value for fmt::Arguments<'_> {
fn record(&self, key: &Field, visitor: &mut dyn Visit) {
visitor.record_debug(key, self)
}
Expand Down Expand Up @@ -681,6 +681,11 @@ impl Field {
pub fn name(&self) -> &'static str {
self.fields.names[self.i]
}

/// Returns the index of this field in its [`FieldSet`].
pub fn index(&self) -> usize {
self.i
}
}

impl fmt::Display for Field {
Expand Down Expand Up @@ -813,7 +818,7 @@ impl FieldSet {
}
}

impl<'a> IntoIterator for &'a FieldSet {
impl IntoIterator for &FieldSet {
type IntoIter = Iter;
type Item = Field;
#[inline]
Expand Down Expand Up @@ -892,7 +897,7 @@ impl Iterator for Iter {

// ===== impl ValueSet =====

impl<'a> ValueSet<'a> {
impl ValueSet<'_> {
/// Returns an [`Identifier`] that uniquely identifies the [`Callsite`]
/// defining the fields this `ValueSet` refers to.
///
Expand Down Expand Up @@ -953,7 +958,7 @@ impl<'a> ValueSet<'a> {
}
}

impl<'a> fmt::Debug for ValueSet<'a> {
impl fmt::Debug for ValueSet<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.values
.iter()
Expand All @@ -968,7 +973,7 @@ impl<'a> fmt::Debug for ValueSet<'a> {
}
}

impl<'a> fmt::Display for ValueSet<'a> {
impl fmt::Display for ValueSet<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.values
.iter()
Expand Down Expand Up @@ -1053,6 +1058,17 @@ mod test {
assert!(valueset.is_empty());
}

#[test]
fn index_of_field_in_fieldset_is_correct() {
let fields = TEST_META_1.fields();
let foo = fields.field("foo").unwrap();
assert_eq!(foo.index(), 0);
let bar = fields.field("bar").unwrap();
assert_eq!(bar.index(), 1);
let baz = fields.field("baz").unwrap();
assert_eq!(baz.index(), 2);
}

#[test]
fn empty_value_set_is_empty() {
let fields = TEST_META_1.fields();
Expand Down
8 changes: 4 additions & 4 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub struct Kind(u8);
/// // ...
/// # drop(span); Id::from_u64(1)
/// }
///
/// fn event(&self, event: &Event<'_>) {
/// // ...
/// # drop(event);
Expand Down Expand Up @@ -333,7 +333,7 @@ impl<'a> Metadata<'a> {
}
}

impl<'a> fmt::Debug for Metadata<'a> {
impl fmt::Debug for Metadata<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut meta = f.debug_struct("Metadata");
meta.field("name", &self.name)
Expand Down Expand Up @@ -441,9 +441,9 @@ impl fmt::Debug for Kind {
}
}

impl<'a> Eq for Metadata<'a> {}
impl Eq for Metadata<'_> {}

impl<'a> PartialEq for Metadata<'a> {
impl PartialEq for Metadata<'_> {
#[inline]
fn eq(&self, other: &Self) -> bool {
if core::ptr::eq(&self, &other) {
Expand Down
2 changes: 1 addition & 1 deletion tracing-error/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl fmt::Debug for SpanTrace {
fields: &'a str,
}

impl<'a> fmt::Debug for DebugSpan<'a> {
impl fmt::Debug for DebugSpan<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
Expand Down
10 changes: 5 additions & 5 deletions tracing-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub trait AsTrace: crate::sealed::Sealed {
fn as_trace(&self) -> Self::Trace;
}

impl<'a> crate::sealed::Sealed for Metadata<'a> {}
impl crate::sealed::Sealed for Metadata<'_> {}

impl<'a> AsLog for Metadata<'a> {
type Log = log::Metadata<'a>;
Expand All @@ -220,7 +220,7 @@ impl<'a> AsLog for Metadata<'a> {
.build()
}
}
impl<'a> crate::sealed::Sealed for log::Metadata<'a> {}
impl crate::sealed::Sealed for log::Metadata<'_> {}

impl<'a> AsTrace for log::Metadata<'a> {
type Trace = Metadata<'a>;
Expand Down Expand Up @@ -350,7 +350,7 @@ fn loglevel_to_cs(
}
}

impl<'a> crate::sealed::Sealed for log::Record<'a> {}
impl crate::sealed::Sealed for log::Record<'_> {}

impl<'a> AsTrace for log::Record<'a> {
type Trace = Metadata<'a>;
Expand Down Expand Up @@ -461,7 +461,7 @@ pub trait NormalizeEvent<'a>: crate::sealed::Sealed {
fn is_log(&self) -> bool;
}

impl<'a> crate::sealed::Sealed for Event<'a> {}
impl crate::sealed::Sealed for Event<'_> {}

impl<'a> NormalizeEvent<'a> for Event<'a> {
fn normalized_metadata(&'a self) -> Option<Metadata<'a>> {
Expand Down Expand Up @@ -513,7 +513,7 @@ impl<'a> LogVisitor<'a> {
}
}

impl<'a> Visit for LogVisitor<'a> {
impl Visit for LogVisitor<'_> {
fn record_debug(&mut self, _field: &Field, _value: &dyn fmt::Debug) {}

fn record_u64(&mut self, field: &Field, value: u64) {
Expand Down
10 changes: 5 additions & 5 deletions tracing-mock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# tracing-mock

Utilities for testing [`tracing`][tracing] and crates that uses it.
Utilities for testing [`tracing`] and crates that uses it.

[![Documentation (master)][docs-master-badge]][docs-master-url]
[![MIT licensed][mit-badge]][mit-url]
Expand Down Expand Up @@ -78,7 +78,7 @@ fn yak_shaving() {
}

let (collector, handle) = collector::mock()
.event(expect::event().with_fields(expect::message("preparing to shave yaks")))
.event(expect::event().with_fields(expect::msg("preparing to shave yaks")))
.only()
.run_with_handle();

Expand Down Expand Up @@ -128,15 +128,15 @@ let (collector, handle) = collector::mock()
expect::event().with_fields(
expect::field("number_of_yaks")
.with_value(&yak_count)
.and(expect::message("preparing to shave yaks"))
.and(expect::msg("preparing to shave yaks"))
.only(),
),
)
.event(
expect::event().with_fields(
expect::field("all_yaks_shaved")
.with_value(&true)
.and(expect::message("yak shaving completed."))
.and(expect::msg("yak shaving completed."))
.only(),
),
)
Expand Down Expand Up @@ -173,4 +173,4 @@ This project is licensed under the [MIT license][mit-url].

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Tracing by you, shall be licensed as MIT, without any additional
terms or conditions.
terms or conditions.
26 changes: 15 additions & 11 deletions tracing-mock/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//!
//! let (collector, handle) = collector::mock()
//! // Expect a single event with a specified message
//! .event(expect::event().with_fields(expect::message("droids")))
//! .event(expect::event().with_fields(expect::msg("droids")))
//! .only()
//! .run_with_handle();
//!
Expand Down Expand Up @@ -40,7 +40,7 @@
//! // Enter a matching span
//! .enter(&span)
//! // Record an event with message "collect parting message"
//! .event(expect::event().with_fields(expect::message("collect parting message")))
//! .event(expect::event().with_fields(expect::msg("collect parting message")))
//! // Record a value for the field `parting` on a matching span
//! .record(&span, expect::field("parting").with_value(&"goodbye world!"))
//! // Exit a matching span
Expand Down Expand Up @@ -81,7 +81,7 @@
//! .named("my_span");
//! let (collector, handle) = collector::mock()
//! .enter(&span)
//! .event(expect::event().with_fields(expect::message("collect parting message")))
//! .event(expect::event().with_fields(expect::msg("collect parting message")))
//! .record(&span, expect::field("parting").with_value(&"goodbye world!"))
//! .exit(span)
//! .only()
Expand Down Expand Up @@ -137,13 +137,6 @@
//!
//! [`Collect`]: trait@tracing::Collect
//! [`MockCollector`]: struct@crate::collector::MockCollector
use crate::{
ancestry::get_ancestry,
event::ExpectedEvent,
expect::Expect,
field::ExpectedFields,
span::{ActualSpan, ExpectedSpan, NewSpan},
};
use std::{
collections::{HashMap, VecDeque},
sync::{
Expand All @@ -152,13 +145,22 @@ use std::{
},
thread,
};

use tracing::{
collect::Interest,
level_filters::LevelFilter,
span::{self, Attributes, Id},
Collect, Event, Metadata,
};

use crate::{
ancestry::get_ancestry,
event::ExpectedEvent,
expect::Expect,
field::ExpectedFields,
span::{ActualSpan, ExpectedSpan, NewSpan},
};

pub(crate) struct SpanState {
id: Id,
name: &'static str,
Expand Down Expand Up @@ -188,6 +190,7 @@ struct Running<F: Fn(&Metadata<'_>) -> bool> {
/// for the methods and the [`collector`] module.
///
/// [`collector`]: mod@crate::collector
#[derive(Debug)]
pub struct MockCollector<F: Fn(&Metadata<'_>) -> bool> {
expected: VecDeque<Expect>,
max_level: Option<LevelFilter>,
Expand All @@ -204,6 +207,7 @@ pub struct MockCollector<F: Fn(&Metadata<'_>) -> bool> {
/// module documentation.
///
/// [`collector`]: mod@crate::collector
#[derive(Debug)]
pub struct MockHandle(Arc<Mutex<VecDeque<Expect>>>, String);

/// Create a new [`MockCollector`].
Expand All @@ -223,7 +227,7 @@ pub struct MockHandle(Arc<Mutex<VecDeque<Expect>>>, String);
/// // Enter a matching span
/// .enter(&span)
/// // Record an event with message "collect parting message"
/// .event(expect::event().with_fields(expect::message("collect parting message")))
/// .event(expect::event().with_fields(expect::msg("collect parting message")))
/// // Record a value for the field `parting` on a matching span
/// .record(&span, expect::field("parting").with_value(&"goodbye world!"))
/// // Exit a matching span
Expand Down
Loading

0 comments on commit 07a5a15

Please sign in to comment.