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

use_debug lint should not trigger on debug!() log macro calls #2132

Open
hcpl opened this issue Oct 12, 2017 · 7 comments
Open

use_debug lint should not trigger on debug!() log macro calls #2132

hcpl opened this issue Oct 12, 2017 · 7 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types

Comments

@hcpl
Copy link

hcpl commented Oct 12, 2017

Example use-case:

#![cfg_attr(feature = "cargo-clippy", warn(use_debug))]

#[macro_use]
extern crate log;

pub fn euclid_steps(mut x: u64, mut y: u64) -> Vec<u64> {
    debug!("x = {}, y = {}", x, y);

    let mut steps = vec![];

    loop {
        let tmp = x % y;

        if tmp == 0 {
            debug!("Steps performed in Euclidean algorithm: {:?}", steps);
            return steps;
        }

        steps.push(tmp);
        x = y;
        y = tmp;
    }
}

Placing #![cfg_attr(feature = "cargo-clippy", allow(use_debug))] before each debug!() usage seems tedious to me when there are several dozens of them; and turning it off (even if locally) defeats the purpose of the lint.

@oli-obk oli-obk added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages T-middle Type: Probably requires verifiying types labels Oct 12, 2017
@sanmai-NL
Copy link
Contributor

There’s also trace! and various other logging crates. I propose that these macros themselves are patched to contain an expression-level allow on the format string.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 26, 2018

should be very easy with the new system. basically we only want this lint on explicit calls to print!, println!, write! and writeln!

Basically pass in the current macro name as an argument to https://github.com/rust-lang-nursery/rust-clippy/blob/master/clippy_lints/src/write.rs#L220 and then use that to lint conditionally in https://github.com/rust-lang-nursery/rust-clippy/blob/master/clippy_lints/src/write.rs#L247

@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy and removed E-medium Call for participation: Medium difficulty level problem and requires some initial experience. labels Jul 26, 2018
@sanmai-NL
Copy link
Contributor

What about format! and then reusing the resulting string in some inappropriate way, e.g. printing the string later on?

@oli-obk
Copy link
Contributor

oli-obk commented Jul 26, 2018

that, too :D good catch

@sanmai-NL
Copy link
Contributor

I’m trying to say, when the programmer uses format!, it’s unclear what happens with the output and also whether that’s inappropriate.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 26, 2018

oh... seems to me that this would be a case for "moderate sprinkling of allow"?

@sanmai-NL
Copy link
Contributor

So deny on format! by default? Seems fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

3 participants