Skip to content

Commit 70a8678

Browse files
authored
v0.1.x: clean up warnings (#3069)
* chore: avoid warnings from unknown cfg flags * core: address warning for static-mut-refs * chore: clean up warnings
1 parent 6d00d7d commit 70a8678

File tree

43 files changed

+125
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+125
-269
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ members = [
1717
"tracing-journald",
1818
"examples"
1919
]
20+
21+
# This will be ignored with Rust older than 1.74, but for now that's okay;
22+
# we're only using it to fix check-cfg issues that first appeared in Rust 1.80.
23+
[workspace.lints.rust]
24+
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(flaky_tests)", "cfg(tracing_unstable)"] }

examples/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ tempfile = "3"
5050
snafu = "0.6.10"
5151
thiserror = "1.0.31"
5252

53-
# valuable examples
53+
# valuable examples
5454
valuable = { version = "0.1.0", features = ["derive"] }
5555

5656
[target.'cfg(tracing_unstable)'.dependencies]
5757
tracing-core = { path = "../tracing-core", version = "0.1.28", features = ["valuable"]}
5858
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = ["json", "env-filter", "valuable"]}
59+
60+
[lints]
61+
workspace = true

examples/examples/sloggish/sloggish_subscriber.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct CurrentSpanPerThread {
3838
impl CurrentSpanPerThread {
3939
pub fn new() -> Self {
4040
thread_local! {
41-
static CURRENT: RefCell<Vec<Id>> = RefCell::new(vec![]);
41+
static CURRENT: RefCell<Vec<Id>> = const { RefCell::new(vec![]) };
4242
};
4343
Self { current: &CURRENT }
4444
}

tracing-appender/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! - Using a [`RollingFileAppender`][rolling_struct] to perform writes to a log file. This will block on writes.
2525
//! - Using *any* type implementing [`std::io::Write`][write] in a non-blocking fashion.
2626
//! - Using a combination of [`NonBlocking`][non_blocking] and [`RollingFileAppender`][rolling_struct] to allow writes to a log file
27-
//! without blocking.
27+
//! without blocking.
2828
//!
2929
//! ## File Appender
3030
//!

tracing-appender/src/rolling.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
//! The following helpers are available for creating a rolling file appender.
1111
//!
1212
//! - [`Rotation::minutely()`][minutely]: A new log file in the format of `some_directory/log_file_name_prefix.yyyy-MM-dd-HH-mm`
13-
//! will be created minutely (once per minute)
13+
//! will be created minutely (once per minute)
1414
//! - [`Rotation::hourly()`][hourly]: A new log file in the format of `some_directory/log_file_name_prefix.yyyy-MM-dd-HH`
15-
//! will be created hourly
15+
//! will be created hourly
1616
//! - [`Rotation::daily()`][daily]: A new log file in the format of `some_directory/log_file_name_prefix.yyyy-MM-dd`
17-
//! will be created daily
17+
//! will be created daily
1818
//! - [`Rotation::never()`][never()]: This will result in log file located at `some_directory/log_file_name`
1919
//!
2020
//!

tracing-attributes/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ rustversion = "1.0.9"
5454

5555
[badges]
5656
maintenance = { status = "experimental" }
57+
58+
[lints]
59+
workspace = true

tracing-attributes/tests/instrument.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn fields() {
100100

101101
#[test]
102102
fn skip() {
103-
struct UnDebug(pub u32);
103+
struct UnDebug();
104104

105105
#[instrument(target = "my_target", level = "debug", skip(_arg2, _arg3))]
106106
fn my_fn(arg1: usize, _arg2: UnDebug, _arg3: UnDebug) {}
@@ -147,9 +147,9 @@ fn skip() {
147147
.run_with_handle();
148148

149149
with_default(subscriber, || {
150-
my_fn(2, UnDebug(0), UnDebug(1));
151-
my_fn(3, UnDebug(0), UnDebug(1));
152-
my_fn2(2, UnDebug(0), UnDebug(1));
150+
my_fn(2, UnDebug(), UnDebug());
151+
my_fn(3, UnDebug(), UnDebug());
152+
my_fn2(2, UnDebug(), UnDebug());
153153
});
154154

155155
handle.assert_finished();

tracing-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ rustdoc-args = ["--cfg", "docsrs", "--cfg", "tracing_unstable"]
4646
# it's necessary to _also_ pass `--cfg tracing_unstable` to rustc, or else
4747
# dependencies will not be enabled, and the docs build will fail.
4848
rustc-args = ["--cfg", "tracing_unstable"]
49+
50+
[lints]
51+
workspace = true

tracing-core/src/dispatcher.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
//! currently default `Dispatch`. This is used primarily by `tracing`
124124
//! instrumentation.
125125
//!
126+
use core::ptr::addr_of;
127+
126128
use crate::{
127129
callsite, span,
128130
subscriber::{self, NoSubscriber, Subscriber},
@@ -144,12 +146,6 @@ use crate::stdlib::{
144146
error,
145147
};
146148

147-
#[cfg(feature = "alloc")]
148-
use alloc::sync::{Arc, Weak};
149-
150-
#[cfg(feature = "alloc")]
151-
use core::ops::Deref;
152-
153149
/// `Dispatch` trace data to a [`Subscriber`].
154150
#[derive(Clone)]
155151
pub struct Dispatch {
@@ -187,10 +183,10 @@ enum Kind<T> {
187183

188184
#[cfg(feature = "std")]
189185
thread_local! {
190-
static CURRENT_STATE: State = State {
186+
static CURRENT_STATE: State = const { State {
191187
default: RefCell::new(None),
192188
can_enter: Cell::new(true),
193-
};
189+
} };
194190
}
195191

196192
static EXISTS: AtomicBool = AtomicBool::new(false);
@@ -455,7 +451,7 @@ fn get_global() -> &'static Dispatch {
455451
unsafe {
456452
// This is safe given the invariant that setting the global dispatcher
457453
// also sets `GLOBAL_INIT` to `INITIALIZED`.
458-
&GLOBAL_DISPATCH
454+
&*addr_of!(GLOBAL_DISPATCH)
459455
}
460456
}
461457

tracing-core/src/field.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,7 @@ impl FieldSet {
836836
/// Returns the [`Field`] named `name`, or `None` if no such field exists.
837837
///
838838
/// [`Field`]: super::Field
839-
pub fn field<Q: ?Sized>(&self, name: &Q) -> Option<Field>
840-
where
841-
Q: Borrow<str>,
842-
{
839+
pub fn field<Q: Borrow<str> + ?Sized>(&self, name: &Q) -> Option<Field> {
843840
let name = &name.borrow();
844841
self.names.iter().position(|f| f == name).map(|i| Field {
845842
i,
@@ -1090,8 +1087,8 @@ mod test {
10901087
use crate::stdlib::{borrow::ToOwned, string::String};
10911088

10921089
// Make sure TEST_CALLSITE_* have non-zero size, so they can't be located at the same address.
1093-
struct TestCallsite1(u8);
1094-
static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(0);
1090+
struct TestCallsite1();
1091+
static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1();
10951092
static TEST_META_1: Metadata<'static> = metadata! {
10961093
name: "field_test1",
10971094
target: module_path!(),
@@ -1111,8 +1108,8 @@ mod test {
11111108
}
11121109
}
11131110

1114-
struct TestCallsite2(u8);
1115-
static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(0);
1111+
struct TestCallsite2();
1112+
static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2();
11161113
static TEST_META_2: Metadata<'static> = metadata! {
11171114
name: "field_test2",
11181115
target: module_path!(),

0 commit comments

Comments
 (0)