#3488·iced

`keyed::Column` reuses incompatible widget state

Author: JustSimplyKyleCreated Sep 26, 2026Updated Sep 26, 2026
Labelsbug

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

On iced commit 10e9b995eb5af74dbac08ed62b01971fe7e495b2, inserting a stateful Column into a keyed::Column can reuse the state of a stateless Space, causing: Downcast on stateless state

Reproduction

Cargo.toml

toml
[package]
name = "iced-keyed-column-state-panic"
version = "0.1.0"
edition = "2024"

[dependencies]
iced_test = { git = "https://github.com/iced-rs/iced.git", rev = "10e9b995eb5af74dbac08ed62b01971fe7e495b2" }
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "10e9b995eb5af74dbac08ed62b01971fe7e495b2" }

main.rs

rust
use iced_test::Simulator;
use iced_widget::core::Element;
use iced_widget::{column, keyed, Space};

#[derive(Clone, Copy, PartialEq)]
enum Key {
    Top,
    Row,
    Bottom,
}

fn view(show_row: bool) -> Element<'static, (), iced_widget::Theme, iced_widget::Renderer> {
    let mut items = keyed::Column::new()
        .push(Key::Top, Space::new())
        .push(Key::Bottom, Space::new());

    if show_row {
        items = keyed::Column::new()
            .push(Key::Top, Space::new())
            .push(Key::Row, column!["Row"])
            .push(Key::Bottom, Space::new());
    }

    items.into()
}

  fn main() {
      let simulator = Simulator::new(view(false));
      simulator.rebuild(view(true));
  }

What is the expected behavior?

keyed::Column::diff bypasses the widget tag check by calling Widget::diff directly. Changing its reconciliation callback fixes the panic: https://github.com/iced-rs/iced/blob/10e9b995eb5af74dbac08ed62b01971fe7e495b2/widget/src/keyed/column.rs#L207

patch
- |tree, child| child.as_widget_mut().diff(tree),
+ |tree, child| tree.diff(child.as_widget_mut()),

Version

master

Operating System

Linux

Do you have any log output?

bash
thread 'main' panicked at core/src/widget/tree.rs:279:28:
Downcast on stateless state

stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <iced_core::widget::tree::State>::downcast_mut::<iced_core::layout::flex::Cache>
             at core/src/widget/tree.rs:279:28
   3: <iced_widget::column::Column<()> as iced_core::widget::Widget<...>>::layout
             at widget/src/column.rs:203:21
   4: iced_core::layout::flex::resolve
             at core/src/layout/flex.rs:221:9
   5: <iced_widget::keyed::column::Column<...> as iced_core::widget::Widget<...>>::layout
             at widget/src/keyed/column.rs:239:21
   6: iced_runtime::user_interface::UserInterface::build
             at runtime/src/user_interface.rs:103:9
   7: iced_test::simulator::Simulator::rebuild
             at test/src/simulator.rs:140:18
   8: iced_keyed_column_state_panic::main
             at src/main.rs:32:22