-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add option to error when warnings are emitted, or ignore warnings #12875
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
Conversation
|
r? @epage (rustbot has picked a reviewer for you, use r? to override) |
| .global(true), | ||
| ) | ||
| .arg( | ||
| opt("warnings", "Warning behavior") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be unstable initially via -Zunstable-options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We likely should if we move forward with this.
| pub fn warn<T: fmt::Display>(&mut self, message: T) -> CargoResult<()> { | ||
| match self.verbosity { | ||
| Verbosity::Quiet => Ok(()), | ||
| _ => self.print(&"warning", Some(&message), &WARN, false), | ||
| self.warning_count += 1; | ||
| if matches!(self.verbosity, Verbosity::Quiet) | ||
| || matches!(self.warnings, WarningHandling::Ignore) | ||
| { | ||
| return Ok(()); | ||
| } | ||
| self.print(&"warning", Some(&message), &WARN, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it only apply to rustc warnings (not Cargo warnings) until cargo has better control over diagnostics system (#12235)?
| Specifying the `--quiet` flag will override and disable verbose output. | ||
| Specifying the `--verbose` flag will override and force verbose output. | ||
|
|
||
| #### `term.warnings` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should the config option go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
term feels wrong.
We have build but this will control other circumstances (maybe even cargo metadata!). However, build might be the first place people look.
Maybe we should have some kind of general category?
| .global(true), | ||
| ) | ||
| .arg( | ||
| opt("warnings", "Warning behavior") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have --config "term.warnings='error'" do we need the --warnings CLI option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean towards
- Stabilize the config and add the flag later (take the incremental approach).
- That also means that we'll mostly have early adopters at first which will reduce the amount annoyance if we say skip cargo warnings and add them later
- This will help us vet how much the flag is needed compared to the config
- When we add the flag, maybe only put it on warning-heavy commands (
cargo check,cargo build) to help people discover it without flooding every command with it (cargo version --warnings error?)
| let result = exec.exec(config, subcommand_args); | ||
| config.shell().error_for_warnings()?; | ||
| result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every command comes back to this, like cargo run does an exec_replace
| ) | ||
| .arg( | ||
| opt("warnings", "Warning behavior") | ||
| .value_parser(["error", "warn", "ignore"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use PossibleValuesParser with TypedValueParser::map to make this work with the native type, rather than returning a string, centralizing the processing
| let mut shell = self.config.shell(); | ||
| shell.print_ansi_stderr(diag.as_bytes())?; | ||
| shell.err().write_all(b"\n")?; | ||
| if shell.warnings() != WarningHandling::Ignore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels weird that shell knows of this, seems more like a config thing
| if shell.warnings() != WarningHandling::Ignore { | ||
| shell.print_ansi_stderr(diag.as_bytes())?; | ||
| shell.err().write_all(b"\n")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed it but how are we turning compiler warnings into errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not turning the warnings into errors. They're still printed as warnings.
After all the warnings are emitted, a single error is emitted if any warnings were present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put another way, how are we tracking compiler warnings to fail the process.
| * `warn` (default): warnings are displayed and do not fail the operation. | ||
| * `error`: if any warnings are encountered an error will be emitted at the of the operation. | ||
| * `ignore`: warnings will be silently ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you did error and ignore rather than deny/forbid and allow?
On one hand, the semantics are slightly different than the levels but on the other hand, they are familiar, predictable terms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed clearer what the behavior would be. If we do deny for "emit an error" and allow for "ignore warnings" what do we call the default "warn" option?
Maybe deny/warn/allow ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forbid might better fit our semantics, but either way that was what I had originally assumed.
|
☔ The latest upstream changes (presumably #12889) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Is there any way to help make progress on this? We've been working around the lack of this by programmatically mutating We can't use |
|
@arlosi Hi, do you have time or interest to continue working on this? If not, I'd like to push forward based on your work. |
|
@xxchan Thanks for your interest here! Last time we discussed this was when Cargo's Linting system was in development and we wanted to see how that would interact here. I'll bring this up at next week's team meeting to discuss how to move forward. |
|
There is also higher level discussions that need to happen on the Issue |
|
Implementation has moved to #14388 |
What does this PR try to resolve?
Users want a way to deny all warnings, particularly in CI.
--warnings error|warn|ignoreCLI flagterm.warningsconfig option.The options mean:
erroremits an error if any warnings were emitted during the Cargo operationwarnis the existing behaviorignorehides the warningsOpen Questions:
-Zunstable-options?rustcwarnings (not Cargo warnings) until cargo has better control over diagnostics system (User control over cargo warnings #12235)?term.warnings, since that also whereverboseandquietlive. However, it's not really a terminal setting.[build]is another option, but this applies to all warnings, not just build warnings.--config "term.warnings='error'"do we need the--warningsCLI option?--configbut adds 1 more option to every command's help.Fixes #8424
How should we test and review this PR?
Tests are included in the PR. Resolving the open questions is the majority of the review work.