zed-industries/zed · error

prefixes is non-empty

Error message

prefixes is non-empty

What it means

A precondition guard in toggle_comments: the code took language.line_comment_prefixes() (possibly trimmed for ignore_indent) and later expects the resulting prefix collection to be non-empty before inserting comment tokens. It fires when toggle_comments proceeds on a language that (after trimming) yields zero comment prefixes — the caller should have bailed before reaching the insertion step.

Source

Thrown at crates/editor/src/input.rs:1544

                    continue;
                }

                // If the language has line comments, toggle those.
                let mut full_comment_prefixes = language.line_comment_prefixes().to_vec();

                // If ignore_indent is set, trim spaces from the right side of all full_comment_prefixes
                if ignore_indent {
                    full_comment_prefixes = full_comment_prefixes
                        .into_iter()
                        .map(|s| Arc::from(s.trim_end()))
                        .collect();
                }

                if !full_comment_prefixes.is_empty() {
                    let first_prefix = full_comment_prefixes
                        .first()
                        .expect("prefixes is non-empty");
                    let prefix_trimmed_lengths = full_comment_prefixes
                        .iter()
                        .map(|p| p.trim_end_matches(' ').len())
                        .collect::<SmallVec<[usize; 4]>>();

                    let mut commented_lines = 0;
                    let mut uncommented_lines = 0;

                    for row in start_row.0..=end_row.0 {
                        let row = MultiBufferRow(row);
                        let is_blank = start_row < end_row && snapshot.is_line_blank(row);
                        if !comment_empty_lines && is_blank {
                            continue;
                        }

                        let prefix_range = full_comment_prefixes
                            .iter()
                            .zip(prefix_trimmed_lengths.iter().copied())
                            .map(|(prefix, trimmed_prefix_len)| {

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Check full_comment_prefixes.is_empty() after collection/trimming and return early (or fall through to block-comment handling)
  2. Fall back to the language's block comment syntax when line prefixes are empty
  3. Guard at the action level: disable the toggle comments action for languages without any comment tokens
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/editor/src/input.rs:1542 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/173686efa3f77ddc. Report an issue: GitHub.