Skip to content

Commit 1edb78c

Browse files
authored
feat(log): reduce unused warnings (#924)
* fix(log): reduce unused warnings * refactor: remove workarounds * fix(ws): typo * fix(log): handle params
1 parent 37da6da commit 1edb78c

11 files changed

Lines changed: 111 additions & 56 deletions

File tree

compio-compat/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ impl<A: Adapter> RuntimeCompat<A> {
7171
Err(e) => panic!("failed to wait for driver: {e:?}"),
7272
}
7373

74-
if let Err(_e) = self.runtime.clear() {
75-
error!("failed to clear notifier: {_e:?}");
74+
if let Err(e) = self.runtime.clear() {
75+
error!("failed to clear notifier: {e:?}");
7676
}
7777

7878
self.runtime.poll_with(Some(Duration::ZERO));

compio-driver/src/sys/driver/fusion/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ impl Driver {
3535
Ok(driver) => Ok(Self {
3636
fuse: FuseDriver::IoUring(driver),
3737
}),
38-
// use _e here so that when `enable_log` is disabled, clippy won't complain
39-
Err(_e) if fallback => {
40-
warn!("Fail to create io-uring driver: {_e:?}, fallback to polling driver.");
38+
Err(e) if fallback => {
39+
warn!("Fail to create io-uring driver: {e:?}, fallback to polling driver.");
4140
Ok(Self {
4241
fuse: FuseDriver::Poll(poll::Driver::new(builder)?),
4342
})

compio-driver/src/sys/driver/iocp/cp/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn iocp_start() -> io::Result<()> {
5151
// Any thin pointer is OK because we don't use the type of opcode.
5252
let overlapped_ptr: *mut Overlapped = entry.lpOverlapped.cast();
5353
let overlapped = unsafe { &*overlapped_ptr };
54-
if let Err(_e) = syscall!(
54+
if let Err(e) = syscall!(
5555
BOOL,
5656
PostQueuedCompletionStatus(
5757
overlapped.driver as _,
@@ -66,7 +66,7 @@ fn iocp_start() -> io::Result<()> {
6666
entry.lpCompletionKey,
6767
entry.lpOverlapped,
6868
overlapped.driver,
69-
_e
69+
e
7070
);
7171
}
7272
}

compio-driver/src/sys/driver/iocp/cp/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl CompletionPort {
158158
&& overlapped.driver != current_driver
159159
{
160160
// Repost the entry to correct port.
161-
if let Err(_e) = syscall!(
161+
if let Err(e) = syscall!(
162162
BOOL,
163163
PostQueuedCompletionStatus(
164164
overlapped.driver as _,
@@ -173,7 +173,7 @@ impl CompletionPort {
173173
entry.lpCompletionKey,
174174
entry.lpOverlapped,
175175
overlapped.driver,
176-
_e
176+
e
177177
);
178178
}
179179
return None;

compio-driver/src/sys/driver/iour/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ impl Driver {
209209
if !more(flags) {
210210
self.need_push_notifier = true;
211211
}
212-
if let Err(_e) = self.notifier.clear() {
213-
error!("failed to clear notifier: {_e}");
212+
if let Err(e) = self.notifier.clear() {
213+
error!("failed to clear notifier: {e:?}");
214214
}
215215
}
216216
key => {

compio-log/src/dummy.rs

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,119 @@
11
#[macro_export]
2-
macro_rules! debug {
3-
($($args:tt)*) => {};
4-
}
5-
6-
#[macro_export]
7-
macro_rules! debug_span {
2+
macro_rules! event {
83
($($args:tt)*) => {
9-
$crate::Span::none()
4+
if false {
5+
$crate::__tracing::event!($($args)*);
6+
}
107
};
118
}
129

1310
#[macro_export]
1411
macro_rules! error {
15-
($($args:tt)*) => {};
12+
($($args:tt)*) => {
13+
if false {
14+
$crate::__tracing::error!($($args)*);
15+
}
16+
};
1617
}
1718

1819
#[macro_export]
19-
macro_rules! error_span {
20+
macro_rules! warn {
2021
($($args:tt)*) => {
21-
$crate::Span::none()
22+
if false {
23+
$crate::__tracing::warn!($($args)*);
24+
}
2225
};
2326
}
2427

2528
#[macro_export]
26-
macro_rules! event {
27-
($($args:tt)*) => {};
29+
macro_rules! info {
30+
($($args:tt)*) => {
31+
if false {
32+
$crate::__tracing::info!($($args)*);
33+
}
34+
};
2835
}
2936

3037
#[macro_export]
31-
macro_rules! info {
32-
($($args:tt)*) => {};
38+
macro_rules! debug {
39+
($($args:tt)*) => {
40+
if false {
41+
$crate::__tracing::debug!($($args)*);
42+
}
43+
};
3344
}
3445

3546
#[macro_export]
36-
macro_rules! info_span {
47+
macro_rules! trace {
3748
($($args:tt)*) => {
38-
$crate::Span::none()
49+
if false {
50+
$crate::__tracing::trace!($($args)*);
51+
}
3952
};
4053
}
4154

4255
#[macro_export]
4356
macro_rules! span {
57+
($($args:tt)*) => {{
58+
if false {
59+
$crate::__tracing::span!($($args)*)
60+
} else {
61+
$crate::Span::none()
62+
}
63+
}};
64+
}
65+
66+
#[macro_export]
67+
macro_rules! error_span {
4468
($($args:tt)*) => {
45-
$crate::Span::none()
69+
if false {
70+
$crate::__tracing::error_span!($($args)*)
71+
} else {
72+
$crate::Span::none()
73+
}
4674
};
4775
}
4876

4977
#[macro_export]
50-
macro_rules! trace {
51-
($($args:tt)*) => {};
78+
macro_rules! warn_span {
79+
($($args:tt)*) => {
80+
if false {
81+
$crate::__tracing::warn_span!($($args)*)
82+
} else {
83+
$crate::Span::none()
84+
}
85+
};
5286
}
5387

5488
#[macro_export]
55-
macro_rules! trace_span {
89+
macro_rules! info_span {
5690
($($args:tt)*) => {
57-
$crate::Span::none()
91+
if false {
92+
$crate::__tracing::info_span!($($args)*)
93+
} else {
94+
$crate::Span::none()
95+
}
5896
};
5997
}
6098

6199
#[macro_export]
62-
macro_rules! warn {
63-
($($args:tt)*) => {};
100+
macro_rules! debug_span {
101+
($($args:tt)*) => {
102+
if false {
103+
$crate::__tracing::debug_span!($($args)*)
104+
} else {
105+
$crate::Span::none()
106+
}
107+
};
64108
}
65109

66110
#[macro_export]
67-
macro_rules! warn_span {
111+
macro_rules! trace_span {
68112
($($args:tt)*) => {
69-
$crate::Span::none()
113+
if false {
114+
$crate::__tracing::trace_span!($($args)*)
115+
} else {
116+
$crate::Span::none()
117+
}
70118
};
71119
}

compio-log/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
html_favicon_url = "https://github.com/compio-rs/compio-logo/raw/refs/heads/master/generated/colored-bold.svg"
66
)]
77

8+
#[doc(hidden)]
9+
pub use tracing as __tracing;
810
#[cfg_attr(not(feature = "enable_log"), doc(hidden))]
911
pub use tracing::*;
1012

@@ -25,6 +27,14 @@ macro_rules! instrument {
2527
#[cfg(not(feature = "enable_log"))]
2628
#[macro_export]
2729
macro_rules! instrument {
28-
($lvl:expr, $name:expr, $($fields:tt)*) => {};
29-
($lvl:expr, $name:expr) => {};
30+
($lvl:expr, $name:expr, $($fields:tt)*) => {
31+
if false {
32+
let _guard = $crate::span!(target:module_path!(), $lvl, $name, $($fields)*).entered();
33+
}
34+
};
35+
($lvl:expr, $name:expr) => {
36+
if false {
37+
let _guard = $crate::span!(target:module_path!(), $lvl, $name).entered();
38+
}
39+
};
3040
}

compio-quic/src/endpoint.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,8 @@ impl Endpoint {
433433
let worker = compio_runtime::spawn({
434434
let inner = inner.clone();
435435
async move {
436-
#[allow(unused)]
437436
if let Err(e) = inner.run().await {
438-
error!("I/O error: {}", e);
437+
error!("I/O error: {:?}", e);
439438
}
440439
}
441440
.in_current_span()

compio-ws/examples/autobahn-client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ async fn main() {
6666
if let Err(e) = run_test(case).await {
6767
match e {
6868
Error::ConnectionClosed | Error::Protocol(_) | Error::Utf8(_) => (),
69-
_err => {
70-
error!("Testcase failed: {_err}");
69+
err => {
70+
error!("Testcase failed: {err}");
7171
}
7272
}
7373
}

compio-ws/examples/autobahn-server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ async fn accept_connection(peer: SocketAddr, stream: TcpStream) {
1111
if let Err(e) = handle_connection(peer, stream).await {
1212
match e {
1313
Error::ConnectionClosed | Error::Protocol(_) | Error::Utf8(_) => (),
14-
_err => {
15-
error!("Error processing connection: {_err}");
14+
err => {
15+
error!("Error processing connection: {err}");
1616
}
1717
}
1818
}
@@ -68,8 +68,8 @@ async fn main() {
6868
info!("Peer address: {addr}");
6969
compio_runtime::spawn(accept_connection(addr, stream)).detach();
7070
}
71-
Err(_e) => {
72-
error!("Error accepting connection: {_e}");
71+
Err(e) => {
72+
error!("Error accepting connection: {e}");
7373
}
7474
}
7575
}

0 commit comments

Comments
 (0)