Skip to content

rust: take lints from cargo unit graph#239

Merged
Andrew Gazelka (andrewgazelka) merged 1 commit into
mainfrom
codex/cargo-unit-manifest-lints
May 28, 2026
Merged

rust: take lints from cargo unit graph#239
Andrew Gazelka (andrewgazelka) merged 1 commit into
mainfrom
codex/cargo-unit-manifest-lints

Conversation

@andrewgazelka
Copy link
Copy Markdown
Member

@andrewgazelka Andrew Gazelka (andrewgazelka) commented May 28, 2026

Summary

  • move the repo Rust lint policy into [workspace.lints] and opt every workspace crate into inherited lints
  • stop the Nix Clippy policy from injecting default -D and -A flags
  • teach nix-cargo-unit to consume lint_rustflags and check_cfg_args from Cargo's unit graph instead of parsing manifest lint tables locally
  • opened the matching long-term Cargo change as Expose resolved lint flags in unit graph rust-lang/cargo#17040

Validation

  • nix run .#lint

Comment thread packages/nix-cargo-unit/src/render.rs Outdated
@github-actions
Copy link
Copy Markdown
Contributor

AI review found issues in this pull request.

Verdict: patch is incorrect
Confidence: 0.91

The patch breaks existing eval assertions around the shared Rust lint policy and adds an incomplete manifest lint renderer for unexpected_cfgs that can reject valid Cargo builds.

  • P1 lib/rust.nix:36 Default clippy policy no longer matches existing checks
  • P2 packages/nix-cargo-unit/src/render.rs:1625 unexpected_cfgs rendering omits Cargo's automatic check-cfg values

Some inline comments could not be placed on the diff:

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec7295061e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread lib/rust.nix
Comment thread packages/nix-cargo-unit/src/render.rs Outdated
Comment thread packages/nix-cargo-unit/src/render.rs Outdated
@andrewgazelka Andrew Gazelka (andrewgazelka) force-pushed the codex/cargo-unit-manifest-lints branch from ec72950 to 4b14005 Compare May 28, 2026 02:55
@andrewgazelka Andrew Gazelka (andrewgazelka) force-pushed the codex/cargo-unit-manifest-lints branch from 4b14005 to fa14265 Compare May 28, 2026 02:57
@andrewgazelka Andrew Gazelka (andrewgazelka) changed the title rust: derive lints from cargo manifests rust: take lints from cargo unit graph May 28, 2026
@andrewgazelka Andrew Gazelka (andrewgazelka) merged commit 4c334d4 into main May 28, 2026
9 of 11 checks passed
@andrewgazelka Andrew Gazelka (andrewgazelka) deleted the codex/cargo-unit-manifest-lints branch May 28, 2026 03:01
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

AI review found issues in this pull request.

Verdict: patch is incorrect
Confidence: 0.90

The patch leaves the test suite internally inconsistent after clearing the shared clippy lint defaults, so required repo checks are expected to fail.

  • P1 lib/rust.nix:40 Default lint policy now contradicts the remaining repo-package test

Comment thread lib/rust.nix
Comment on lines +40 to +41
deniedLints = [ ];
allowedLints = [ ];
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.

P1 Badge Default lint policy now contradicts the remaining repo-package test

Changing the shared default clippy.deniedLints to [] applies to every rust.resolvePolicy caller, including the repo package workspace exposed through repoPackages.*.passthru.policy. The PR updates the cargoUnitWorkspace assertion to expect an empty list, but the existing tests/default.nix repo-package assertion still expects warnings and the clippy groups, so the repo eval/lint check will fail. Either update that remaining assertion to the new Cargo.toml-owned contract or keep an explicit strict policy for repo packages.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa14265d9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment on lines +26 to +29
#[serde(default)]
pub lint_rustflags: Vec<String>,
#[serde(default)]
pub check_cfg_args: Vec<String>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Populate lint flags from manifests instead

When the real Cargo unit graph is used, these fields are absent: Cargo's unit_graph::SerializedUnit still serializes only pkg_id, target, profile, platform, mode, features, is_std, and dependencies, and a local cargo +1.95.0 build --unit-graph -Z unstable-options with [lints] produced no lint_rustflags or check_cfg_args. Because the new fields default to empty here, every generated unit silently drops the workspace manifest lints, so nix-cargo-unit builds no longer deny warnings after the Nix-side defaults were removed.

Useful? React with 👍 / 👎.

Comment on lines 878 to +882
for rustflag in &unit.profile.rustflags {
push_arg(script, rustflag);
}
for rustflag in &unit.lint_rustflags {
push_arg(script, rustflag);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve Cargo's lint flag precedence

For packages that set profile rustflags to override a manifest lint level, this renders the flags in the opposite order from Cargo: Cargo appends manifest lint flags before profile rustflags, while this puts profile.rustflags first and then lint_rustflags. Since rustc uses the later lint level for the same lint, generated unit builds can fail or pass differently from cargo build whenever profile rustflags adjust a lint configured in [lints].

Useful? React with 👍 / 👎.

Comment on lines +884 to +886
for arg in &unit.check_cfg_args {
push_arg(script, arg);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Forward build-script check-cfg declarations

For crates that enable unexpected_cfgs and have a build script emit a dynamic cfg, Cargo forwards both cargo::rustc-cfg=has_foo and its matching cargo::rustc-check-cfg=cfg(has_foo) to the final rustc command. This only appends the static unit check_cfg_args, while the build-script reader later consumes rustc-cfg but not rustc-check-cfg, so generated builds reject valid build-script cfgs as unexpected even though cargo build accepts them.

Useful? React with 👍 / 👎.

Comment thread Cargo.toml
Comment on lines +30 to +31
cargo = "deny"
multiple_crate_versions = "allow"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Set a lower priority for the clippy::cargo group

With manifest lint tables, Cargo ignores table order and Clippy rejects a lint group and an overridden member at the same priority. This combination makes cargo clippy fail with clippy::lint_groups_priority before checking the crate because clippy::cargo and clippy::multiple_crate_versions both default to priority 0; the old CLI flags did not trigger that manifest-priority lint. Set the group to a lower priority, for example cargo = { level = "deny", priority = -1 }, so the allow can override it.

Useful? React with 👍 / 👎.

Wyatt Gill (wyattgill9) added a commit that referenced this pull request May 28, 2026
The Nix-side clippy policy stopped seeding default deniedLints once the
workspace started inheriting [workspace.lints] in Cargo.toml (#239), so
the eval-time check should mirror that contract instead of asserting the
old strict-lint list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant