summary refs log tree commit diff stats
path: root/tests/ui/no_uaf_1.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/no_uaf_1.rs')
-rw-r--r--tests/ui/no_uaf_1.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/ui/no_uaf_1.rs b/tests/ui/no_uaf_1.rs
new file mode 100644
index 0000000..e4d7ac4
--- /dev/null
+++ b/tests/ui/no_uaf_1.rs
@@ -0,0 +1,44 @@
+use core::cell::Cell;
+
+use selfref::Holder;
+use selfref::NewWith;
+use selfref::opaque;
+
+mod bad {
+    use super::*;
+    use std::rc::Rc;
+    struct Foo<'a> {
+        x: String,
+        y: Rc<Cell<&'a str>>,
+    }
+    struct FooOpaque;
+    opaque! {
+        impl Opaque for FooOpaque {
+            type Kind<'a> = Foo<'a>;
+        }
+    }
+    pub fn test() {
+        let rc = Rc::new(Cell::new(""));
+        struct FooBuilder<'b>(Rc<Cell<&'b str>>);
+        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 x = Box::pin(x);
+        x.as_ref().operate_in(|foo| {
+            let foo = foo.get_ref();
+            foo.y.set(&foo.x);
+        });
+        dbg!(&rc);
+        drop(x);
+        dbg!(&rc);
+    }
+}
+fn main() {
+    bad::test();
+}