zed-industries/zed · error
{self:?} is not a named SearchOption
Error message
{self:?} is not a named SearchOption What it means
SearchOption::icon() maps only the four options rendered as toolbar toggle buttons (WholeWord, CaseSensitive, IncludeIgnored, Regex) to icons; every other variant falls into the wildcard panic arm (crates/search/src/search.rs:115). It is a tripwire forcing new SearchOption variants to be classified: either a named toolbar button or something that must never be rendered as one.
Source
Thrown at crates/search/src/search.rs:115
pub fn label(&self) -> &'static str {
match self {
SearchOption::WholeWord => "Match Whole Words",
SearchOption::CaseSensitive => "Match Case Sensitivity",
SearchOption::IncludeIgnored => "Also search files ignored by configuration",
SearchOption::Regex => "Use Regular Expressions",
SearchOption::OneMatchPerLine => "One Match Per Line",
SearchOption::Backwards => "Search Backwards",
}
}
pub fn icon(&self) -> ui::IconName {
match self {
SearchOption::WholeWord => IconName::WholeWord,
SearchOption::CaseSensitive => IconName::CaseSensitive,
SearchOption::IncludeIgnored => IconName::FileIgnored,
SearchOption::Regex => IconName::Regex,
_ => panic!("{self:?} is not a named SearchOption"),
}
}
pub fn to_toggle_action(self) -> &'static dyn Action {
match self {
SearchOption::WholeWord => &ToggleWholeWord,
SearchOption::CaseSensitive => &ToggleCaseSensitive,
SearchOption::IncludeIgnored => &ToggleIncludeIgnored,
SearchOption::Regex => &ToggleRegex,
_ => panic!("{self:?} is not a toggle action"),
}
}
pub fn as_button(
&self,
active: SearchOptions,
search_source: SearchSource,
focus_handle: FocusHandle,View on GitHub (pinned to f4178619ac)
Solutions
- Only pass the four toggle-capable options down icon/button paths; keep an explicit const list (WholeWord, CaseSensitive, IncludeIgnored, Regex) for the toolbar.
- If the new variant should be a toolbar button, add it to icon(), the label/action mapping, and to_toggle_action() in the same change.
- Replace the wildcard arm with an exhaustive match so unclassified variants become compile errors instead of runtime panics.
- Use the backtrace to find the caller (usually as_button via the search toolbar construction) and what variant it passed.
Example fix
// before
match self {
SearchOption::WholeWord => IconName::WholeWord,
_ => panic!("{self:?} is not a named SearchOption"),
}
// after: exhaustive match forces classification of new variants
match self {
SearchOption::WholeWord => IconName::WholeWord,
SearchOption::CaseSensitive => IconName::CaseSensitive,
SearchOption::IncludeIgnored => IconName::FileIgnored,
SearchOption::Regex => IconName::Regex,
SearchOption::OneMatchPerLine | SearchOption::Backwards => {
IconName::CaseSensitive // placeholder: decide deliberately
}
} Defensive patterns
Strategy: type-guard
Type guard
fn is_toggle_button_option(option: SearchOption) -> bool {
matches!(
option,
SearchOption::WholeWord
| SearchOption::CaseSensitive
| SearchOption::IncludeIgnored
| SearchOption::Regex
)
}
if is_toggle_button_option(option) {
toolbar.child(option.as_button(active, source, focus_handle));
} Prevention
- Make matches over SearchOption exhaustive (no wildcard arm) so new variants fail at compile time.
- Keep one const list of toolbar options next to the enum and render only from it.
- Add a unit test iterating all variants asserting icon()/to_toggle_action() are guarded or supported.
When it happens
Trigger: Calling SearchOption::icon() — directly or via as_button(), which builds the toolbar toggle — on SearchOption::OneMatchPerLine or SearchOption::Backwards. Typical shape: a loop over a list of 'all' options that renders each as a button.
Common situations: Making the search toolbar option list data-driven and feeding it every variant; adding a new SearchOption variant meant to be config-only but passed to the button builder; refactors that generalize option rendering.
Related errors
- {self:?} is not a toggle action
- compute_indents_fn is required for UniformListDecoration
- row out of range
- invalid display row {}
- blocking sender returned without value
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/f383bb4f3dc36d8e.
Report an issue: GitHub.