{"record":{"id":"abb266b258c9b8a9","repo":"zed-industries/zed","slug":"just-written-the-type-downcasted-to","errorCode":null,"errorMessage":"just written the type downcasted to","messagePattern":"just written the type downcasted to","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/editor/src/items.rs","lineNumber":1652,"sourceCode":"            snapshot.clip_point(range.start, Bias::Left)\n                ..snapshot.clip_point(range.end, Bias::Right)\n        })\n        .collect()\n}\n\nimpl EventEmitter<SearchEvent> for Editor {}\n\nimpl Editor {\n    pub fn update_restoration_data(\n        &self,\n        cx: &mut Context<Self>,\n        write: impl for<'a> FnOnce(&'a mut RestorationData) + 'static,\n    ) {\n        if self.mode.is_minimap() || !WorkspaceSettings::get(None, cx).restore_on_file_reopen {\n            return;\n        }\n\n        let editor = cx.entity();\n        cx.defer(move |cx| {\n            editor.update(cx, |editor, cx| {\n                let kind = Editor::project_item_kind()?;\n                let pane = editor.workspace()?.read(cx).pane_for(&cx.entity())?;\n                let buffer = editor.buffer().read(cx).as_singleton()?;\n                let file_abs_path = project::File::from_dyn(buffer.read(cx).file())?.abs_path(cx);\n                pane.update(cx, |pane, _| {\n                    let data = pane\n                        .project_item_restoration_data\n                        .entry(kind)\n                        .or_insert_with(|| Box::new(EditorRestorationData::default()) as Box<_>);\n                    let data = match data.downcast_mut::<EditorRestorationData>() {\n                        Some(data) => data,\n                        None => {\n                            *data = Box::new(EditorRestorationData::default());\n                            data.downcast_mut::<EditorRestorationData>()\n                                .expect(\"just written the type downcasted to\")\n                        }","sourceCodeStart":1634,"sourceCodeEnd":1670,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/editor/src/items.rs#L1634-L1670","documentation":"A downcast guard in update_restoration_data: pane restoration data is stored per project-item kind as dyn Any, and this code downcasts the stored value back to the editor's expected type. The expect ('just written the type downcasted to') fires if the entry for Editor's item kind holds a different concrete type — i.e. another item kind or a stale/changed restoration struct was stored under the same key.","triggerScenarios":"Thrown at crates/editor/src/items.rs:1644 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use if let Some(data) = entry.downcast_ref::<ExpectedType>() and skip the update when the type mismatches","Key restoration data by (kind, concrete type) or store an enum to make mismatches unrepresentable","Version the restoration struct or migrate old entries when its shape changes"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}