From 72841de072c4a904983e9eb631b690a61d3e06ff Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Mon, 5 Dec 2022 16:32:20 -0300 Subject: Use closures for new_with --- tests/ui/no_uaf_1.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'tests/ui/no_uaf_1.rs') diff --git a/tests/ui/no_uaf_1.rs b/tests/ui/no_uaf_1.rs index e4d7ac4..1d9411e 100644 --- a/tests/ui/no_uaf_1.rs +++ b/tests/ui/no_uaf_1.rs @@ -1,7 +1,6 @@ use core::cell::Cell; use selfref::Holder; -use selfref::NewWith; use selfref::opaque; mod bad { @@ -19,16 +18,13 @@ mod bad { } pub fn test() { let rc = Rc::new(Cell::new("")); - struct FooBuilder<'b>(Rc>); - impl<'k, 'b> NewWith<'k, FooOpaque> for FooBuilder<'b> { - fn new_with<'a>(self) -> Foo<'a> where 'k: 'a { - Foo { - x: "Hello".to_owned(), - y: self.0, - } - } - } - let x = Holder::new_with(FooBuilder(rc.clone())); + let rc_clone = rc.clone(); + let x = Holder::<'_, FooOpaque>::new_with(move |builder| { + builder.build(Foo { + x: "Hello".to_owned(), + y: rc_clone, + }); + }); let x = Box::pin(x); x.as_ref().operate_in(|foo| { let foo = foo.get_ref(); -- cgit 1.4.1