()
| 45 | |
| 46 | #[test] |
| 47 | fn drop_func() -> Result<()> { |
| 48 | static HITS: AtomicUsize = AtomicUsize::new(0); |
| 49 | struct A; |
| 50 | |
| 51 | impl Drop for A { |
| 52 | fn drop(&mut self) { |
| 53 | HITS.fetch_add(1, SeqCst); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | let engine = Engine::default(); |
| 58 | let mut linker = Linker::<()>::new(&engine); |
| 59 | linker.allow_shadowing(true); |
| 60 | |
| 61 | let a = A; |
| 62 | linker.func_wrap("", "", move || { |
| 63 | let _ = &a; |
| 64 | })?; |
| 65 | |
| 66 | assert_eq!(HITS.load(SeqCst), 0); |
| 67 | |
| 68 | // Define the function again to ensure redefined functions are dropped |
| 69 | |
| 70 | let a = A; |
| 71 | linker.func_wrap("", "", move || { |
| 72 | let _ = &a; |
| 73 | })?; |
| 74 | |
| 75 | assert_eq!(HITS.load(SeqCst), 1); |
| 76 | |
| 77 | drop(linker); |
| 78 | |
| 79 | assert_eq!(HITS.load(SeqCst), 2); |
| 80 | |
| 81 | Ok(()) |
| 82 | } |
| 83 | |
| 84 | #[test] |
| 85 | #[cfg_attr(miri, ignore)] |
nothing calls this directly
no test coverage detected