From 4e427d9b7e2cd1a68dba68b1a8c36d4fc6b27585 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sun, 16 Aug 2026 08:39:52 +0800 Subject: [PATCH] docs(view): say why the prompt editor's row unwraps cannot fail `lines.last_mut().unwrap()` appears six times while laying out the inline editor, the furthest of them seventy lines from the thing that makes it safe: `lines` is seeded with one row and rows are only ever pushed. A reader meeting the unwrap first has to go looking, and a reader adding a `pop` or a `drain` has nothing to warn them. Found by sweeping the tree for panicking arithmetic and unwraps rather than by anything failing. Everything else that sweep turned up is already guarded, and the guards are worth recording as checked: - `heal_active` in tree_sync returns early on an empty tab list before `tabs.len() - 1`, matching the `ActiveTabChanged` contract that a workspace with no tabs simply has no active tab. - The scrollback ring's `bytes[bytes.len() - RING_CAP..]` sits behind `if bytes.len() >= RING_CAP`, and its neighbours use saturating adds. - The tab-title eliders bound every head against `cells.len()` before subtracting, and the binary search's `mid - 1` cannot underflow because `mid` is at least 1 whenever `lo < hi`. --- src/terminal/view.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/terminal/view.rs b/src/terminal/view.rs index 74639b15..18e929aa 100644 --- a/src/terminal/view.rs +++ b/src/terminal/view.rs @@ -5508,6 +5508,10 @@ impl TerminalView { let blank = move |w: gpui::Pixels| div().flex_none().w(w).h(lh); + // Seeded with one row, and rows are only ever pushed — never popped or + // drained. That is what makes the `lines.last_mut().unwrap()` below + // safe, several of them a long way from here: there is always a row to + // append to, including before the first newline is seen. let mut lines: Vec> = vec![vec![blank(cell_w * (ccol as f32)).into_any_element()]];