{"record":{"id":"257bbd904cc42996","repo":"zed-industries/zed","slug":"self-is-not-a-toggle-action","errorCode":null,"errorMessage":"{self:?} is not a toggle action","messagePattern":"(.+?) is not a toggle action","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/search/src/search.rs","lineNumber":125,"sourceCode":"    }\n\n    pub fn icon(&self) -> ui::IconName {\n        match self {\n            SearchOption::WholeWord => IconName::WholeWord,\n            SearchOption::CaseSensitive => IconName::CaseSensitive,\n            SearchOption::IncludeIgnored => IconName::FileIgnored,\n            SearchOption::Regex => IconName::Regex,\n            _ => panic!(\"{self:?} is not a named SearchOption\"),\n        }\n    }\n\n    pub fn to_toggle_action(self) -> &'static dyn Action {\n        match self {\n            SearchOption::WholeWord => &ToggleWholeWord,\n            SearchOption::CaseSensitive => &ToggleCaseSensitive,\n            SearchOption::IncludeIgnored => &ToggleIncludeIgnored,\n            SearchOption::Regex => &ToggleRegex,\n            _ => panic!(\"{self:?} is not a toggle action\"),\n        }\n    }\n\n    pub fn as_button(\n        &self,\n        active: SearchOptions,\n        search_source: SearchSource,\n        focus_handle: FocusHandle,\n    ) -> impl IntoElement {\n        let action = self.to_toggle_action();\n        let label = self.label();\n\n        IconButton::new(\n            (label, matches!(search_source, SearchSource::Buffer) as u32),\n            self.icon(),\n        )\n        .map(|button| match search_source {\n            SearchSource::Buffer => {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/search/src/search.rs#L107-L143","documentation":"SearchOption::to_toggle_action() returns the toggle Action for the four options that have one (ToggleWholeWord, ToggleCaseSensitive, ToggleIncludeIgnored, ToggleRegex); as_button() calls it unconditionally on its first line (crates/search/src/search.rs:135). Variants without a toggle action — OneMatchPerLine, Backwards — hit the panic arm at crates/search/src/search.rs:125.","triggerScenarios":"Calling SearchOption::to_toggle_action() or SearchOption::as_button() with SearchOption::OneMatchPerLine or SearchOption::Backwards; any generic loop that builds a button per option without filtering to the toggle subset.","commonSituations":"Data-driven option rendering that assumes every option is a toolbar toggle; newly added SearchOption variants not classified; UI refactors generalizing the search options bar.","solutions":["Filter to the four toggle options before building buttons (a matches! guard or a const list next to the enum).","If the variant needs a toggle action, define the Action and add a match arm to to_toggle_action().","Make the match exhaustive to turn future variant additions into compile errors.","Check the backtrace: the caller above as_button passed the unsupported variant."],"exampleFix":"// before\nfor option in all_options { // includes OneMatchPerLine, Backwards\n    toolbar.child(option.as_button(active, source, focus.clone()));\n}\n\n// after\nconst TOGGLE_OPTIONS: &[SearchOption] = &[\n    SearchOption::WholeWord,\n    SearchOption::CaseSensitive,\n    SearchOption::IncludeIgnored,\n    SearchOption::Regex,\n];\nfor option in TOGGLE_OPTIONS {\n    toolbar.child(option.as_button(active, source, focus.clone()));\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn has_toggle_action(option: SearchOption) -> bool {\n    matches!(\n        option,\n        SearchOption::WholeWord\n            | SearchOption::CaseSensitive\n            | SearchOption::IncludeIgnored\n            | SearchOption::Regex\n    )\n}\n\nif has_toggle_action(option) {\n    let action = option.to_toggle_action(); // safe: only the four toggle variants\n}","tryCatchPattern":null,"preventionTips":["Filter option lists with the guard before building buttons.","as_button() calls to_toggle_action() unconditionally — never feed it unguarded variants.","Define the Action and add the match arm when a variant genuinely needs a toggle."],"tags":["search","ui","enum","exhaustiveness","panic","zed"],"backgroundTag":"unhandled-enum-variant","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}