Why does setting `RUSTFLAGS` to `-D warnings` cause errors for `cargo check|clippy` but not for `cargo doc`?

I don't want to add #![deny(warnings)] because I don't want a few warning-turned-errors prevent me from testing my code. I also want rust-analyzer to show cargo doc warnings in my editor.

I’m not familiar enough with command-line-option+environment configuration of rustc-tooling (and their design princples) to answer the question of “why”, but I tried out a few things, and apparently RUSTDOCFLAGS="-D warnings" does work, so maybe that’s sufficient for your use-case?

1 Like

It does solve the CI problem. But it's not nearly as sufficient. I still need rust-analyzer to show the warnings for me.

I think you could set rust-analyzer.checkOnSave.command to doc. That will only run cargo doc though and thus suppress for example type errors and some name resolution errors. It would also be slower as it will now build the documentation every time you save.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.