Skip to content

Commit

Permalink
fix: remove AnyItemState in from_iter composable to pass stacked borr…
Browse files Browse the repository at this point in the history
…ows check in miri
  • Loading branch information
matthunz committed Dec 9, 2024
1 parent 5c379e1 commit 2360814
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/compose/from_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use std::marker::PhantomData;
///
/// impl Compose for App {
/// fn compose(cx: Scope<Self>) -> impl Compose {
/// compose::from_fn(|| {
/// dbg!("Composing User");
///
/// compose::from_fn(|_cx| {
/// User { id: 0 }
/// })
/// }
Expand Down
27 changes: 2 additions & 25 deletions src/compose/from_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
C: Compose,
{
fn compose(cx: Scope<Self>) -> impl Compose {
let states: &RefCell<Vec<AnyItemState>> = use_ref(&cx, || RefCell::new(Vec::new()));
let states: &RefCell<Vec<ItemState<Item>>> = use_ref(&cx, || RefCell::new(Vec::new()));
let mut states = states.borrow_mut();

let mut items: Vec<Option<_>> = cx.me().iter.clone().into_iter().map(Some).collect();
Expand All @@ -84,16 +84,7 @@ where
let item = item.take().unwrap();

let state = ItemState { item, key: None };
let boxed = Box::new(state);
let boxed: Box<()> = unsafe { mem::transmute(boxed) };
states.push(AnyItemState {
boxed: Some(boxed),
drop: |any_state| {
let state: Box<ItemState<Item>> =
unsafe { mem::transmute(any_state.boxed.take().unwrap()) };
drop(state);
},
});
states.push(state);
}
} else {
states.truncate(items.len());
Expand All @@ -102,9 +93,6 @@ where
for (idx, state) in states.iter_mut().enumerate() {
let mut nodes = rt.nodes.borrow_mut();

let state: &mut ItemState<Item> =
unsafe { mem::transmute(state.boxed.as_deref_mut().unwrap()) };

if state.key.is_none() {
let item_ref: &Item = &state.item;
let item_ref: &Item = unsafe { mem::transmute(item_ref) };
Expand Down Expand Up @@ -152,14 +140,3 @@ struct ItemState<T> {
item: T,
key: Option<DefaultKey>,
}

struct AnyItemState {
boxed: Option<Box<()>>,
drop: fn(&mut Self),
}

impl Drop for AnyItemState {
fn drop(&mut self) {
(self.drop)(self)
}
}

0 comments on commit 2360814

Please sign in to comment.