Treat warnings as errors for workspace?

Is there any way to add something to a workspace to get it to treat warnings as errors, and/or provide clippy directives?

If not, is there a good argument for keeping it out of the workspace?

The main reason I’m looking to put it in the workspace first is that people can still use standard build tools / commands and they’ll just do the right thing, as opposed to having to use a Makefile or something.

You make warnings into errors with #![deny(name of the warning)] directives in the source code (Rust controls warnings from the source code, not from the compiler flags*).

They're per crate, rather than per workspace. Workspace-wide attributes are an unsolved problem.

*) except --cap-lints which disables warnings-as-errors for dependencies, because otherwise addition of new warnings to the compiler would be a breaking change.

I find that warnings as errors immediately is the wrong approach. This prevents staged warnings (where a warning is emitted later in the compilation pipeline) from emitting them all, and temporary warnings (such as unreachable code) become unnecessary blockers.

Rather, your PR review process should include cargo clippy -- -D warnings (on CI, ideally) if you want to enforce no warnings.

4 Likes