diff --git a/Cargo.toml b/Cargo.toml index 65bb8fd092..afd6d10d83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,8 @@ members = [ "tracing-journald", "examples" ] + + # This will be ignored with Rust older than 1.74, but for now that's okay; + # we're only using it to fix check-cfg issues that first appeared in Rust 1.80. +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ["cfg(flaky_tests)", "cfg(tracing_unstable)"] } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 48de191a97..9c07e33415 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -50,9 +50,12 @@ tempfile = "3" snafu = "0.6.10" thiserror = "1.0.31" -# valuable examples +# valuable examples valuable = { version = "0.1.0", features = ["derive"] } [target.'cfg(tracing_unstable)'.dependencies] tracing-core = { path = "../tracing-core", version = "0.1.28", features = ["valuable"]} tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = ["json", "env-filter", "valuable"]} + +[lints] +workspace = true diff --git a/examples/examples/sloggish/sloggish_subscriber.rs b/examples/examples/sloggish/sloggish_subscriber.rs index 971e607fda..e551811557 100644 --- a/examples/examples/sloggish/sloggish_subscriber.rs +++ b/examples/examples/sloggish/sloggish_subscriber.rs @@ -38,7 +38,7 @@ pub struct CurrentSpanPerThread { impl CurrentSpanPerThread { pub fn new() -> Self { thread_local! { - static CURRENT: RefCell> = RefCell::new(vec![]); + static CURRENT: RefCell> = const { RefCell::new(vec![]) }; }; Self { current: &CURRENT } } diff --git a/tracing-appender/src/lib.rs b/tracing-appender/src/lib.rs index 6e18fbb11c..66ad227ee6 100644 --- a/tracing-appender/src/lib.rs +++ b/tracing-appender/src/lib.rs @@ -24,7 +24,7 @@ //! - Using a [`RollingFileAppender`][rolling_struct] to perform writes to a log file. This will block on writes. //! - Using *any* type implementing [`std::io::Write`][write] in a non-blocking fashion. //! - Using a combination of [`NonBlocking`][non_blocking] and [`RollingFileAppender`][rolling_struct] to allow writes to a log file -//! without blocking. +//! without blocking. //! //! ## File Appender //! diff --git a/tracing-appender/src/rolling.rs b/tracing-appender/src/rolling.rs index cce6139871..cc148480d7 100644 --- a/tracing-appender/src/rolling.rs +++ b/tracing-appender/src/rolling.rs @@ -10,11 +10,11 @@ //! The following helpers are available for creating a rolling file appender. //! //! - [`Rotation::minutely()`][minutely]: A new log file in the format of `some_directory/log_file_name_prefix.yyyy-MM-dd-HH-mm` -//! will be created minutely (once per minute) +//! will be created minutely (once per minute) //! - [`Rotation::hourly()`][hourly]: A new log file in the format of `some_directory/log_file_name_prefix.yyyy-MM-dd-HH` -//! will be created hourly +//! will be created hourly //! - [`Rotation::daily()`][daily]: A new log file in the format of `some_directory/log_file_name_prefix.yyyy-MM-dd` -//! will be created daily +//! will be created daily //! - [`Rotation::never()`][never()]: This will result in log file located at `some_directory/log_file_name` //! //! diff --git a/tracing-attributes/Cargo.toml b/tracing-attributes/Cargo.toml index 60e575984c..6dff74311d 100644 --- a/tracing-attributes/Cargo.toml +++ b/tracing-attributes/Cargo.toml @@ -54,3 +54,6 @@ rustversion = "1.0.9" [badges] maintenance = { status = "experimental" } + +[lints] +workspace = true diff --git a/tracing-attributes/tests/instrument.rs b/tracing-attributes/tests/instrument.rs index 351ae53e18..c5e816045b 100644 --- a/tracing-attributes/tests/instrument.rs +++ b/tracing-attributes/tests/instrument.rs @@ -100,7 +100,7 @@ fn fields() { #[test] fn skip() { - struct UnDebug(pub u32); + struct UnDebug(); #[instrument(target = "my_target", level = "debug", skip(_arg2, _arg3))] fn my_fn(arg1: usize, _arg2: UnDebug, _arg3: UnDebug) {} @@ -147,9 +147,9 @@ fn skip() { .run_with_handle(); with_default(subscriber, || { - my_fn(2, UnDebug(0), UnDebug(1)); - my_fn(3, UnDebug(0), UnDebug(1)); - my_fn2(2, UnDebug(0), UnDebug(1)); + my_fn(2, UnDebug(), UnDebug()); + my_fn(3, UnDebug(), UnDebug()); + my_fn2(2, UnDebug(), UnDebug()); }); handle.assert_finished(); diff --git a/tracing-core/Cargo.toml b/tracing-core/Cargo.toml index e4f1bed1cd..ee34231a89 100644 --- a/tracing-core/Cargo.toml +++ b/tracing-core/Cargo.toml @@ -46,3 +46,6 @@ rustdoc-args = ["--cfg", "docsrs", "--cfg", "tracing_unstable"] # it's necessary to _also_ pass `--cfg tracing_unstable` to rustc, or else # dependencies will not be enabled, and the docs build will fail. rustc-args = ["--cfg", "tracing_unstable"] + +[lints] +workspace = true diff --git a/tracing-core/src/dispatcher.rs b/tracing-core/src/dispatcher.rs index de02afb790..deb56f7341 100644 --- a/tracing-core/src/dispatcher.rs +++ b/tracing-core/src/dispatcher.rs @@ -123,6 +123,8 @@ //! currently default `Dispatch`. This is used primarily by `tracing` //! instrumentation. //! +use core::ptr::addr_of; + use crate::{ callsite, span, subscriber::{self, NoSubscriber, Subscriber}, @@ -144,12 +146,6 @@ use crate::stdlib::{ error, }; -#[cfg(feature = "alloc")] -use alloc::sync::{Arc, Weak}; - -#[cfg(feature = "alloc")] -use core::ops::Deref; - /// `Dispatch` trace data to a [`Subscriber`]. #[derive(Clone)] pub struct Dispatch { @@ -187,10 +183,10 @@ enum Kind { #[cfg(feature = "std")] thread_local! { - static CURRENT_STATE: State = State { + static CURRENT_STATE: State = const { State { default: RefCell::new(None), can_enter: Cell::new(true), - }; + } }; } static EXISTS: AtomicBool = AtomicBool::new(false); @@ -455,7 +451,7 @@ fn get_global() -> &'static Dispatch { unsafe { // This is safe given the invariant that setting the global dispatcher // also sets `GLOBAL_INIT` to `INITIALIZED`. - &GLOBAL_DISPATCH + &*addr_of!(GLOBAL_DISPATCH) } } diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index 90c4eaa85d..2267407164 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -836,10 +836,7 @@ impl FieldSet { /// Returns the [`Field`] named `name`, or `None` if no such field exists. /// /// [`Field`]: super::Field - pub fn field(&self, name: &Q) -> Option - where - Q: Borrow, - { + pub fn field + ?Sized>(&self, name: &Q) -> Option { let name = &name.borrow(); self.names.iter().position(|f| f == name).map(|i| Field { i, @@ -1090,8 +1087,8 @@ mod test { use crate::stdlib::{borrow::ToOwned, string::String}; // Make sure TEST_CALLSITE_* have non-zero size, so they can't be located at the same address. - struct TestCallsite1(u8); - static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(0); + struct TestCallsite1(); + static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(); static TEST_META_1: Metadata<'static> = metadata! { name: "field_test1", target: module_path!(), @@ -1111,8 +1108,8 @@ mod test { } } - struct TestCallsite2(u8); - static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(0); + struct TestCallsite2(); + static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(); static TEST_META_2: Metadata<'static> = metadata! { name: "field_test2", target: module_path!(), diff --git a/tracing-error/src/lib.rs b/tracing-error/src/lib.rs index 4dfbfed5e7..138aa92adf 100644 --- a/tracing-error/src/lib.rs +++ b/tracing-error/src/lib.rs @@ -26,10 +26,10 @@ //! //! - `traced-error` - Enables the [`TracedError`] type and related Traits //! - [`InstrumentResult`] and [`InstrumentError`] extension traits, which -//! provide an [`in_current_span()`] method for bundling errors with a -//! [`SpanTrace`]. +//! provide an [`in_current_span()`] method for bundling errors with a +//! [`SpanTrace`]. //! - [`ExtractSpanTrace`] extension trait, for extracting `SpanTrace`s from -//! behind `dyn Error` trait objects. +//! behind `dyn Error` trait objects. //! //! ## Usage //! diff --git a/tracing-futures/Cargo.toml b/tracing-futures/Cargo.toml index 5dc17394b7..c03c222d85 100644 --- a/tracing-futures/Cargo.toml +++ b/tracing-futures/Cargo.toml @@ -51,3 +51,6 @@ maintenance = { status = "actively-developed" } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/tracing-futures/src/executor/futures_01.rs b/tracing-futures/src/executor/futures_01.rs index 7d4b674af8..fb558878a2 100644 --- a/tracing-futures/src/executor/futures_01.rs +++ b/tracing-futures/src/executor/futures_01.rs @@ -35,7 +35,7 @@ where } #[cfg(feature = "tokio")] -#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 +#[allow(unreachable_pub, unused_imports)] // https://github.com/rust-lang/rust/issues/57411 pub use self::tokio::*; #[cfg(feature = "tokio")] diff --git a/tracing-futures/src/executor/futures_preview.rs b/tracing-futures/src/executor/futures_preview.rs deleted file mode 100644 index a9fdd6ef6a..0000000000 --- a/tracing-futures/src/executor/futures_preview.rs +++ /dev/null @@ -1,121 +0,0 @@ -use crate::stdlib::future::Future; -use crate::{Instrument, Instrumented, WithDispatch}; -use futures_core_preview::{ - future::FutureObj, - task::{LocalSpawn, Spawn, SpawnError}, -}; - -impl Spawn for Instrumented -where - T: Spawn, -{ - /// Spawns a future that will be run to completion. - /// - /// # Errors - /// - /// The executor may be unable to spawn tasks. Spawn errors should - /// represent relatively rare scenarios, such as the executor - /// having been shut down so that it is no longer able to accept - /// tasks. - fn spawn_obj(&mut self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - let future = future.instrument(self.span.clone()); - self.inner.spawn_obj(Box::pin(future)) - } - - /// Determines whether the executor is able to spawn new tasks. - /// - /// This method will return `Ok` when the executor is *likely* - /// (but not guaranteed) to accept a subsequent spawn attempt. - /// Likewise, an `Err` return means that `spawn` is likely, but - /// not guaranteed, to yield an error. - #[inline] - fn status(&self) -> Result<(), SpawnError> { - self.inner.status() - } -} - -impl Spawn for WithDispatch -where - T: Spawn, -{ - /// Spawns a future that will be run to completion. - /// - /// # Errors - /// - /// The executor may be unable to spawn tasks. Spawn errors should - /// represent relatively rare scenarios, such as the executor - /// having been shut down so that it is no longer able to accept - /// tasks. - fn spawn_obj(&mut self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - self.inner.spawn_obj(Box::pin(self.with_dispatch(future))) - } - - /// Determines whether the executor is able to spawn new tasks. - /// - /// This method will return `Ok` when the executor is *likely* - /// (but not guaranteed) to accept a subsequent spawn attempt. - /// Likewise, an `Err` return means that `spawn` is likely, but - /// not guaranteed, to yield an error. - #[inline] - fn status(&self) -> Result<(), SpawnError> { - self.inner.status() - } -} - -impl LocalSpawn for Instrumented -where - T: LocalSpawn, -{ - /// Spawns a future that will be run to completion. - /// - /// # Errors - /// - /// The executor may be unable to spawn tasks. Spawn errors should - /// represent relatively rare scenarios, such as the executor - /// having been shut down so that it is no longer able to accept - /// tasks. - fn spawn_local_obj(&mut self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - let future = future.instrument(self.span.clone()); - self.inner.spawn_local_obj(Box::pin(future)) - } - - /// Determines whether the executor is able to spawn new tasks. - /// - /// This method will return `Ok` when the executor is *likely* - /// (but not guaranteed) to accept a subsequent spawn attempt. - /// Likewise, an `Err` return means that `spawn` is likely, but - /// not guaranteed, to yield an error. - #[inline] - fn status_local(&self) -> Result<(), SpawnError> { - self.inner.status_local() - } -} - -impl LocalSpawn for WithDispatch -where - T: Spawn, -{ - /// Spawns a future that will be run to completion. - /// - /// # Errors - /// - /// The executor may be unable to spawn tasks. Spawn errors should - /// represent relatively rare scenarios, such as the executor - /// having been shut down so that it is no longer able to accept - /// tasks. - fn spawn_local_obj(&mut self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - self.inner - .spawn_local_obj(Box::pin(self.with_dispatch(future))) - } - - /// Determines whether the executor is able to spawn new tasks. - /// - /// This method will return `Ok` when the executor is *likely* - /// (but not guaranteed) to accept a subsequent spawn attempt. - /// Likewise, an `Err` return means that `spawn` is likely, but - /// not guaranteed, to yield an error. - #[inline] - fn status_local(&self) -> Result<(), SpawnError> { - self.inner.status_local() - } -} diff --git a/tracing-futures/src/executor/mod.rs b/tracing-futures/src/executor/mod.rs index ced3b5a460..1e646cafc1 100644 --- a/tracing-futures/src/executor/mod.rs +++ b/tracing-futures/src/executor/mod.rs @@ -1,12 +1,8 @@ #[cfg(feature = "futures-01")] mod futures_01; -#[cfg(feature = "futures_preview")] -mod futures_preview; -#[cfg(feature = "futures_preview")] -pub use self::futures_preview::*; - #[cfg(feature = "futures-03")] mod futures_03; +#[allow(unreachable_pub, unused_imports)] #[cfg(feature = "futures-03")] -pub use self::futures_03::*; +pub use futures_03::*; diff --git a/tracing-futures/tests/std_future.rs b/tracing-futures/tests/std_future.rs index 4f29fd73cd..ba35de6f8f 100644 --- a/tracing-futures/tests/std_future.rs +++ b/tracing-futures/tests/std_future.rs @@ -54,6 +54,7 @@ fn span_on_drop() { } } + #[allow(dead_code)] // Field unused, but logs on `Drop` struct Fut(Option); impl Future for Fut { diff --git a/tracing-journald/Cargo.toml b/tracing-journald/Cargo.toml index 2ccbb1d39d..6cb80c7ac6 100644 --- a/tracing-journald/Cargo.toml +++ b/tracing-journald/Cargo.toml @@ -24,3 +24,6 @@ tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", defaul serde_json = "1.0.82" serde = { version = "1.0.140", features = ["derive"] } tracing = { path = "../tracing", version = "0.1.35" } + +[lints] +workspace = true diff --git a/tracing-log/Cargo.toml b/tracing-log/Cargo.toml index dad4cf366d..df2f612fea 100644 --- a/tracing-log/Cargo.toml +++ b/tracing-log/Cargo.toml @@ -45,3 +45,6 @@ rustdoc-args = ["--cfg", "docsrs"] [[bench]] name = "logging" harness = false + +[lints] +workspace = true diff --git a/tracing-log/src/interest_cache.rs b/tracing-log/src/interest_cache.rs index aabf9ebaf7..5ad9c1362e 100644 --- a/tracing-log/src/interest_cache.rs +++ b/tracing-log/src/interest_cache.rs @@ -235,7 +235,7 @@ mod tests { fn lock_for_test() -> impl Drop { // We need to make sure only one test runs at a time. - static LOCK: Lazy> = Lazy::new(Mutex::new); + static LOCK: Lazy> = Lazy::new(|| Mutex::new(())); match LOCK.lock() { Ok(guard) => guard, diff --git a/tracing-macros/Cargo.toml b/tracing-macros/Cargo.toml index f0d1ff7896..703ca6fbee 100644 --- a/tracing-macros/Cargo.toml +++ b/tracing-macros/Cargo.toml @@ -25,3 +25,6 @@ tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", featur [badges] maintenance = { status = "experimental" } + +[lints] +workspace = true diff --git a/tracing-mock/Cargo.toml b/tracing-mock/Cargo.toml index c87cf6524e..ca2bebb1eb 100644 --- a/tracing-mock/Cargo.toml +++ b/tracing-mock/Cargo.toml @@ -29,3 +29,6 @@ tokio-stream = { version = "0.1.9", optional = true } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/tracing-serde/Cargo.toml b/tracing-serde/Cargo.toml index b3bab80eb4..cc4ca471a8 100644 --- a/tracing-serde/Cargo.toml +++ b/tracing-serde/Cargo.toml @@ -34,3 +34,6 @@ valuable-serde = { version = "0.1.0", optional = true, default-features = false [badges] maintenance = { status = "experimental" } + +[lints] +workspace = true diff --git a/tracing-serde/src/lib.rs b/tracing-serde/src/lib.rs index 2ef8a5b774..801280e0ff 100644 --- a/tracing-serde/src/lib.rs +++ b/tracing-serde/src/lib.rs @@ -199,18 +199,6 @@ use tracing_core::{ pub mod fields; -#[derive(Debug)] -pub struct SerializeField(Field); - -impl Serialize for SerializeField { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(self.0.name()) - } -} - #[derive(Debug)] pub struct SerializeFieldSet<'a>(&'a FieldSet); diff --git a/tracing-subscriber/Cargo.toml b/tracing-subscriber/Cargo.toml index 807880b8cd..ad796f5a7e 100644 --- a/tracing-subscriber/Cargo.toml +++ b/tracing-subscriber/Cargo.toml @@ -36,6 +36,7 @@ valuable = ["tracing-core/valuable", "valuable_crate", "valuable-serde", "tracin # Enables support for local time when using the `time` crate timestamp # formatters. local-time = ["time/local-offset"] +nu-ansi-term = ["dep:nu-ansi-term"] [dependencies] tracing-core = { path = "../tracing-core", version = "0.1.30", default-features = false } @@ -103,3 +104,6 @@ harness = false [[bench]] name = "enter" harness = false + +[lints] +workspace = true diff --git a/tracing-subscriber/src/filter/env/builder.rs b/tracing-subscriber/src/filter/env/builder.rs index 8afe117c51..ce93687527 100644 --- a/tracing-subscriber/src/filter/env/builder.rs +++ b/tracing-subscriber/src/filter/env/builder.rs @@ -210,15 +210,15 @@ impl Builder { } if !disabled.is_empty() { - #[cfg(feature = "nu_ansi_term")] + #[cfg(feature = "nu-ansi-term")] use nu_ansi_term::{Color, Style}; // NOTE: We can't use a configured `MakeWriter` because the EnvFilter // has no knowledge of any underlying subscriber or subscriber, which // may or may not use a `MakeWriter`. let warn = |msg: &str| { - #[cfg(not(feature = "nu_ansi_term"))] + #[cfg(not(feature = "nu-ansi-term"))] let msg = format!("warning: {}", msg); - #[cfg(feature = "nu_ansi_term")] + #[cfg(feature = "nu-ansi-term")] let msg = { let bold = Style::new().bold(); let mut warning = Color::Yellow.paint("warning"); @@ -228,9 +228,9 @@ impl Builder { eprintln!("{}", msg); }; let ctx_prefixed = |prefix: &str, msg: &str| { - #[cfg(not(feature = "nu_ansi_term"))] + #[cfg(not(feature = "nu-ansi-term"))] let msg = format!("{} {}", prefix, msg); - #[cfg(feature = "nu_ansi_term")] + #[cfg(feature = "nu-ansi-term")] let msg = { let mut equal = Color::Fixed(21).paint("="); // dark blue equal.style_ref_mut().is_bold = true; @@ -241,9 +241,9 @@ impl Builder { let ctx_help = |msg| ctx_prefixed("help:", msg); let ctx_note = |msg| ctx_prefixed("note:", msg); let ctx = |msg: &str| { - #[cfg(not(feature = "nu_ansi_term"))] + #[cfg(not(feature = "nu-ansi-term"))] let msg = format!("note: {}", msg); - #[cfg(feature = "nu_ansi_term")] + #[cfg(feature = "nu-ansi-term")] let msg = { let mut pipe = Color::Fixed(21).paint("|"); pipe.style_ref_mut().is_bold = true; diff --git a/tracing-subscriber/src/filter/env/field.rs b/tracing-subscriber/src/filter/env/field.rs index 1394fd04a6..30f57ec942 100644 --- a/tracing-subscriber/src/filter/env/field.rs +++ b/tracing-subscriber/src/filter/env/field.rs @@ -267,7 +267,7 @@ impl fmt::Display for ValueMatch { match self { ValueMatch::Bool(ref inner) => fmt::Display::fmt(inner, f), ValueMatch::F64(ref inner) => fmt::Display::fmt(inner, f), - ValueMatch::NaN => fmt::Display::fmt(&std::f64::NAN, f), + ValueMatch::NaN => fmt::Display::fmt(&f64::NAN, f), ValueMatch::I64(ref inner) => fmt::Display::fmt(inner, f), ValueMatch::U64(ref inner) => fmt::Display::fmt(inner, f), ValueMatch::Debug(ref inner) => fmt::Display::fmt(inner, f), @@ -507,7 +507,7 @@ impl<'a> Visit for MatchVisitor<'a> { matched.store(true, Release); } Some((ValueMatch::F64(ref e), ref matched)) - if (value - *e).abs() < std::f64::EPSILON => + if (value - *e).abs() < f64::EPSILON => { matched.store(true, Release); } diff --git a/tracing-subscriber/src/filter/layer_filters/mod.rs b/tracing-subscriber/src/filter/layer_filters/mod.rs index 69736fafd4..040eb705f7 100644 --- a/tracing-subscriber/src/filter/layer_filters/mod.rs +++ b/tracing-subscriber/src/filter/layer_filters/mod.rs @@ -886,7 +886,7 @@ where impl FilterId { const fn disabled() -> Self { - Self(std::u64::MAX) + Self(u64::MAX) } /// Returns a `FilterId` that will consider _all_ spans enabled. @@ -1029,7 +1029,7 @@ impl FilterExt for F where F: layer::Filter {} impl FilterMap { pub(crate) fn set(self, FilterId(mask): FilterId, enabled: bool) -> Self { - if mask == std::u64::MAX { + if mask == u64::MAX { return self; } @@ -1051,7 +1051,7 @@ impl FilterMap { #[inline] pub(crate) fn any_enabled(self) -> bool { - self.bits != std::u64::MAX + self.bits != u64::MAX } } diff --git a/tracing-subscriber/src/fmt/fmt_layer.rs b/tracing-subscriber/src/fmt/fmt_layer.rs index d3cb8c1ed5..54c84e422c 100644 --- a/tracing-subscriber/src/fmt/fmt_layer.rs +++ b/tracing-subscriber/src/fmt/fmt_layer.rs @@ -572,7 +572,7 @@ where /// # Options /// /// - [`Layer::flatten_event`] can be used to enable flattening event fields into the root - /// object. + /// object. /// /// [`Layer::flatten_event`]: Layer::flatten_event() #[cfg(feature = "json")] @@ -943,7 +943,7 @@ where fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { thread_local! { - static BUF: RefCell = RefCell::new(String::new()); + static BUF: RefCell = const { RefCell::new(String::new()) }; } BUF.with(|buf| { diff --git a/tracing-subscriber/src/fmt/format/json.rs b/tracing-subscriber/src/fmt/format/json.rs index bf32f7c9a8..7799abb6e0 100644 --- a/tracing-subscriber/src/fmt/format/json.rs +++ b/tracing-subscriber/src/fmt/format/json.rs @@ -60,11 +60,11 @@ use tracing_log::NormalizeEvent; /// output JSON objects: /// /// - [`Json::flatten_event`] can be used to enable flattening event fields into -/// the root +/// the root /// - [`Json::with_current_span`] can be used to control logging of the current -/// span +/// span /// - [`Json::with_span_list`] can be used to control logging of the span list -/// object. +/// object. /// /// By default, event fields are not flattened, and both current span and span /// list are logged. diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index 80612e1ec2..4e36ca0069 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -674,7 +674,7 @@ impl Format { /// # Options /// /// - [`Format::flatten_event`] can be used to enable flattening event fields into the root - /// object. + /// object. #[cfg(feature = "json")] #[cfg_attr(docsrs, doc(cfg(feature = "json")))] pub fn json(self) -> Format { diff --git a/tracing-subscriber/src/fmt/time/chrono_crate.rs b/tracing-subscriber/src/fmt/time/chrono_crate.rs index 1a831efa1b..def3b3b6c4 100644 --- a/tracing-subscriber/src/fmt/time/chrono_crate.rs +++ b/tracing-subscriber/src/fmt/time/chrono_crate.rs @@ -109,18 +109,15 @@ impl FormatTime for ChronoUtc { /// /// [`chrono::format::strftime`]: https://docs.rs/chrono/0.4.9/chrono/format/strftime/index.html #[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Default)] enum ChronoFmtType { /// Format according to the RFC 3339 convention. + #[default] Rfc3339, /// Format according to a custom format string. Custom(String), } -impl Default for ChronoFmtType { - fn default() -> Self { - ChronoFmtType::Rfc3339 - } -} #[cfg(test)] mod tests { diff --git a/tracing-subscriber/src/fmt/time/datetime.rs b/tracing-subscriber/src/fmt/time/datetime.rs index 5313316870..2a1d3cfbb5 100644 --- a/tracing-subscriber/src/fmt/time/datetime.rs +++ b/tracing-subscriber/src/fmt/time/datetime.rs @@ -247,12 +247,12 @@ impl From for DateTime { fn from(timestamp: std::time::SystemTime) -> DateTime { let (t, nanos) = match timestamp.duration_since(std::time::UNIX_EPOCH) { Ok(duration) => { - debug_assert!(duration.as_secs() <= std::i64::MAX as u64); + debug_assert!(duration.as_secs() <= i64::MAX as u64); (duration.as_secs() as i64, duration.subsec_nanos()) } Err(error) => { let duration = error.duration(); - debug_assert!(duration.as_secs() <= std::i64::MAX as u64); + debug_assert!(duration.as_secs() <= i64::MAX as u64); let (secs, nanos) = (duration.as_secs() as i64, duration.subsec_nanos()); if nanos == 0 { (-secs, 0) @@ -332,7 +332,7 @@ impl From for DateTime { #[cfg(test)] mod tests { - use std::i32; + use i32; use std::time::{Duration, UNIX_EPOCH}; use super::*; @@ -382,8 +382,8 @@ mod tests { 1, ); - case("2038-01-19T03:14:07.000000Z", std::i32::MAX as i64, 0); - case("2038-01-19T03:14:08.000000Z", std::i32::MAX as i64 + 1, 0); + case("2038-01-19T03:14:07.000000Z", i32::MAX as i64, 0); + case("2038-01-19T03:14:08.000000Z", i32::MAX as i64 + 1, 0); case("1901-12-13T20:45:52.000000Z", i32::MIN as i64, 0); case("1901-12-13T20:45:51.000000Z", i32::MIN as i64 - 1, 0); @@ -392,8 +392,8 @@ mod tests { // high date value tests to panic #[cfg(not(target_os = "windows"))] { - case("+292277026596-12-04T15:30:07.000000Z", std::i64::MAX, 0); - case("+292277026596-12-04T15:30:06.000000Z", std::i64::MAX - 1, 0); + case("+292277026596-12-04T15:30:07.000000Z", i64::MAX, 0); + case("+292277026596-12-04T15:30:06.000000Z", i64::MAX - 1, 0); case("-292277022657-01-27T08:29:53.000000Z", i64::MIN + 1, 0); } diff --git a/tracing-subscriber/src/fmt/writer.rs b/tracing-subscriber/src/fmt/writer.rs index bbc1c4a298..961a127713 100644 --- a/tracing-subscriber/src/fmt/writer.rs +++ b/tracing-subscriber/src/fmt/writer.rs @@ -654,6 +654,9 @@ pub struct MutexGuardWriter<'a, W>(MutexGuard<'a, W>); /// Implements [`std::io::Write`] for an [`Arc`] where `&W: Write`. /// /// This is an implementation detail of the [`MakeWriter`] impl for [`Arc`]. +#[doc(hidden)] +#[deprecated(since = "0.1.19", note = "unused implementation detail -- do not use")] +#[allow(dead_code)] #[derive(Clone, Debug)] pub struct ArcWriter(Arc); @@ -1134,6 +1137,7 @@ where // === impl ArcWriter === +#[allow(deprecated)] impl io::Write for ArcWriter where for<'a> &'a W: io::Write, diff --git a/tracing-subscriber/src/layer/mod.rs b/tracing-subscriber/src/layer/mod.rs index 296de5ef48..8543e2b08c 100644 --- a/tracing-subscriber/src/layer/mod.rs +++ b/tracing-subscriber/src/layer/mod.rs @@ -567,9 +567,10 @@ //! //! Consider the following: //! - `layer_a` and `layer_b`, which should only receive spans and events at -//! the [`INFO`] [level] and above. +//! the [`INFO`] [level] and above. //! - A third layer, `layer_c`, which should receive spans and events at -//! the [`DEBUG`] [level] as well. +//! the [`DEBUG`] [level] as well. +//! //! The layers and filters would be composed thusly: //! //! ``` diff --git a/tracing-subscriber/src/lib.rs b/tracing-subscriber/src/lib.rs index a6b570ee4f..373f76310a 100644 --- a/tracing-subscriber/src/lib.rs +++ b/tracing-subscriber/src/lib.rs @@ -240,7 +240,7 @@ feature! { #![all(feature = "registry", feature = "std")] pub use registry::Registry; - /// + /// Returns a default [`Registry`]. pub fn registry() -> Registry { Registry::default() } diff --git a/tracing-subscriber/src/registry/sharded.rs b/tracing-subscriber/src/registry/sharded.rs index 88520a2a66..17a3775cab 100644 --- a/tracing-subscriber/src/registry/sharded.rs +++ b/tracing-subscriber/src/registry/sharded.rs @@ -214,7 +214,7 @@ thread_local! { /// track how many layers have processed the close. /// For additional details, see [`CloseGuard`]. /// - static CLOSE_COUNT: Cell = Cell::new(0); + static CLOSE_COUNT: Cell = const { Cell::new(0) }; } impl Subscriber for Registry { @@ -352,7 +352,7 @@ impl Subscriber for Registry { let refs = span.ref_count.fetch_sub(1, Ordering::Release); if !std::thread::panicking() { - assert!(refs < std::usize::MAX, "reference count overflow!"); + assert!(refs < usize::MAX, "reference count overflow!"); } if refs > 1 { return false; @@ -545,10 +545,6 @@ mod tests { Subscriber, }; - #[derive(Debug)] - struct DoesNothing; - impl Layer for DoesNothing {} - struct AssertionLayer; impl Layer for AssertionLayer where @@ -596,6 +592,7 @@ mod tests { closed: Vec<(&'static str, Weak<()>)>, } + #[allow(dead_code)] // Field is exercised via checking `Arc::downgrade()` struct SetRemoved(Arc<()>); impl Layer for CloseLayer diff --git a/tracing-tower/Cargo.toml b/tracing-tower/Cargo.toml index 8e958e2d05..38e265d224 100644 --- a/tracing-tower/Cargo.toml +++ b/tracing-tower/Cargo.toml @@ -40,3 +40,6 @@ maintenance = { status = "experimental" } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/tracing-tower/src/lib.rs b/tracing-tower/src/lib.rs index 68345a7d68..f987a4ec7c 100644 --- a/tracing-tower/src/lib.rs +++ b/tracing-tower/src/lib.rs @@ -70,33 +70,8 @@ where } } -#[cfg(feature = "tower-util")] -#[cfg_attr(docsrs, doc(cfg(feature = "tower-util")))] -pub trait InstrumentMake -where - Self: tower_util::MakeService + Sized, -{ - fn with_traced_service(self, get_span: G) -> service_span::MakeService - where - G: GetSpan, - { - service_span::MakeService::new(self, get_span) - } - - fn with_traced_requests(self, get_span: G) -> request_span::MakeService - where - G: GetSpan + Clone, - { - request_span::MakeService::new(self, get_span) - } -} - impl InstrumentableService for S where S: Service + Sized {} -#[cfg(feature = "tower-util")] -#[cfg_attr(docsrs, doc(cfg(feature = "tower-util")))] -impl InstrumentMake for M where M: tower_util::MakeService {} - pub trait GetSpan: crate::sealed::Sealed { fn span_for(&self, target: &T) -> tracing::Span; } diff --git a/tracing-tower/src/service_span.rs b/tracing-tower/src/service_span.rs index 5e0fc9a610..7642e6552c 100644 --- a/tracing-tower/src/service_span.rs +++ b/tracing-tower/src/service_span.rs @@ -16,10 +16,6 @@ pub struct Service { #[cfg_attr(docsrs, doc(cfg(feature = "tower-layer")))] pub use self::layer::*; -#[cfg(feature = "tower-util")] -#[cfg_attr(docsrs, doc(cfg(feature = "tower-util")))] -pub use self::make::MakeService; - #[cfg(feature = "tower-layer")] #[cfg_attr(docsrs, doc(cfg(feature = "tower-layer")))] mod layer { diff --git a/tracing/Cargo.toml b/tracing/Cargo.toml index bcad05c640..c1b1041759 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -34,8 +34,8 @@ tracing-attributes = { path = "../tracing-attributes", version = "0.1.27", optio pin-project-lite = "0.2.9" [dev-dependencies] -criterion = { version = "0.3.6", default_features = false } -futures = { version = "0.3.21", default_features = false } +criterion = { version = "0.3.6", default-features = false } +futures = { version = "0.3.21", default-features = false } log = "0.4.17" tracing-mock = { path = "../tracing-mock" } @@ -113,3 +113,6 @@ rustdoc-args = ["--cfg", "docsrs", "--cfg", "tracing_unstable"] # it's necessary to _also_ pass `--cfg tracing_unstable` to rustc, or else # dependencies will not be enabled, and the docs build will fail. rustc-args = ["--cfg", "tracing_unstable"] + +[lints] +workspace = true diff --git a/tracing/src/macros.rs b/tracing/src/macros.rs index 676a3a5812..a3115ecf3e 100644 --- a/tracing/src/macros.rs +++ b/tracing/src/macros.rs @@ -1117,15 +1117,15 @@ macro_rules! span_enabled { /// in false positives or false negatives include: /// /// - If a subscriber is using a filter which may enable a span or event based -/// on field names, but `enabled!` is invoked without listing field names, -/// `enabled!` may return a false negative if a specific field name would -/// cause the subscriber to enable something that would otherwise be disabled. +/// on field names, but `enabled!` is invoked without listing field names, +/// `enabled!` may return a false negative if a specific field name would +/// cause the subscriber to enable something that would otherwise be disabled. /// - If a subscriber is using a filter which enables or disables specific events by -/// file path and line number, a particular event may be enabled/disabled -/// even if an `enabled!` invocation with the same level, target, and fields -/// indicated otherwise. +/// file path and line number, a particular event may be enabled/disabled +/// even if an `enabled!` invocation with the same level, target, and fields +/// indicated otherwise. /// - The subscriber can choose to enable _only_ spans or _only_ events, which `enabled` -/// will not reflect. +/// will not reflect. /// /// `enabled!()` requires a [level](crate::Level) argument, an optional `target:` /// argument, and an optional set of field names. If the fields are not provided, diff --git a/tracing/src/span.rs b/tracing/src/span.rs index 3c235dc792..808539144c 100644 --- a/tracing/src/span.rs +++ b/tracing/src/span.rs @@ -1104,20 +1104,14 @@ impl Span { /// Returns a [`Field`][super::field::Field] for the field with the /// given `name`, if one exists, - pub fn field(&self, field: &Q) -> Option - where - Q: field::AsField, - { + pub fn field(&self, field: &Q) -> Option { self.metadata().and_then(|meta| field.as_field(meta)) } /// Returns true if this `Span` has a field for the given /// [`Field`][super::field::Field] or field name. #[inline] - pub fn has_field(&self, field: &Q) -> bool - where - Q: field::AsField, - { + pub fn has_field(&self, field: &Q) -> bool { self.field(field).is_some() } @@ -1191,11 +1185,11 @@ impl Span { /// /// [`field::Empty`]: super::field::Empty /// [`Metadata`]: super::Metadata - pub fn record(&self, field: &Q, value: V) -> &Self - where - Q: field::AsField, - V: field::Value, - { + pub fn record( + &self, + field: &Q, + value: V, + ) -> &Self { if let Some(meta) = self.meta { if let Some(field) = field.as_field(meta) { self.record_all( @@ -1607,14 +1601,6 @@ unsafe impl Sync for PhantomNotSend {} mod test { use super::*; - trait AssertSend: Send {} - impl AssertSend for Span {} - - trait AssertSync: Sync {} - impl AssertSync for Span {} - impl AssertSync for Entered<'_> {} - impl AssertSync for EnteredSpan {} - #[test] fn test_record_backwards_compat() { Span::current().record("some-key", "some text"); diff --git a/tracing/tests/instrument.rs b/tracing/tests/instrument.rs index 5247249946..9233727d44 100644 --- a/tracing/tests/instrument.rs +++ b/tracing/tests/instrument.rs @@ -21,6 +21,7 @@ fn span_on_drop() { } } + #[allow(dead_code)] // Field not used, but logs on `Drop` struct Fut(Option); impl Future for Fut {