Skip to content

runtime/cli: drop redundant guards already implied by the enclosing branch - #34805

Merged
dylan-conway merged 1 commit into
mainfrom
farm/37386e74/cli-drop-redundant-guards
Jul 20, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
farm/37386e74/cli-drop-redundant-guards

Conversation

@robobun

@robobun robobun commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Three small simplifications in src/runtime/cli/ where an inner condition re-checks something the enclosing branch already guarantees. No behavior change.

shell_completions.rs

ShellCompletions::print returns early when commands.is_empty(), so at the point of the loop commands.len() >= 1 and &commands[1..] is always in bounds (an empty slice when len() == 1, which the for loop handles). The len() > 1 wrapper adds nothing.

update_interactive_command.rs, ensure_cursor_in_viewport

Inside if !state.packages.is_empty() the length is at least 1, so len() - 1 cannot underflow. When len() == 1 the expression is 0, which is exactly what the removed else branch returned.

update_interactive_command.rs, update_viewport

The third else if arm is guarded by state.viewport_height > context_below && .... Neither viewport_height nor context_below is mutated inside the arm, so re-testing viewport_height > context_below before computing desired_start always takes the true branch. Both subtractions remain safe: viewport_height - context_below is covered by the outer guard, and cursor - (viewport_height - context_below) is covered by the second conjunct (cursor > viewport_start + viewport_height - context_below with viewport_start: usize >= 0).

Verification

cargo clippy -p bun_runtime is clean and the existing getcompletes and update --interactive snapshot tests pass unchanged with the debug build. Because the change preserves behavior exactly, there is no input that distinguishes before from after, so no new regression test is added.

@robobun

robobun commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. Pure no-behavior-change simplification (dead-branch removal); cargo clippy -p bun_runtime clean, existing getcompletes and update-interactive tests pass with the debug build. Self-review found no surviving concerns. The pre-existing descriptions[i] mis-pairing flagged inline is tracked separately (it's half of a larger sort-alignment bug in run_command.rs).

@robobun

robobun commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 1:46 AM PT - Jul 20th, 2026

@robobun, your commit 999473e is building: #76181

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: dd5ec4f7-9d44-4497-af95-da53b66fcfaa

📥 Commits

Reviewing files that changed from the base of the PR and between 01e913e and 999473e.

📒 Files selected for processing (2)
  • src/runtime/cli/shell_completions.rs
  • src/runtime/cli/update_interactive_command.rs

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

@claude claude Bot left a comment

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.

LGTM — all three removed guards are provably implied by their enclosing conditions, so this is byte-for-byte behavior-preserving. The inline note on descriptions[i] is pre-existing and orthogonal; fine to punt.

Extended reasoning...

Overview

Three de-indentation simplifications in src/runtime/cli/: removes an if commands.len() > 1 wrapper around a loop over commands[1..] in ShellCompletions::print, collapses a len() > 1 { len() - 1 } else { 0 } to len() - 1 inside a !is_empty() guard in ensure_cursor_in_viewport, and drops a re-test of viewport_height > context_below inside an else if arm already gated on that exact predicate in update_viewport.

Security risks

None. Shell-completion stdout formatting and interactive-TUI viewport arithmetic; no untrusted input parsing, no I/O boundary changes.

Level of scrutiny

Low. Each removal is a tautology check:

  • commands[1..] after an is_empty() early-return cannot panic (yields &[] at len 1).
  • packages.len() - 1 inside !packages.is_empty() cannot underflow, and equals the removed else-value at len 1.
  • The update_viewport arm's outer guard is viewport_height > context_below && cursor > viewport_start + viewport_height - context_below; neither operand is mutated before the removed inner check, so the true branch was always taken. The remaining subtraction cursor - (viewport_height - context_below) stays safe via the second conjunct (viewport_start >= 0).

Other factors

The one flagged issue (descriptions[i] off-by-one) is pre-existing — the diff only de-indents that line unchanged — and is cosmetic (mis-paired zsh completion hints), so it doesn't block. Clippy is clean and existing snapshot tests pass per the description; no new test is expected since no input distinguishes before/after.

Comment thread src/runtime/cli/shell_completions.rs Resolved
@robobun

robobun commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: this is a behavior-preserving simplification, so by construction no input distinguishes the before state from the after state and there is no regression test that can fail-before/pass-after.

For each of the three sites the removed branch is provably unreachable under the enclosing guard (proof in the PR body), so any test that exercises these paths passes identically with or without the diff. Self-review and the automated review both confirmed the equivalence.

The branch is left up in case a maintainer wants to land the cleanup manually. The adjacent descriptions[i] mis-pairing noted inline is a real behavior bug and is being fixed separately.

@robobun robobun closed this Jul 20, 2026
@dylan-conway dylan-conway reopened this Jul 20, 2026
@dylan-conway
dylan-conway merged commit 822ef64 into main Jul 20, 2026
58 of 70 checks passed
@dylan-conway
dylan-conway deleted the farm/37386e74/cli-drop-redundant-guards branch July 20, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants