Clippy option to suppress "unused" errors

Is there some Clippy command line option to suppress "field is never read", "unused variable", and "function is never used"? That would be useful when the program isn't finished yet.

I was hoping that "todo!()" would tell Clippy that something isn't finished yet and related unused" messages should be suppressed, But it doesn't do that.

1 Like

Those are built-in lints (and maybe some Clippy ones too), and you can use something like

RUSTFLAGS="-A unused" cargo check

(Or something finer grained.)

This may only be a partial answer; perhaps someone else can fill in some Clippy-specific advice.

To suppress a clippy lint, use #[allow(clippy::name_of_offending_lint)].

One thing I often do is put

#![cfg(test, allow(dead_code))]

at the top of the library.

I find that handy for avoiding some of the "yeah, I know" when I'm just in a cargo test iteration loop.

(It does require remembering to do a non-test build at some point before saying you're done, though.)

RUSTFLAGS="-A unused" cargo clippy

turned out to do exactly what I wanted. All Clippy errors appear, while several types of "unused" warnings are suppressed. That needs to be documented better, since it's a very useful check for an in-progress project. You may want to check in code that's not called yet, but not check in code with other warnings.