tracing
tracing copied to clipboard
attributes: auto skip unused parameters
Motivation
The unused parameters always need to be skipped in most cases. However, keep writing
#[tracing::instrument(skip(_arg1, _arg2))]
is unnecessary and unconcise.
Rarely, someone would use underscore parameter as normal, but that should be ascribed to a code style issue.
fn foo(_arg: usize) {
println!("{}", _arg);
}
Solution
Support auto skips unused parameters for the tracing::instrument
attribute.
Raise a compile error if an unnecessary skipping found:
#[tracing::instrument(skip(_arg))]
fn foo(_arg: usize) {
}
error: unnecessary skipping: the unused parameter is auto skipped by default
|
2 | #[tracing::instrument(skip(_arg))]
| ^^^^
error: aborting due to previous error
error: using `clone` on type `metadata::Level` which implements the `Copy` trait
--> tracing-core/src/metadata.rs:835:47
|
835 | let actual: LevelFilter = level.clone().into();
| ^^^^^^^^^^^^^ help: try dereferencing it: `(*level)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
I guess this is an unrelated Clippy warning, which should be fixed in another PR.
error: using `clone` on type `metadata::Level` which implements the `Copy` trait --> tracing-core/src/metadata.rs:835:47 | 835 | let actual: LevelFilter = level.clone().into(); | ^^^^^^^^^^^^^ help: try dereferencing it: `(*level)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
I guess this is an unrelated Clippy warning, which should be fixed in another PR.
fixed this in #1444 :)
error: unnecessary skipping: the unused parameter is auto skipped by default
unused parameter
Maybe "parameter for which unused warning is silenced" or "underscored parameter" would be better?
Also maybe it should be a warning, not error?
AFAICT we could still merge this, after a rebase and review