From 84b5b6442491560d46807967026bb5ef3a86fcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BClker?= Date: Mon, 19 Aug 2024 09:24:38 +0200 Subject: [PATCH] Fix incorrect documentation and add `track_caller` to DomRefCell methods (#33111) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix DomRefCell documentation about panic behaviour Fixes https://github.com/servo/servo/issues/33099 Signed-off-by: Simon Wülker * Annotate DomRefCell::borrow/borrow_mut with #[track_caller] Fixes https://github.com/servo/servo/issues/27336 Signed-off-by: Simon Wülker --------- Signed-off-by: Simon Wülker --- components/script/dom/bindings/cell.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index bc63d9ecacb..60f3225eee3 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -35,6 +35,12 @@ impl DomRefCell { /// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving /// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by /// this method is alive is undefined behaviour. + /// + /// # Panics + /// + /// Panics if this is called from anywhere other than the layout thread + /// + /// Panics if the value is currently mutably borrowed. #[allow(unsafe_code)] pub unsafe fn borrow_for_layout(&self) -> &T { assert_in_layout(); @@ -50,6 +56,10 @@ impl DomRefCell { /// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving /// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by /// this method is alive is undefined behaviour. + /// + /// # Panics + /// + /// Panics if this is called from anywhere other than the script thread. #[allow(unsafe_code, clippy::mut_from_ref)] pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T { assert_in_script(); @@ -64,6 +74,10 @@ impl DomRefCell { /// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving /// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by /// this method is alive is undefined behaviour. + /// + /// # Panics + /// + /// Panics if this is called from anywhere other than the layout thread. #[allow(unsafe_code, clippy::mut_from_ref)] pub unsafe fn borrow_mut_for_layout(&self) -> &mut T { assert_in_layout(); @@ -88,9 +102,8 @@ impl DomRefCell { /// /// # Panics /// - /// Panics if this is called off the script thread. - /// /// Panics if the value is currently mutably borrowed. + #[track_caller] pub fn borrow(&self) -> Ref { self.value.borrow() } @@ -102,9 +115,8 @@ impl DomRefCell { /// /// # Panics /// - /// Panics if this is called off the script thread. - /// /// Panics if the value is currently borrowed. + #[track_caller] pub fn borrow_mut(&self) -> RefMut { self.value.borrow_mut() }