-
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
Cargo check should allow disabling warnings #3591
Comments
cc @nrc @jonathandturner, opinions on this? |
I would not object to having this. Its not something that I've noticed being super-painful though. |
Ditto. WFM |
I'll give an example of where I'd find it useful: I'm building up a library and I have a bunch of code I know I'll be using, because I've written them to use elsewhere in the library. But I get dead-code warnings constantly because I haven't written those implementations yet, and it's just noise while I'm working on fixing a broken test, or on seeing actual build errors elsewhere in the library, etc. |
On the other side of things, I leave warnings as warnings when working on a crate, but then want to turn them into errors on CI. |
I strongly want this too. I came to the repo looking to file an issue requesting |
If we do anything, we should do it for both |
That would be awesome for |
Where I find it annoying is when the output is not colored (ie. IDE terminal doesn't support it) and I just want to check and fix errors quickly when making incremental changes to code or when I'm just testing or playing around, like in a "test-some-posibility" branch. It's a bit harder on my eyes to stop at the first error when warnings are printed first. I have to traverse all the warnings first. |
How about just putting this in your crate during development: #![ allow( dead_code, unused_imports ) ] |
I also saw this: Source: https://users.rust-lang.org/t/suppress-warnings-from-the-cargo-command/10536/6 |
Note that we have RFC 2383 which proposed a way to "expect" a lint that is actually what I really want during development (a way to say "I know this code is dead, I expect that, and warn me if it becomes not dead so I can remove the annotation"). |
This is what I have been doing recently - this will catch compile errors with enough info to fix them and it silences warnings but still says how many warnings there are. cargo check 2>&1 | rg -i --multiline "(^error.*\n.*)|(aborting)|(warnings)"
|
followup of !431 [1] deny(warnings) is an anti-pattern as a newer release of the compiler can cause working/released builds to stop compilling for downstreams. Having to export a RUST_FLAG is not the prettiest, but its the best we got atm [2] [1] https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/431 [2] rust-lang/cargo#3591
Thought I'd add my solution. I use this
|
This comment has been minimized.
This comment has been minimized.
Cargo command-line disabling of warnings would provide better ergonomics for many workflows. Windows console scrolls very slowly, and my IDE already displays warnings in-line, cargo check/test have no need to display them. My workflow is to have cargo watch -x test running in one terminal, and rust-analyzer in the IDE. The redundancy and lag are not desirable here. |
Maybe using In this case it could be [tool.rustc]
allow_warnings = "dead_code" Edit: or add the configuration option to .cargo/config.toml. At the moment it can be indirectly configured with [target.'cfg(target_family = "unix")']
rustflags = [
"-Adead_code"
] |
My proposal would be to add options like clippy has for build-like commands (check, build, etc):
(Then we could also have these directly in I'd be willing to implement this if a Cargo team member approves of the plan. |
I would love to see this feature added. I'd also like to point out that using A potential solution to improve the UX is to suppress and/or level-set the messages on |
I would expect cargo's Edit for clarity due to downvotes: I often need to check the commandline output of my programs and the clutter from warnings distracts from that. |
While it would be great to have an option to remove the visual clutter that happens when you have both compile errors and warnings, where you try to scan the errors out of the bunch, I think it would be nice to not completely remove the information that you have warnings, because those warnings should not be overlooked. For example, we could see a summary on the last tine with a count of the number of warnings, even if those warnings are not displayed. |
#12115 adds a new |
I'm here cause I was wanting a similar thing... I wish there was a way to run something like The main reason is that I work on some massive code bases and there's dead code and unused imports, etc everywhere on the dev branches and when I need to only focus on either actual fatal Errors. Sometimes there's so many warnings that it exceeds my terminal's max history and I can't even read the actual Errors that are thrown that my terminal that are preventing my code from compiling or running. Having to go around and put #![allow(foo_bar)] everywhere and then remove it would just take too much time.But that's currently one of my only options. Please, please, please do something about this. Not having this feature is one of the current banes of my existence :D |
@noraa-july-stoke for me, that sounds slightly different than the request in this issue. I'd recommend creating a dedicated issue for it (or highjacking #8424 as I could see us having a Since #12115 is merged, I'm closing this as resolved. |
@epage Is the I tried I'm asking, since this issue specifically asks for flags, so I was hoping #12115 would resolve that with |
@JeanMertz There is a proposal of a new flag to control warnings: #12875 |
Thank you for that insight @weihanglo. I wasn't aware The
It doesn't look like #12875 would solve this particular issue, though, as it proposes a blanket disable/enable feature, instead of fine-grained control over which specific lint is set to which level. I'll use |
Terminology is hard.
Does |
To add, we have
If a new issue is created, I would recommend focusing on the use case for why cargo needs to expose the flags more directly to the user. If there is discussion on the solution, a comparison with the above would be beneficial to help highlight the unique need here. Keep in mind that if a flag is added, a full recompilation will be needed so rustc can respond to the different diagnostic flag. The most we can benefit from this is that adding the flag won't flush caches of previously builds like |
Thank you for the input @epage.
This is precisely what I'm looking for. A way to conveniently configure specific lints in specific situations (local dev, pre-commit, CI, etc.), and the behavior you describe (no cache flushing, limited to my personal crate or workspace). None of the proposals you listed above would tackle that, but this issue seems to specifically request exactly that (e.g. have a way for I'll see if I can find some time over the weekend to file a new issue for this 👍. |
There are a lot of compiler warnings that are noisy and useless during development, such as dead_code. Unfortunately, cargo check does not have any way of disabling these warnings. There needs to be a way to disable specific warnigns when running cargo check.
So far, the only workaround I've found is
export RUSTFLAGS='-A dead_code'
, which is ugly and undiscoverable, and you have to remember to undo it when you are ready for release.The text was updated successfully, but these errors were encountered: