Skip to content

enable clippy nursery mode#507

Merged
mrshmllow merged 1 commit into
trunkfrom
marshmallow/p-uqouktvuoktx
Jun 7, 2026
Merged

enable clippy nursery mode#507
mrshmllow merged 1 commit into
trunkfrom
marshmallow/p-uqouktvuoktx

Conversation

@mrshmllow

@mrshmllow mrshmllow commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • Refactor

    • Streamlined control flow patterns and simplified error handling logic across multiple modules.
    • Optimized resource cleanup and lock guard management during asynchronous operations.
  • Chores

    • Enhanced code quality with stricter linting standards and enforcement.
    • Improved internal module visibility for better code organization and maintainability.

@github-actions github-actions Bot added rust Pull requests that update rust code release PRs against main labels Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR modernizes the codebase by enabling stricter Clippy linting, tightening async generic bounds across command-execution and client interfaces, expanding public APIs for command handling, and refactoring control flow to use contemporary Rust patterns like map_or_else, Self constructors, and explicit drop calls for borrow lifetime precision.

Changes

Lint Hardening & Code Quality Modernization

Layer / File(s) Summary
Workspace Clippy configuration and lint suppressions
Cargo.toml, crates/cli/src/tracing_setup.rs, crates/core/src/commands/noninteractive.rs, crates/core/src/commands/pty/mod.rs, crates/core/src/hive/steps/activate.rs, crates/core/src/status.rs
Enables the Clippy nursery lint group at deny severity in workspace config. Adds Clippy lint suppression attributes (allow(clippy::significant_drop_tightening) and allow(clippy::iter_with_drain)) before code regions where temporary borrows intentionally extend or where draining while iterating serves correctness.
Async generic bound tightening for Send+Sync
crates/cli/src/apply.rs, crates/core/src/commands/mod.rs, crates/core/src/commands/noninteractive.rs, crates/core/src/commands/pty/mod.rs, crates/core/src/lib.rs, crates/nix_client/src/lib.rs
Tightens generic constraints across async functions and closure types by requiring S: AsRef<str> + Sync on command string types, adding Send bounds to trace-callback closures in NixClient, and adding R: Send to stream impls for thread-safe spawning of command processes.
Public visibility expansion for command types
crates/core/src/commands/builder.rs, crates/core/src/commands/noninteractive.rs, crates/core/src/commands/pty/logbuffer.rs, crates/core/src/commands/pty/mod.rs, crates/cli/src/sigint.rs
Promotes internal command-handling and signal-handling types from crate-private to public: CommandStringBuilder, NonInteractiveChildChip, non_interactive_command_with_env, InteractiveChildChip, interactive_command_with_env, LogBuffer, and handle_signals, enabling use across crate boundaries.
Control flow modernization and borrow management
crates/cli/src/apply.rs, crates/cli/src/cli.rs, crates/cli/src/main.rs, crates/cli/src/tracing_setup.rs, crates/core/src/cache/mod.rs, crates/core/src/commands/common.rs, crates/core/src/commands/mod.rs, crates/core/src/commands/noninteractive.rs, crates/core/src/commands/pty/mod.rs, crates/core/src/commands/pty/output.rs, crates/core/src/errors.rs, crates/core/src/hive/mod.rs, crates/core/src/hive/node.rs, crates/core/src/hive/plan.rs, crates/core/src/lib.rs, crates/nix_client/src/lib.rs, crates/nix_client/src/store_path.rs
Refactors conditional patterns to use map_or_else and matches! instead of if-let/match; uses Self in constructor returns and impl conversions; adds explicit drop() calls for precise borrow lifetime control; removes unnecessary clones in logging and reduces iterator/collection allocations by using .count() instead of .collect().len().
Type equality and derive trait updates
crates/core/src/hive/mod.rs, crates/core/src/hive/steps/evaluate.rs, crates/core/src/errors.rs, crates/core/src/hive/steps/keys.rs, crates/nix_client/src/store_path.rs
Adds Eq trait derivation alongside PartialEq for Hive and Evaluate structs; updates method return types from concrete type names to Self (SafeStorePath::from_absolute_path, Hive::new_from_path, HiveLocation::get_flake, NixClient::handshake); refactors deserialization to construct via Self { ... } for consistency.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • forallsys/wire#502: Both PRs refactor gc_evaluation_cache logic in crates/core/src/cache/mod.rs, changing how entry invalidity is determined and tracked.
  • forallsys/wire#400: Both PRs modify crates/core/src/commands/noninteractive.rs API surface and bounds; this PR tightens non_interactive_command_with_env with S: Sync and expands visibility while the earlier PR introduced async/SharedTarget refactoring.
  • forallsys/wire#499: Both PRs tighten generic bounds and refactor command execution paths in crates/core/src/commands/mod.rs and nix-daemon integration, directly affecting the same async spawning and tracing code.

Suggested Labels

rust

Poem

🐰 Lints now nurseries embrace,
Sync bounds keep async in place,
Self and drop make borrows tight,
Control flows dance in patterns bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The PR title 'enable clippy nursery mode' accurately describes the main change: adding Clippy nursery lint configuration to Cargo.toml while also addressing multiple Clippy warnings throughout the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch marshmallow/p-uqouktvuoktx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
crates/core/src/commands/pty/mod.rs (1)

47-47: Reconsider pub visibility on InteractiveChildChip.
rg finds no references to InteractiveChildChip outside crates/core/**, so no external crate currently uses it. Unless this is intended as part of the public API, consider keeping it pub(crate).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/core/src/commands/pty/mod.rs` at line 47, InteractiveChildChip is
declared pub but appears unused outside the crate; change its visibility to
pub(crate) if it is not intended as part of the public API by updating the
struct declaration for InteractiveChildChip to use pub(crate) instead of pub,
and run a build/test to ensure no external code requires the public visibility.
crates/cli/src/sigint.rs (1)

12-12: Reduce handle_signals visibility in crates/cli/src/sigint.rs

  • handle_signals is only used from crates/cli/src/main.rs and has no usages outside crates/cli, so pub doesn’t need to expose any external API (the crates/cli crate is bin-only—no lib.rs).
  • Keep it accessible to main.rs (it’s imported via mod sigint; use crate::sigint::handle_signals;), but prefer pub(super) or pub(crate) instead of pub.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/cli/src/sigint.rs` at line 12, The function handle_signals is
unnecessarily public; change its visibility from pub to a restricted visibility
so it remains accessible to main.rs but not exported outside the binary
crate—replace the signature pub async fn handle_signals(...) with a narrower
visibility like pub(crate) async fn handle_signals(...) (or pub(super) if you
prefer module-level restriction) so the existing import pattern (mod sigint; use
crate::sigint::handle_signals;) still works but the symbol is not exposed
externally.
crates/core/src/commands/noninteractive.rs (1)

25-25: Make NonInteractiveChildChip pub(crate)
Search for NonInteractiveChildChip outside crates/core returns no matches, so it isn’t referenced by other crates; it can likely be crate-private unless you intentionally want it to be part of the public API.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/core/src/commands/noninteractive.rs` at line 25, The struct
NonInteractiveChildChip is exported publicly but not used outside the crate;
change its visibility to crate-private by replacing its declaration modifier
(pub) with pub(crate) for NonInteractiveChildChip so it remains accessible
within the crate but not part of the public API; ensure any internal uses
continue to compile and run tests to verify no external references break.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/nix_client/src/lib.rs`:
- Around line 146-149: The impls currently force T and reader types to be Send
at the impl level (see impl<NixClient<UnixStream, UnixStream, T>> and impl<R, W,
T> NixClient) which unnecessarily tightens the API; instead, remove the + Send
bound from the impl-level where clauses (delete + Send from T and from R in the
generic impl) and only require Send on the individual async methods that
actually need multithreaded futures (the async read/write methods referenced
around lines ~174-178). Concretely: drop the Send requirement from the impl
declarations (NixClient<UnixStream,UnixStream,T> and impl<R,W,T>) and add + Send
to the specific method-level where clauses (the async reader/writer functions)
so callers with non-Send callbacks/readers can still use the sync parts while
preserving Send for methods that will be spawned.

---

Nitpick comments:
In `@crates/cli/src/sigint.rs`:
- Line 12: The function handle_signals is unnecessarily public; change its
visibility from pub to a restricted visibility so it remains accessible to
main.rs but not exported outside the binary crate—replace the signature pub
async fn handle_signals(...) with a narrower visibility like pub(crate) async fn
handle_signals(...) (or pub(super) if you prefer module-level restriction) so
the existing import pattern (mod sigint; use crate::sigint::handle_signals;)
still works but the symbol is not exposed externally.

In `@crates/core/src/commands/noninteractive.rs`:
- Line 25: The struct NonInteractiveChildChip is exported publicly but not used
outside the crate; change its visibility to crate-private by replacing its
declaration modifier (pub) with pub(crate) for NonInteractiveChildChip so it
remains accessible within the crate but not part of the public API; ensure any
internal uses continue to compile and run tests to verify no external references
break.

In `@crates/core/src/commands/pty/mod.rs`:
- Line 47: InteractiveChildChip is declared pub but appears unused outside the
crate; change its visibility to pub(crate) if it is not intended as part of the
public API by updating the struct declaration for InteractiveChildChip to use
pub(crate) instead of pub, and run a build/test to ensure no external code
requires the public visibility.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9197e76e-1dac-445b-aeae-eaaee51d1361

📥 Commits

Reviewing files that changed from the base of the PR and between 9125ad5 and 2aabd14.

📒 Files selected for processing (25)
  • Cargo.toml
  • crates/cli/src/apply.rs
  • crates/cli/src/cli.rs
  • crates/cli/src/main.rs
  • crates/cli/src/sigint.rs
  • crates/cli/src/tracing_setup.rs
  • crates/core/src/cache/mod.rs
  • crates/core/src/commands/builder.rs
  • crates/core/src/commands/common.rs
  • crates/core/src/commands/mod.rs
  • crates/core/src/commands/noninteractive.rs
  • crates/core/src/commands/pty/logbuffer.rs
  • crates/core/src/commands/pty/mod.rs
  • crates/core/src/commands/pty/output.rs
  • crates/core/src/errors.rs
  • crates/core/src/hive/mod.rs
  • crates/core/src/hive/node.rs
  • crates/core/src/hive/plan.rs
  • crates/core/src/hive/steps/activate.rs
  • crates/core/src/hive/steps/evaluate.rs
  • crates/core/src/hive/steps/keys.rs
  • crates/core/src/lib.rs
  • crates/core/src/status.rs
  • crates/nix_client/src/lib.rs
  • crates/nix_client/src/store_path.rs

Comment on lines 146 to 149
impl<T> NixClient<UnixStream, UnixStream, T>
where
T: Fn(LogMessage, &Arc<Mutex<HashMap<u64, Arc<String>>>>, bool) -> Option<String>,
T: Fn(LogMessage, &Arc<Mutex<HashMap<u64, Arc<String>>>>, bool) -> Option<String> + Send,
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find NixClient usage patterns and callback definitions

echo "=== NixClient::open_local calls ==="
rg -nP '\bNixClient::open_local\s*\(' --type=rust -C3

echo -e "\n=== NixClient::handshake calls ==="
rg -nP '\bNixClient::handshake\s*\(' --type=rust -C3

echo -e "\n=== Callback function definitions ==="
rg -nP 'trace_nix_log_message|trace_callback' --type=rust -C2

Repository: forallsys/wire

Length of output: 10631


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show relevant sections around the reported lines.
echo "=== crates/nix_client/src/lib.rs: lines 120-220 ==="
nl -ba crates/nix_client/src/lib.rs | sed -n '110,230p'

echo "=== crates/nix_client/src/lib.rs: lines 230-320 ==="
nl -ba crates/nix_client/src/lib.rs | sed -n '230,330p'

# Search for all Send bounds in nix_client lib.
echo "=== Send bounds in crates/nix_client/src/lib.rs ==="
rg -n "Send\b" crates/nix_client/src/lib.rs

# Identify the NixClient struct and its generic parameters.
echo "=== NixClient struct/impl generics ==="
rg -n "struct NixClient|impl<|type NixClient" crates/nix_client/src/lib.rs

Repository: forallsys/wire

Length of output: 171


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== crates/nix_client/src/lib.rs: lines 120-220 ==="
nl -ba crates/nix_client/src/lib.rs | sed -n '120,220p'

echo "=== crates/nix_client/src/lib.rs: lines 220-320 ==="
nl -ba crates/nix_client/src/lib.rs | sed -n '220,330p'

echo "=== Send bounds in crates/nix_client/src/lib.rs ==="
rg -n "Send\b" crates/nix_client/src/lib.rs

echo "=== NixClient struct and key impl blocks ==="
rg -n "struct NixClient|impl<" crates/nix_client/src/lib.rs

Repository: forallsys/wire

Length of output: 171


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== crates/nix_client/src/lib.rs: lines 120-220 ==="
nl -ba crates/nix_client/src/lib.rs | sed -n '120,220p'

echo "=== crates/nix_client/src/lib.rs: lines 220-330 ==="
nl -ba crates/nix_client/src/lib.rs | sed -n '220,330p'

echo "=== Send bounds in crates/nix_client/src/lib.rs ==="
rg -n "Send\b" crates/nix_client/src/lib.rs

echo "=== NixClient struct and key impl blocks ==="
rg -n "struct NixClient|impl<" crates/nix_client/src/lib.rs

Repository: forallsys/wire

Length of output: 171


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="crates/nix_client/src/lib.rs"

echo "=== Print crates/nix_client/src/lib.rs with line numbers (120-220) ==="
awk 'NR>=120 && NR<=220 {printf "%6d\t%s\n", NR, $0}' "$FILE"

echo "=== Print crates/nix_client/src/lib.rs with line numbers (220-330) ==="
awk 'NR>=220 && NR<=330 {printf "%6d\t%s\n", NR, $0}' "$FILE"

echo "=== Search for Send bounds in crates/nix_client/src/lib.rs ==="
rg -n "Send\b" "$FILE"

echo "=== Search for reader generic bounds containing Send (best-effort) ==="
rg -n "R\s*:\s*[^,\n]*Send|reader[^,\n]*Send" "$FILE" || true

echo "=== Search for where-clauses containing Send (best-effort) ==="
rg -n "where[^{\n]*Send|where[^{]*\+ Send|where[^\n]*Send" "$FILE" || true

Repository: forallsys/wire

Length of output: 11662


Confirm Send bound tightening affects both callback (T) and reader (R) generics

crates/nix_client/src/lib.rs now requires the callback to be Send (T: ... + Send) in both the UnixStream-specific impl and the generic impl, and it also requires the reader to be Send (impl<R, W, T> ... where ... R: Send). The async methods further add R: ... + Send / W: ... + Send bounds, which tightens the contract for any users providing non-Send readers/callbacks and affects whether the resulting async futures can be used with multithreaded executors (e.g., when spawned). [lines 146-149, 174-178]

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/nix_client/src/lib.rs` around lines 146 - 149, The impls currently
force T and reader types to be Send at the impl level (see
impl<NixClient<UnixStream, UnixStream, T>> and impl<R, W, T> NixClient) which
unnecessarily tightens the API; instead, remove the + Send bound from the
impl-level where clauses (delete + Send from T and from R in the generic impl)
and only require Send on the individual async methods that actually need
multithreaded futures (the async read/write methods referenced around lines
~174-178). Concretely: drop the Send requirement from the impl declarations
(NixClient<UnixStream,UnixStream,T> and impl<R,W,T>) and add + Send to the
specific method-level where clauses (the async reader/writer functions) so
callers with non-Send callbacks/readers can still use the sync parts while
preserving Send for methods that will be spawned.

@mrshmllow mrshmllow force-pushed the marshmallow/p-uqouktvuoktx branch from 2aabd14 to ceb9acb Compare June 7, 2026 02:28
@mrshmllow mrshmllow changed the title enable clippy pedantic mode enable clippy nursery mode Jun 7, 2026
@mrshmllow mrshmllow merged commit 8856bb7 into trunk Jun 7, 2026
26 of 28 checks passed
@mrshmllow mrshmllow deleted the marshmallow/p-uqouktvuoktx branch June 7, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release PRs against main rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant