GitoxideLabs/gitoxide · error

fixed size array with three items

Error message

fixed size array with three items

What it means

`apply_index_entries` in `gix-merge` maps conflict stage slots from a fixed 3-element array (Base/Ours/Theirs). The `unreachable!` fires if the index exceeds 2, which the fixed-size array makes impossible — a compiler-invariant defense.

Solutions

  1. No user action needed; if hit, report upstream with the conflict reproduction.
  2. If maintaining, prefer exhaustive `Stage` iteration or `TryFrom` over `unreachable!` on index conversion.

Example fix

// before
_ => unreachable!("fixed size array with three items"),
// after
_ => Stage::try_from(idx as u8).expect("stage array has exactly Base/Ours/Theirs"),
Defensive patterns

Strategy: try-catch

Try / catch

// Compiler-guaranteed unreachable; no caller guard possible.

Prevention

When it happens

Trigger: Never reachable with the current fixed-size array; only a hazard if the stages array type is changed to a slice/Vec later.

Common situations: Not hit in real merges; appears only during code evolution mistakes.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/842ee8f1c95f481c. Report an issue: GitHub.

Appendix: source

Thrown at gix-merge/src/tree/mod.rs:573

                        } => (
                            Some(renamed_unique_path_to_modified_blob.as_bstr()),
                            conflict.ours.location(),
                        ),
                        ResolutionFailure::OursAddedTheirsAddedTypeMismatch { their_unique_location } => {
                            (Some(their_unique_location.as_bstr()), conflict.ours.location())
                        }
                    },
                };
                let source_path = conflict.ours.source_location();

                let entries_with_stage = conflict.entries().into_iter().enumerate().filter_map(|(idx, entry)| {
                    entry.filter(|e| e.mode.is_no_tree()).map(|e| {
                        (
                            match idx {
                                0 => gix_index::entry::Stage::Base,
                                1 => gix_index::entry::Stage::Ours,
                                2 => gix_index::entry::Stage::Theirs,
                                _ => unreachable!("fixed size array with three items"),
                            },
                            match e.path_hint {
                                None => renamed_path.unwrap_or(current_path),
                                Some(ConflictIndexEntryPathHint::Source) => source_path,
                                Some(ConflictIndexEntryPathHint::Current) => current_path,
                                Some(ConflictIndexEntryPathHint::RenamedOrTheirs) => {
                                    renamed_path.unwrap_or_else(|| conflict.changes_in_resolution().1.location())
                                }
                            },
                            e,
                        )
                    })
                });

                if !entries_with_stage.clone().any(|(_, path, _)| {
                    index
                        .entry_index_by_path_and_stage_bounded(path, gix_index::entry::Stage::Unconflicted, len)
                        .is_some()

View on GitHub (pinned to e73179060b)