From f75561b7b703298b108ebe73ac5218ac1d03675c Mon Sep 17 00:00:00 2001
From: Lyude Paul <lyude@redhat.com>
Date: Wed, 25 Sep 2024 14:21:36 -0400
Subject: [PATCH] WIP: rust: lock: Add B::is_locked() assertion to Guard::new()

TODO: turn this into its own commit in preparation for making Guard::new()
public
---
 rust/kernel/sync/lock.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index 4c3af91924f66..b98c8bc89041e 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -252,6 +252,9 @@ impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> {
         state: B::GuardState,
         _context: B::Context<'a>,
     ) -> Self {
+        // SAFETY: The lock is guaranteed to be initialized by `Lock`'s type invariants
+        debug_assert!(unsafe { B::is_locked(lock.state.get()) });
+
         Self {
             lock,
             state,
-- 
GitLab