tracing icon indicating copy to clipboard operation
tracing copied to clipboard

attributes: auto skip unused parameters

Open Folyd opened this issue 3 years ago • 4 comments

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

Folyd avatar Jun 23 '21 10:06 Folyd

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.

Folyd avatar Jun 23 '21 10:06 Folyd

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 :)

hawkw avatar Jun 23 '21 17:06 hawkw

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?

vi avatar Jun 24 '21 08:06 vi

AFAICT we could still merge this, after a rebase and review

bryangarza avatar May 06 '22 00:05 bryangarza