From 1dec34eff096ecd4a152c66fca30ba564174dcf0 Mon Sep 17 00:00:00 2001 From: Adoo Date: Mon, 25 Sep 2023 15:35:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=F0=9F=90=9B=20unit=20test=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/pipe.rs | 7 +++++-- dev-helper/src/widget_test.rs | 10 +++++----- widgets/src/lists.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/src/pipe.rs b/core/src/pipe.rs index 2afb38da2..a14c5499d 100644 --- a/core/src/pipe.rs +++ b/core/src/pipe.rs @@ -476,9 +476,12 @@ macro_rules! multi_parent_impl { (p, child) }, move |new_p, old_p, ctx| { - let arena = &ctx.tree.borrow().arena; + // Safety: we escape the borrow of arena, but we only access the children of the + // `old_p` and we know `compose_children` will not modifies the children of + // `old_p`. + let arena = unsafe { &(*ctx.tree.as_ptr()).arena }; let children = old_p.children(arena).map(|id| Widget::from_id(id, ctx)); - new_p.compose_children(children, ctx).consume() + new_p.compose_children(children.into_iter(), ctx).consume() }, ) } else { diff --git a/dev-helper/src/widget_test.rs b/dev-helper/src/widget_test.rs index 20c7fb689..99f70c624 100644 --- a/dev-helper/src/widget_test.rs +++ b/dev-helper/src/widget_test.rs @@ -90,7 +90,7 @@ macro_rules! widget_test_suit { /// use ribir_core::{ prelude::*, test_helper::* }; /// use ribir_dev_helper::*; /// -/// fn my_widget() -> Widget { +/// fn my_widget() -> impl WidgetBuilder { /// fn_widget!{ /// @MockBox { /// size: Size::new(100., 100.), @@ -98,16 +98,16 @@ macro_rules! widget_test_suit { /// size: Size::new(50., 50.) /// } /// } -/// }.into() +/// } /// } /// /// // only use to avoid conflict. -/// fn my_widget_a() -> Widget { my_widget() } +/// fn my_widget_a() -> impl WidgetBuilder { my_widget() } /// /// // Only test the whole widget size. /// widget_layout_test!(my_widget_a, width == 100., height == 100.,); /// -/// fn my_widget_b() -> Widget { my_widget() } +/// fn my_widget_b() -> impl WidgetBuilder { my_widget() } /// // Only test the whole widget size but with a window size. /// widget_layout_test!( /// my_widget_b, @@ -116,7 +116,7 @@ macro_rules! widget_test_suit { /// height == 10., /// ); /// -/// fn my_widget_c() -> Widget { my_widget() } +/// fn my_widget_c() -> impl WidgetBuilder { my_widget() } /// // Test two widget layout information. /// widget_layout_test!( /// my_widget_c, diff --git a/widgets/src/lists.rs b/widgets/src/lists.rs index b578b1b27..69699dfdc 100644 --- a/widgets/src/lists.rs +++ b/widgets/src/lists.rs @@ -63,7 +63,7 @@ use ribir_core::prelude::*; /// @Container { /// size: Size::splat(40.), /// background: Color::YELLOW, -/// }.into() +/// }.widget_build(ctx!()) /// ) /// } /// } @@ -96,7 +96,7 @@ use ribir_core::prelude::*; /// @Container { /// size: Size::splat(40.), /// background: Color::YELLOW, -/// }.into() +/// }.widget_build(ctx!()) /// ) /// } /// }