diff --git a/Cargo.toml b/Cargo.toml index b83b1fcc47..1624740e6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,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 f10a324c79..fefb90ef05 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -50,3 +50,6 @@ tempfile = "3.3.0" # fmt examples snafu = "0.6.10" thiserror = "1.0.31" + +[lints] +workspace = true diff --git a/tracing-attributes/Cargo.toml b/tracing-attributes/Cargo.toml index 33d988a5cf..145464cd29 100644 --- a/tracing-attributes/Cargo.toml +++ b/tracing-attributes/Cargo.toml @@ -60,3 +60,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 722919fad5..2897316bec 100644 --- a/tracing-attributes/tests/instrument.rs +++ b/tracing-attributes/tests/instrument.rs @@ -100,8 +100,7 @@ fn fields() { #[test] fn skip() { - #[allow(dead_code)] - struct UnDebug(pub u32); + struct UnDebug(); #[instrument(target = "my_target", level = "debug", skip(_arg2, _arg3))] fn my_fn(arg1: usize, _arg2: UnDebug, _arg3: UnDebug) {} @@ -135,8 +134,8 @@ fn skip() { .run_with_handle(); with_default(collector, || { - my_fn(2, UnDebug(0), UnDebug(1)); - my_fn(3, UnDebug(0), UnDebug(1)); + my_fn(2, UnDebug(), UnDebug()); + my_fn(3, UnDebug(), UnDebug()); }); handle.assert_finished(); diff --git a/tracing-core/Cargo.toml b/tracing-core/Cargo.toml index c56b59f262..88ff413eac 100644 --- a/tracing-core/Cargo.toml +++ b/tracing-core/Cargo.toml @@ -39,4 +39,11 @@ once_cell = { version = "1.13.0", optional = true } [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] +# enable unstable features in the documentation +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/field.rs b/tracing-core/src/field.rs index fbaa50dec4..c46b003170 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -999,9 +999,8 @@ mod test { use crate::metadata::{Kind, Level, Metadata}; // Make sure TEST_CALLSITE_* have non-zero size, so they can't be located at the same address. - #[allow(dead_code)] - 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!(), @@ -1021,9 +1020,8 @@ mod test { } } - #[allow(dead_code)] - 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-futures/Cargo.toml b/tracing-futures/Cargo.toml index dc48f28eed..bc600f6a29 100644 --- a/tracing-futures/Cargo.toml +++ b/tracing-futures/Cargo.toml @@ -52,3 +52,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/mod.rs b/tracing-futures/src/executor/mod.rs index 86bad9379c..1e646cafc1 100644 --- a/tracing-futures/src/executor/mod.rs +++ b/tracing-futures/src/executor/mod.rs @@ -3,5 +3,6 @@ mod futures_01; #[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 fb2a31c130..0ee64dacc5 100644 --- a/tracing-futures/tests/std_future.rs +++ b/tracing-futures/tests/std_future.rs @@ -55,7 +55,7 @@ fn span_on_drop() { } } - #[allow(dead_code)] + #[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 ef22014c3d..11e0f05b39 100644 --- a/tracing-journald/Cargo.toml +++ b/tracing-journald/Cargo.toml @@ -25,3 +25,5 @@ serde_json = "1.0.82" serde = { version = "1.0.139", features = ["derive"] } tracing = { path = "../tracing", version = "0.2" } +[lints] +workspace = true diff --git a/tracing-log/Cargo.toml b/tracing-log/Cargo.toml index 8e51f2561c..7caedb5522 100644 --- a/tracing-log/Cargo.toml +++ b/tracing-log/Cargo.toml @@ -37,3 +37,6 @@ maintenance = { status = "actively-maintained" } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/tracing-macros/Cargo.toml b/tracing-macros/Cargo.toml index 3efd4e4374..1c5a74433b 100644 --- a/tracing-macros/Cargo.toml +++ b/tracing-macros/Cargo.toml @@ -25,3 +25,6 @@ tracing-subscriber = { path = "../tracing-subscriber", version = "0.3" } [badges] maintenance = { status = "experimental" } + +[lints] +workspace = true diff --git a/tracing-mock/Cargo.toml b/tracing-mock/Cargo.toml index 22689f3f29..71cc20a25d 100644 --- a/tracing-mock/Cargo.toml +++ b/tracing-mock/Cargo.toml @@ -28,3 +28,6 @@ tokio-stream = "0.1.9" [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 8fb16eeac1..83e186afc5 100644 --- a/tracing-serde/Cargo.toml +++ b/tracing-serde/Cargo.toml @@ -31,3 +31,6 @@ serde_json = "1.0.82" [badges] maintenance = { status = "experimental" } + +[lints] +workspace = true diff --git a/tracing-subscriber/Cargo.toml b/tracing-subscriber/Cargo.toml index 92efbff841..edc7f23468 100644 --- a/tracing-subscriber/Cargo.toml +++ b/tracing-subscriber/Cargo.toml @@ -36,6 +36,7 @@ json = ["tracing-serde", "serde", "serde_json"] # 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.2", default-features = false } @@ -103,6 +104,5 @@ harness = false name = "enter" harness = false -[[bench]] -name = "reload" -harness = false +[lints] +workspace = true diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index f867d228d3..f979121da2 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -679,7 +679,6 @@ impl Format { /// /// - [`Format::flatten_event`] can be used to enable flattening event fields into the root /// 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 e7f58f9890..68cb730c86 100644 --- a/tracing-subscriber/src/fmt/time/datetime.rs +++ b/tracing-subscriber/src/fmt/time/datetime.rs @@ -192,7 +192,6 @@ // permissive licensing, and of not having licensing issues being an // obstacle to adoption, that text has been removed. - use std::fmt; /// A date/time type which exists primarily to convert `SystemTime` timestamps into an ISO 8601 @@ -332,6 +331,7 @@ impl From for DateTime { #[cfg(test)] mod tests { + use i32; use std::time::{Duration, UNIX_EPOCH}; use super::*; @@ -381,6 +381,8 @@ mod tests { 1, ); + 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("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); @@ -391,6 +393,8 @@ mod tests { // high date value tests to panic #[cfg(not(target_os = "windows"))] { + case("+292277026596-12-04T15:30:07.000000Z", i64::MAX, 0); + case("+292277026596-12-04T15:30:06.000000Z", 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/lib.rs b/tracing-subscriber/src/lib.rs index 8f390e19e6..b5787915c2 100644 --- a/tracing-subscriber/src/lib.rs +++ b/tracing-subscriber/src/lib.rs @@ -214,7 +214,7 @@ feature! { /// implementation which tracks per-span data and exposes it to /// [`Subscribe`]s. /// - /// For more information see [`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 0ebcdf9a58..5e586848ec 100644 --- a/tracing-subscriber/src/registry/sharded.rs +++ b/tracing-subscriber/src/registry/sharded.rs @@ -349,6 +349,7 @@ impl Collect for Registry { let refs = span.ref_count.fetch_sub(1, Ordering::Release); if !std::thread::panicking() { assert!(refs < usize::MAX, "reference count overflow!"); + assert!(refs < usize::MAX, "reference count overflow!"); } if refs > 1 { return false; @@ -588,7 +589,7 @@ mod tests { closed: Vec<(&'static str, Weak<()>)>, } - #[allow(dead_code)] + #[allow(dead_code)] // Field is exercised via checking `Arc::downgrade()` struct SetRemoved(Arc<()>); impl Subscribe for CloseSubscriber diff --git a/tracing-tower/Cargo.toml b/tracing-tower/Cargo.toml index 9153e9bdb7..62fdb00cbc 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/Cargo.toml b/tracing/Cargo.toml index a653458fab..4e4a516968 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -108,4 +108,11 @@ maintenance = { status = "actively-developed" } [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] +# enable unstable features in the documentation +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/tests/instrument.rs b/tracing/tests/instrument.rs index 36b7394883..9ab29c7179 100644 --- a/tracing/tests/instrument.rs +++ b/tracing/tests/instrument.rs @@ -21,7 +21,7 @@ fn span_on_drop() { } } - #[allow(dead_code)] + #[allow(dead_code)] // Field not used, but logs on `Drop` struct Fut(Option); impl Future for Fut {