Skip to content

Commit

Permalink
v0.1.x: clean up warnings (tokio-rs#3069)
Browse files Browse the repository at this point in the history
* chore: avoid warnings from unknown cfg flags

* core: address warning for static-mut-refs

* chore: clean up warnings
  • Loading branch information
djc authored Sep 24, 2024
1 parent 6d00d7d commit 70a8678
Show file tree
Hide file tree
Showing 43 changed files with 125 additions and 269 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"] }
5 changes: 4 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/examples/sloggish/sloggish_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct CurrentSpanPerThread {
impl CurrentSpanPerThread {
pub fn new() -> Self {
thread_local! {
static CURRENT: RefCell<Vec<Id>> = RefCell::new(vec![]);
static CURRENT: RefCell<Vec<Id>> = const { RefCell::new(vec![]) };
};
Self { current: &CURRENT }
}
Expand Down
2 changes: 1 addition & 1 deletion tracing-appender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down
6 changes: 3 additions & 3 deletions tracing-appender/src/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
//!
//!
Expand Down
3 changes: 3 additions & 0 deletions tracing-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ rustversion = "1.0.9"

[badges]
maintenance = { status = "experimental" }

[lints]
workspace = true
8 changes: 4 additions & 4 deletions tracing-attributes/tests/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tracing-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 5 additions & 9 deletions tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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 {
Expand Down Expand Up @@ -187,10 +183,10 @@ enum Kind<T> {

#[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);
Expand Down Expand Up @@ -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)
}
}

Expand Down
13 changes: 5 additions & 8 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,7 @@ impl FieldSet {
/// Returns the [`Field`] named `name`, or `None` if no such field exists.
///
/// [`Field`]: super::Field
pub fn field<Q: ?Sized>(&self, name: &Q) -> Option<Field>
where
Q: Borrow<str>,
{
pub fn field<Q: Borrow<str> + ?Sized>(&self, name: &Q) -> Option<Field> {
let name = &name.borrow();
self.names.iter().position(|f| f == name).map(|i| Field {
i,
Expand Down Expand Up @@ -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!(),
Expand All @@ -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!(),
Expand Down
6 changes: 3 additions & 3 deletions tracing-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down
3 changes: 3 additions & 0 deletions tracing-futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ maintenance = { status = "actively-developed" }
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true
2 changes: 1 addition & 1 deletion tracing-futures/src/executor/futures_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
121 changes: 0 additions & 121 deletions tracing-futures/src/executor/futures_preview.rs

This file was deleted.

8 changes: 2 additions & 6 deletions tracing-futures/src/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
1 change: 1 addition & 0 deletions tracing-futures/tests/std_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn span_on_drop() {
}
}

#[allow(dead_code)] // Field unused, but logs on `Drop`
struct Fut(Option<AssertSpanOnDrop>);

impl Future for Fut {
Expand Down
3 changes: 3 additions & 0 deletions tracing-journald/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions tracing-log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ rustdoc-args = ["--cfg", "docsrs"]
[[bench]]
name = "logging"
harness = false

[lints]
workspace = true
2 changes: 1 addition & 1 deletion tracing-log/src/interest_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<()>> = Lazy::new(Mutex::new);
static LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

match LOCK.lock() {
Ok(guard) => guard,
Expand Down
3 changes: 3 additions & 0 deletions tracing-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", featur

[badges]
maintenance = { status = "experimental" }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions tracing-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions tracing-serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ valuable-serde = { version = "0.1.0", optional = true, default-features = false

[badges]
maintenance = { status = "experimental" }

[lints]
workspace = true
Loading

0 comments on commit 70a8678

Please sign in to comment.