Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@ unstable_cli_options!(
target_applies_to_host: bool = ("Enable the `target-applies-to-host` key in the .cargo/config.toml file"),
trim_paths: bool = ("Enable the `trim-paths` option in profiles"),
unstable_options: bool = ("Allow the usage of unstable options"),
warnings: bool = ("Allow use of the build.warnings config key"),
);

const STABILIZED_COMPILE_PROGRESS: &str = "The progress bar is now always \
Expand Down Expand Up @@ -1001,6 +1000,8 @@ const STABILIZED_BUILD_DIR: &str = "build.build-dir is now always enabled.";

const STABILIZED_CONFIG_INCLUDE: &str = "The `include` config key is now always available";

const STABILIZED_WARNINGS: &str = "The `build.warnings` config key is now always available";

fn deserialize_comma_separated_list<'de, D>(
deserializer: D,
) -> Result<Option<Vec<String>>, D::Error>
Expand Down Expand Up @@ -1389,6 +1390,7 @@ impl CliUnstable {
"package-workspace" => stabilized_warn(k, "1.89", STABILIZED_PACKAGE_WORKSPACE),
"build-dir" => stabilized_warn(k, "1.91", STABILIZED_BUILD_DIR),
"config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE),
"warnings" => stabilized_warn(k, "1.96", STABILIZED_WARNINGS),

// Unstable features
// Sorted alphabetically:
Expand Down Expand Up @@ -1456,7 +1458,6 @@ impl CliUnstable {
"target-applies-to-host" => self.target_applies_to_host = parse_empty(k, v)?,
"panic-immediate-abort" => self.panic_immediate_abort = parse_empty(k, v)?,
"unstable-options" => self.unstable_options = parse_empty(k, v)?,
"warnings" => self.warnings = parse_empty(k, v)?,
_ => bail!(
"\
unknown `-Z` flag specified: {k}\n\n\
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2114,11 +2114,7 @@ impl GlobalContext {

/// Get the global [`WarningHandling`] configuration.
pub fn warning_handling(&self) -> CargoResult<WarningHandling> {
if self.unstable_flags.warnings {
Ok(self.build_config()?.warnings.unwrap_or_default())
} else {
Ok(WarningHandling::default())
}
Ok(self.build_config()?.warnings.unwrap_or_default())
}

pub fn ws_roots(&self) -> MutexGuard<'_, HashMap<PathBuf, WorkspaceRootConfig>> {
Expand Down
15 changes: 15 additions & 0 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ recursive_example = "rr --example recursions"
space_example = ["run", "--release", "--", "\"command list\""]

[build]
warnings = "warn" # adjust the effective lint level for warnings
jobs = 1 # number of parallel jobs, defaults to # of CPUs
rustc = "rustc" # the rust compiler tool
rustc-wrapper = "…" # run this wrapper instead of `rustc`
Expand Down Expand Up @@ -457,6 +458,20 @@ recursive_example = "rr --example recursions"

The `[build]` table controls build-time operations and compiler settings.

### `build.warnings`
* Type: string
* Default: `warn`
* Environment: `CARGO_BUILD_WARNINGS`

Adjust the effective lint level for warnings.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section seems confusing between the terms lint and warning.

The following sounds like all warnings have a lint level that we're adjusting.

Adjust the effective lint level for warnings.

This sounds like all lints can have an adjustable lint level that we're changing here.

warn: continue to emit the lints as warnings (default).

This is now emitting errors for warnings not lints.

deny: emit an error for a crate that has warnings

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is tricky to talk about this precisely enough while not adding so many qualifiers that it makes it hard to follow. My intent with the last paragraph ("Only warnings") was to clarify this.

Allowed values are:
* `warn`: continue to emit the lints as warnings (default).
* `allow`: hide the lints.
* `deny`: emit an error for a crate that has warnings. Use `--keep-going` to see see the warnings for all crates.

Only warnings within the user's control to resolve or adjust the level of are affected,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be more precise about what "user's control to resolve" means?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I was seeking to clarify by providing examples.

e.g. leaving as-is non-lint warnings or warnings from dependencies visible through `--verbose --verbose`.
Comment on lines +472 to +473
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Only warnings within the user's control to resolve or adjust the level of are affected,
e.g. leaving as-is non-lint warnings or warnings from dependencies visible through `--verbose --verbose`.
Only warnings within the user's control to resolve or adjust the level of are affected.
Non-lint warnings or warnings from dependencies visible through `--verbose --verbose` are not affected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going for this to be descriptive, rather than prescriptive, and felt listing the cases as examples would help set that tone.


#### `build.jobs`
* Type: integer or string
* Default: number of logical CPUs
Expand Down
27 changes: 4 additions & 23 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ Each new feature described below should explain how to use it.
* [script](#script) --- Enable support for single-file `.rs` packages.
* [lockfile-path](#lockfile-path) --- Allows to specify a path to lockfile other than the default path `<workspace_root>/Cargo.lock`.
* [native-completions](#native-completions) --- Move cargo shell completions to native completions.
* [warnings](#warnings) --- controls warning behavior; options for allowing or denying warnings.
* [Package message format](#package-message-format) --- Message format for `cargo package`.
* [`fix-edition`](#fix-edition) --- A permanently unstable edition migration helper.
* [Plumbing subcommands](https://github.com/crate-ci/cargo-plumbing) --- Low, level commands that act as APIs for Cargo, like `cargo metadata`
Expand Down Expand Up @@ -1839,28 +1838,6 @@ When in doubt, you can discuss this in [#14520](https://github.com/rust-lang/car
- powershell:
Add `CARGO_COMPLETE=powershell cargo +nightly | Invoke-Expression` to `$PROFILE`.

## warnings

* Original Issue: [#8424](https://github.com/rust-lang/cargo/issues/8424)
* Tracking Issue: [#14802](https://github.com/rust-lang/cargo/issues/14802)

The `-Z warnings` feature enables the `build.warnings` configuration option to control how
Cargo handles warnings. If the `-Z warnings` unstable flag is not enabled, then
the `build.warnings` config will be ignored.

This setting currently only applies to rustc warnings. It may apply to additional warnings (such as Cargo lints or Cargo warnings)
in the future.

### `build.warnings`
* Type: string
* Default: `warn`
* Environment: `CARGO_BUILD_WARNINGS`

Controls how Cargo handles warnings. Allowed values are:
* `warn`: warnings are emitted as warnings (default).
* `allow`: warnings are hidden.
* `deny`: if warnings are emitted, an error will be raised at the end of the current crate and the process. Use `--keep-going` to see all warnings.

## feature unification

* RFC: [#3692](https://github.com/rust-lang/rfcs/blob/master/text/3692-feature-unification.md)
Expand Down Expand Up @@ -2348,3 +2325,7 @@ See the [`include` config documentation](config.md#include) for more.
## pubtime

The `pubtime` index field has been stabilized in Rust 1.94.0.

## warnings

The `build.warnings` config field has been stabilized in Rust 1.96.
14 changes: 6 additions & 8 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 0 additions & 46 deletions tests/testsuite/warning_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ fn make_project_with_rustc_warning() -> Project {
.build()
}

#[cargo_test]
fn requires_nightly() {
// build.warnings has no effect without -Zwarnings.
let p = make_project_with_rustc_warning();
p.cargo("check")
.arg("--config")
.arg("build.warnings='deny'")
.with_stderr_data(str![[r#"
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[WARNING] unused variable: `x`
...
[WARNING] `foo` (bin "foo") generated 1 warning[..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}

#[cargo_test]
fn clippy() {
let p = project()
Expand All @@ -56,8 +38,6 @@ fn clippy() {
.build();

p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.env("RUSTC_WORKSPACE_WRAPPER", tools::wrapped_clippy_driver())
Expand All @@ -77,8 +57,6 @@ fn clippy() {
fn config() {
let p = make_project_with_rustc_warning();
p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.env("CARGO_BUILD_WARNINGS", "deny")
.with_stderr_data(str![[r#"
[CHECKING] foo v0.0.1 ([ROOT]/foo)
Expand All @@ -93,8 +71,6 @@ fn config() {

// CLI has precedence over env
p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='warn'")
.env("CARGO_BUILD_WARNINGS", "deny")
Expand All @@ -112,8 +88,6 @@ fn config() {
fn unknown_value() {
let p = make_project_with_rustc_warning();
p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='forbid'")
.with_stderr_data(str![[r#"
Expand Down Expand Up @@ -146,8 +120,6 @@ fn keep_going() {
.build();

p.cargo("build")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.with_stderr_data(str![[r#"
Expand All @@ -164,8 +136,6 @@ fn keep_going() {
assert!(!p.bin("foo").is_file());

p.cargo("build --keep-going")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.with_stderr_data(str![[r#"
Expand All @@ -189,8 +159,6 @@ fn keep_going() {
fn rustc_caching_allow_first() {
let p = make_project_with_rustc_warning();
p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='allow'")
.with_stderr_data(str![[r#"
Expand All @@ -201,8 +169,6 @@ fn rustc_caching_allow_first() {
.run();

p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.with_stderr_data(str![[r#"
Expand All @@ -220,8 +186,6 @@ fn rustc_caching_allow_first() {
fn rustc_caching_deny_first() {
let p = make_project_with_rustc_warning();
p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.with_stderr_data(str![[r#"
Expand All @@ -236,8 +200,6 @@ fn rustc_caching_deny_first() {
.run();

p.cargo("check")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='allow'")
.with_stderr_data(str![[r#"
Expand Down Expand Up @@ -300,8 +262,6 @@ fn hard_warning_deny() {

// Behavior under test
p.cargo("rustc")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.arg("--")
Expand Down Expand Up @@ -370,8 +330,6 @@ fn hard_warning_allow() {

// Behavior under test
p.cargo("rustc")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='allow'")
.arg("--")
Expand Down Expand Up @@ -446,8 +404,6 @@ fn cap_lints_deny() {

// Behavior under test
p.cargo("check -vv")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='deny'")
.with_stderr_data(str![[r#"
Expand Down Expand Up @@ -520,8 +476,6 @@ fn cap_lints_allow() {

// Behavior under test
p.cargo("check -vv")
.masquerade_as_nightly_cargo(&["warnings"])
.arg("-Zwarnings")
.arg("--config")
.arg("build.warnings='allow'")
.with_stderr_data(str![[r#"
Expand Down