-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add --deny-warnings
functionality for all commands.
#8424
Comments
Commenting to support this feature request. The project I work on has [target.'cfg(all())']
rustflags = ["-D", "warnings"] This works great for CI, where it prevents us from merging code that has warnings. However, it is painful for local development. I frequently add a few lines, run Adding a |
You can already do this in your CI. It's just about setting your ENV variable Cargo will fetch the ENV variables and pass them to This would be an example using actions-rs on: [push]
name: CI
jobs:
build_and_test:
name: Rust project
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --all-features If you want to treat warnings as errors, or do any fancy stuff, check the docs about lint levels for I think this issue can be closed considering that |
That does not work for projects that need
As an example, It is possible deny warnings only in CI by including a |
I understand your point. With multiple crates things get out of control for maintenance. We're working on an RFC that might make this easier to manage. See: rust-lang/rust-clippy#6625 Although the --deny-warnings would require a bit of design since it can have some edge cases IMO. |
Another reason why |
And yet another reason why Hmm. Now that I write that, I realise that promoting warnings to build-failing errors actually is not a cosmetic thing and, perhaps, it actually should force a full recompile, following the same arguments behind |
For the |
Is there anything new regarding this issue? I want to run cargo check with deny warnings as a precommit hook but the only way is to set RUSTFLAGS which causes a recompile of the crate and all the dependencies. |
If its not in this issue, likely not. The closest related work is #12115 which removes some reliance on RUSTFLAGS for dealing with warnings but not in this case.
The hard thing here is that technically your dependencies are reporting warnings and deny-warnings could affect them, so we'd need to recompile to verify that. However, with caplints, most warnings from dependencies are dropped and with our caching of warnings between runs, rebuilds aren't needed. The challenge with RUSTFLAGS is that its opaque to us (and should remain so) and that it applies to all packages when you only care about workspace members. #8716 at least partially improves the RUSTFLAGS situation because we would generate separate files for each RUSTFLAGS, rather than overwriting, so a full rebuild would happen once and then we'd rebuild on top of that. |
I don't think using RUSTFLAGS here is the correct solution, clippy has the option to control the lints directly using |
This PR fixes existing clippy warnings and adds `-Dwarnings` to the clippy invocations of the justfile. I used the CLI args rather than RUSTFLAGS as there can be some issues with overriding other rustflags used. See rust-lang/cargo#8424 for more context re: rustflags issues
Been thinking about this more in the context of "how do we rely on RUSTFLAGS less?" In a case like this, a What if we added a flag |
That would be really useful for some of my use cases so I can just focus on looking at critical errors when I need to. |
Would be great to have an interface like clippy's for |
@djc could you clarify what you mean For Also it sounds like you are wanting the denying of warnings to be the default for your project and users have to allow them. Is that correct? Is there a reason you want that rather than warn by default and have CI turn those warnings into errors? |
Taken from rust-lang/cargo#8424 (comment). Otherwise CI would not highlight the issue.
Taken from rust-lang/cargo#8424 (comment). Otherwise CI would not highlight the issue.
I talked briefly with @ehuss about this to get some more input on the idea. This is a summary of that specific conversation and doesn't represent the team as a whole. The main points of interest
The first is just a process question. For the second, my hope is that we can generally move to lints being configured on a project basis. We have I do think there is still a hole though for "warnings I want to know about but not block CI". An example is if you don't want to block on deprecations when upgrading. I've started https://internals.rust-lang.org/t/forbid-deny-warn-allow-and-notice/19986/20 to discuss these kinds of cases. There is also experimentation but people can use We'd like want input from clippy and others to see if there are cases we are missing. With that said, one way to delay having to make a decision on any of this is by only starting this as a config setting |
Based on the PR, a question would be what non-rustc warnings should be in-scope
|
Taken from rust-lang/cargo#8424 (comment). Otherwise CI would not highlight the issue.
It would be great if |
To add to the above, turns out |
Taken from rust-lang/cargo#8424 (comment). Otherwise CI would not highlight the issue.
I have a build script that prints "cargo::warning=Missing ENV variable that is important for release". This i fine during development but I want it to be a compile error in CI. Is that possible? Does Cargo have a flag to stop on warnings? |
That's a bit hacky, but you could probably check the environment for a |
Nice workaround! |
Tracking issue: #14802 |
Describe the problem you are trying to solve
I often automate
cargo
and I typically want any automation to halt whencargo
emits warnings. AFAICT the only way to do this is to try to parse the output for the way warnings are typically produced.(Related issue: there are two categories of warnings which is confusing and needs clarification, which I filed as #8423 .)
Describe the solution you'd like
Add a commandline flag called
--deny-warnings
and if set, if a warning is encountered, this ensures the process will exit with a non-zero status and that no "non-dry-run" operations proceed. For example, withcargo publish --deny-warnings
any of the early local packaging-style lint warnings will causecargo publish
to avoid making any requests tocrates.io.
Notes
I'm not sure about the option name
--deny-warnings
which I took from the#![deny(warnings)]
rust compilation attribute, but I can't think of anything clearer and concise.--treat-warnings-like-errors
,--exit-with-error-when-encountering-warnings
,--don't-just-warn-me-stop-me!
, and--please-save-me-from-myself
all are too cumbersome.Related Tickets
This is related to #3591 because in some way these are opposites (disabling warnings versus escalating them to errors). There might be some common CLI magic that addresses both issues and is clear enough to users.
Even if they use separate cli and/or config specification, if both implemented, they might lead to nonsensical / confusing combinations which a good UX would complain-and-exit about, for example:
cargo do-stuff --hide-warnings --deny-warnings
or something similar should probably say "I can't tell what you meant to do."The text was updated successfully, but these errors were encountered: