Skip to content

Commit bfe64e8

Browse files
simonwuelkerarihant2math
authored andcommitted
Fix incorrect documentation and add track_caller to DomRefCell methods (servo#33111)
* Fix DomRefCell documentation about panic behaviour Fixes servo#33099 Signed-off-by: Simon Wülker <[email protected]> * Annotate DomRefCell::borrow/borrow_mut with #[track_caller] Fixes servo#27336 Signed-off-by: Simon Wülker <[email protected]> --------- Signed-off-by: Simon Wülker <[email protected]>
1 parent a34f2ed commit bfe64e8

File tree

1 file changed

+16
-4
lines changed
  • components/script/dom/bindings

1 file changed

+16
-4
lines changed

components/script/dom/bindings/cell.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ impl<T> DomRefCell<T> {
3535
/// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving
3636
/// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by
3737
/// this method is alive is undefined behaviour.
38+
///
39+
/// # Panics
40+
///
41+
/// Panics if this is called from anywhere other than the layout thread
42+
///
43+
/// Panics if the value is currently mutably borrowed.
3844
#[allow(unsafe_code)]
3945
pub unsafe fn borrow_for_layout(&self) -> &T {
4046
assert_in_layout();
@@ -50,6 +56,10 @@ impl<T> DomRefCell<T> {
5056
/// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving
5157
/// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by
5258
/// this method is alive is undefined behaviour.
59+
///
60+
/// # Panics
61+
///
62+
/// Panics if this is called from anywhere other than the script thread.
5363
#[allow(unsafe_code, clippy::mut_from_ref)]
5464
pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T {
5565
assert_in_script();
@@ -64,6 +74,10 @@ impl<T> DomRefCell<T> {
6474
/// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving
6575
/// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by
6676
/// this method is alive is undefined behaviour.
77+
///
78+
/// # Panics
79+
///
80+
/// Panics if this is called from anywhere other than the layout thread.
6781
#[allow(unsafe_code, clippy::mut_from_ref)]
6882
pub unsafe fn borrow_mut_for_layout(&self) -> &mut T {
6983
assert_in_layout();
@@ -88,9 +102,8 @@ impl<T> DomRefCell<T> {
88102
///
89103
/// # Panics
90104
///
91-
/// Panics if this is called off the script thread.
92-
///
93105
/// Panics if the value is currently mutably borrowed.
106+
#[track_caller]
94107
pub fn borrow(&self) -> Ref<T> {
95108
self.value.borrow()
96109
}
@@ -102,9 +115,8 @@ impl<T> DomRefCell<T> {
102115
///
103116
/// # Panics
104117
///
105-
/// Panics if this is called off the script thread.
106-
///
107118
/// Panics if the value is currently borrowed.
119+
#[track_caller]
108120
pub fn borrow_mut(&self) -> RefMut<T> {
109121
self.value.borrow_mut()
110122
}

0 commit comments

Comments
 (0)