mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Fix incorrect documentation and add track_caller
to DomRefCell methods (#33111)
* Fix DomRefCell documentation about panic behaviour Fixes https://github.com/servo/servo/issues/33099 Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Annotate DomRefCell::borrow/borrow_mut with #[track_caller] Fixes https://github.com/servo/servo/issues/27336 Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
3576c02ae2
commit
84b5b64424
1 changed files with 16 additions and 4 deletions
|
@ -35,6 +35,12 @@ impl<T> DomRefCell<T> {
|
||||||
/// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving
|
/// 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
|
/// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by
|
||||||
/// this method is alive is undefined behaviour.
|
/// 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)]
|
#[allow(unsafe_code)]
|
||||||
pub unsafe fn borrow_for_layout(&self) -> &T {
|
pub unsafe fn borrow_for_layout(&self) -> &T {
|
||||||
assert_in_layout();
|
assert_in_layout();
|
||||||
|
@ -50,6 +56,10 @@ impl<T> DomRefCell<T> {
|
||||||
/// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving
|
/// 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
|
/// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by
|
||||||
/// this method is alive is undefined behaviour.
|
/// 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)]
|
#[allow(unsafe_code, clippy::mut_from_ref)]
|
||||||
pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T {
|
pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T {
|
||||||
assert_in_script();
|
assert_in_script();
|
||||||
|
@ -64,6 +74,10 @@ impl<T> DomRefCell<T> {
|
||||||
/// Unlike RefCell::borrow, this method is unsafe because it does not return a Ref, thus leaving
|
/// 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
|
/// the borrow flag untouched. Mutably borrowing the RefCell while the reference returned by
|
||||||
/// this method is alive is undefined behaviour.
|
/// 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)]
|
#[allow(unsafe_code, clippy::mut_from_ref)]
|
||||||
pub unsafe fn borrow_mut_for_layout(&self) -> &mut T {
|
pub unsafe fn borrow_mut_for_layout(&self) -> &mut T {
|
||||||
assert_in_layout();
|
assert_in_layout();
|
||||||
|
@ -88,9 +102,8 @@ impl<T> DomRefCell<T> {
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if this is called off the script thread.
|
|
||||||
///
|
|
||||||
/// Panics if the value is currently mutably borrowed.
|
/// Panics if the value is currently mutably borrowed.
|
||||||
|
#[track_caller]
|
||||||
pub fn borrow(&self) -> Ref<T> {
|
pub fn borrow(&self) -> Ref<T> {
|
||||||
self.value.borrow()
|
self.value.borrow()
|
||||||
}
|
}
|
||||||
|
@ -102,9 +115,8 @@ impl<T> DomRefCell<T> {
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if this is called off the script thread.
|
|
||||||
///
|
|
||||||
/// Panics if the value is currently borrowed.
|
/// Panics if the value is currently borrowed.
|
||||||
|
#[track_caller]
|
||||||
pub fn borrow_mut(&self) -> RefMut<T> {
|
pub fn borrow_mut(&self) -> RefMut<T> {
|
||||||
self.value.borrow_mut()
|
self.value.borrow_mut()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue