From b0d2bd20eb40b9cbc2958b981ba2dcd9e6f9396e Mon Sep 17 00:00:00 2001 From: 2ndTaleStudio <43264484+2ndTaleStudio@users.noreply.github.com> Date: Mon, 16 Nov 2020 21:32:29 +0100 Subject: [PATCH] fix soundness --- src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d36df5d..82ce57a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,8 +81,10 @@ pub struct Singleton { // The Singleton need to implement Send & Sync to ensure cross core compile check mechanics // this is safe as the inner RWLock ensures cross core safety -unsafe impl Sync for Singleton {} -unsafe impl Send for Singleton {} +// but we need to be conditional on the inner type to prevent interior mutable types beeing used +// inside a singleton +unsafe impl Sync for Singleton where T: Sync {} +unsafe impl Send for Singleton where T: Send {} impl Singleton { /// Create a new [Singleton] instance to be used in a static variable. Only ``const fn`` constructors are allowed