Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[tracing::instrument] swallows lints such as dead_code #1366

Open
andrewhickman opened this issue Apr 21, 2021 · 1 comment
Open

#[tracing::instrument] swallows lints such as dead_code #1366

andrewhickman opened this issue Apr 21, 2021 · 1 comment

Comments

@andrewhickman
Copy link

Bug Report

Version

0.1.25

Platform

Windows 10 64-bit

Crates

  • tracing

Description

Functions wrapped in #[tracing::instrument] will not trigger lints such as dead_code. See andrewhickman/fn-error-context#3 for a very similar issue (in a much simpler macro) which was caused by dropping some spans on the macro tokens.

Minimal example to reproduce:

#[tracing::instrument]
fn never_used() {}

fn main() {}

Without the instrument attribute, we get a dead_code lint warning, but with it applied the warning is suppressed.

@andrewhickman andrewhickman changed the title #[tracing::instrument] swallows lints such as dead_code #[tracing::instrument] swallows lints such as dead_code Apr 21, 2021
@dvdsk
Copy link

dvdsk commented Jan 4, 2022

This is particularly confusing if combined with a dead code warning inside the function.

This only seems to happens if the traced function is inside a implementation block.
Like this (playground):

struct Test;
impl Test {
    #[tracing::instrument]
    fn never_used(var: i32) {
        const IS_USED: &str = "I get a dead code warning";

        if IS_USED == "" {
            println!("");
        }
    }
}

fn main() {
    let _test = Test;
}

If one comments out the constant IS_USED you get a undefined variable warning. Given there is no dead_code warning this gets really confusing.

I brought this specific case up with the compiler to see if there is anything they can do about this especially confusing case.

9999years added a commit to 9999years/tracing that referenced this issue Oct 17, 2024
9999years added a commit to 9999years/tracing that referenced this issue Oct 17, 2024
9999years added a commit to 9999years/tracing that referenced this issue Oct 17, 2024
9999years added a commit to 9999years/tracing that referenced this issue Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants