zed-industries/zed · error

just written the type downcasted to

Error message

just written the type downcasted to

What it means

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.

Source

Thrown at crates/editor/src/items.rs:1652

            snapshot.clip_point(range.start, Bias::Left)
                ..snapshot.clip_point(range.end, Bias::Right)
        })
        .collect()
}

impl EventEmitter<SearchEvent> for Editor {}

impl Editor {
    pub fn update_restoration_data(
        &self,
        cx: &mut Context<Self>,
        write: impl for<'a> FnOnce(&'a mut RestorationData) + 'static,
    ) {
        if self.mode.is_minimap() || !WorkspaceSettings::get(None, cx).restore_on_file_reopen {
            return;
        }

        let editor = cx.entity();
        cx.defer(move |cx| {
            editor.update(cx, |editor, cx| {
                let kind = Editor::project_item_kind()?;
                let pane = editor.workspace()?.read(cx).pane_for(&cx.entity())?;
                let buffer = editor.buffer().read(cx).as_singleton()?;
                let file_abs_path = project::File::from_dyn(buffer.read(cx).file())?.abs_path(cx);
                pane.update(cx, |pane, _| {
                    let data = pane
                        .project_item_restoration_data
                        .entry(kind)
                        .or_insert_with(|| Box::new(EditorRestorationData::default()) as Box<_>);
                    let data = match data.downcast_mut::<EditorRestorationData>() {
                        Some(data) => data,
                        None => {
                            *data = Box::new(EditorRestorationData::default());
                            data.downcast_mut::<EditorRestorationData>()
                                .expect("just written the type downcasted to")
                        }

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Use if let Some(data) = entry.downcast_ref::<ExpectedType>() and skip the update when the type mismatches
  2. Key restoration data by (kind, concrete type) or store an enum to make mismatches unrepresentable
  3. Version the restoration struct or migrate old entries when its shape changes
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/editor/src/items.rs:1644 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/abb266b258c9b8a9. Report an issue: GitHub.