Skip to content

feat: Stabilize build.warnings#16796

Open
epage wants to merge 1 commit intorust-lang:masterfrom
epage:warning
Open

feat: Stabilize build.warnings#16796
epage wants to merge 1 commit intorust-lang:masterfrom
epage:warning

Conversation

@epage
Copy link
Copy Markdown
Contributor

@epage epage commented Mar 26, 2026

What does this PR try to resolve?

This allows users to either

build.warnings is setup to mirror the behavior of RUSTFLAGS=-Dwarnings, including

  • only errors for lint warnings and not hard warnings
  • only errors for local warnings and not non-local warnings visible with --verbose --verbose
  • stop the build without --keep-going

These conditions were not originally met and also came as feedback from rust-lang/rust which has been dogfooding this since the merge of rust-lang/rust#148332.

Things are a bit different with RUSTFLAGS=-Awarnings:

  • Hard warnings are hidden for rustc but not cargo (rustc seems in the wrong imo)
    • In particular, we shouldn't mask the edition warning for Cargo Script
  • both hide the warning summary line (number of warnings per crate)
  • both hide non-local warnings for --verbose --verbose

One design constraint we are operating on with this is that changing build.warnings should not cause a rebuild, unlike a RUSTFLAGS solution.

Closes #14802

How to test and review this PR?

My main concern over this was how the naming scheme would extend to rust-lang/rfcs#3730 but that RFC has not gained much interest

build seems as good of a home as any.

This allows users to either
- hide warnings (rust-lang#14258)
- error on warnings (rust-lang#8424)

`build.warnings` is setup to mirror the behavior of `RUSTFLAGS=-Dwarnings`,
including
- only errors for lint warnings and not hard warnings
- only errors for local warnings and not non-local warnings visible with
  `--verbose --verbose`
- stop the build without `--keep-going`

These conditions were not originally met and also came as feedback from
rust-lang/rust which has been dogfooding this since the merge of rust-lang/rust#148332.

Things are a bit different with `RUSTFLAGS=-Awarnings`:
- Hard warnings are hidden for rustc but not cargo (rustc seems in the
  wrong imo)
  - In particular, we shouldn't mask the edition warning for Cargo
    Script
- both hide the warning summary line (number of warnings per crate)
- both hide non-local warnings for `--verbose --verbose`

One design constraint we are operating on with this is that changing
`build.warnings` should not cause a rebuild, unlike a `RUSTFLAGS`
solution.

Closes rust-lang#14802
@epage epage added the T-cargo Team: Cargo label Mar 26, 2026
@rustbot rustbot added A-configuration Area: cargo config files and env vars A-documenting-cargo-itself Area: Cargo's documentation labels Mar 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, weihanglo

@rustbot rustbot added A-unstable Area: nightly unstable support S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 26, 2026
@epage
Copy link
Copy Markdown
Contributor Author

epage commented Mar 26, 2026

@rfcbot fcp merge cargo

@rust-rfcbot
Copy link
Copy Markdown
Collaborator

rust-rfcbot commented Mar 26, 2026

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Mar 26, 2026
@epage
Copy link
Copy Markdown
Contributor Author

epage commented Mar 26, 2026

Right now, we exactly mirror RUSTFLAGS=[AD]warnings behavior.

My one concern is with build.warnings = "allow" with hard warnings.

  • Right now, rustc warnings are hidden and cargo warnings are shown. We likely want these to be consistent
  • We shouldn't be hiding the Cargo Script warning
  • Hard warnings should be rare
  • deny ignores hard warnings

From this, I would lean towards making allow show hard warnings always.

Copy link
Copy Markdown
Contributor

@arlosi arlosi left a comment

Choose a reason for hiding this comment

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

I agree with stabilizing the existing behavior, but I think we need to be clear about exactly what this option impacts.

"Hard warnings" don't seem to be defined as term in our documentation.

View changes since this review

Comment on lines +472 to +473
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`.
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.

* 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.

* `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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-configuration Area: cargo config files and env vars A-documenting-cargo-itself Area: Cargo's documentation A-unstable Area: nightly unstable support disposition-merge FCP with intent to merge proposed-final-comment-period An FCP proposal has started, but not yet signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue for warnings (config build.warnings)

5 participants