Repository navigation
runtime/cli: drop redundant guards already implied by the enclosing branch - #34805
Conversation
|
Status: ready for review. Pure no-behavior-change simplification (dead-branch removal); |
|
Warning Review limit reached
Next review available in: 5 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
There was a problem hiding this comment.
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 anis_empty()early-return cannot panic (yields&[]at len 1).packages.len() - 1inside!packages.is_empty()cannot underflow, and equals the removed else-value at len 1.- The
update_viewportarm's outer guard isviewport_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 subtractioncursor - (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.
|
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 |
Three small simplifications in
src/runtime/cli/where an inner condition re-checks something the enclosing branch already guarantees. No behavior change.shell_completions.rsShellCompletions::printreturns early whencommands.is_empty(), so at the point of the loopcommands.len() >= 1and&commands[1..]is always in bounds (an empty slice whenlen() == 1, which theforloop handles). Thelen() > 1wrapper adds nothing.update_interactive_command.rs,ensure_cursor_in_viewportInside
if !state.packages.is_empty()the length is at least 1, solen() - 1cannot underflow. Whenlen() == 1the expression is0, which is exactly what the removedelsebranch returned.update_interactive_command.rs,update_viewportThe third
else ifarm is guarded bystate.viewport_height > context_below && .... Neitherviewport_heightnorcontext_belowis mutated inside the arm, so re-testingviewport_height > context_belowbefore computingdesired_startalways takes the true branch. Both subtractions remain safe:viewport_height - context_belowis covered by the outer guard, andcursor - (viewport_height - context_below)is covered by the second conjunct (cursor > viewport_start + viewport_height - context_belowwithviewport_start: usize >= 0).Verification
cargo clippy -p bun_runtimeis clean and the existinggetcompletesandupdate --interactivesnapshot 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.