mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
script: Wrapping unsafe code in unsafe
blocks for basic DOM types (#37997)
There is a new default cargo clippy lint, `unsafe_op_in_unsafe_fn`, which requires unsafe code to be wrapped in unsafe blocks, even inside functions marked as unsafe. The lint is disabled as much of our code doesn't fulfill this contract. The thing itself is pretty useful in order to gradually remove unsafety, so this change starts adding `unsafe` blocks so we can eventually enable this lint. Testing: This doesn't change behavior so existings tests should suffice. Fixes: This is part of #35955. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
a13cc1b25a
commit
2366a8bf9e
6 changed files with 51 additions and 30 deletions
|
@ -1600,7 +1600,8 @@ where
|
|||
/// returns it.
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) unsafe fn from_untrusted_node_address(candidate: UntrustedNodeAddress) -> DomRoot<Node> {
|
||||
DomRoot::from_ref(Node::from_untrusted_node_address(candidate))
|
||||
let node = unsafe { Node::from_untrusted_node_address(candidate) };
|
||||
DomRoot::from_ref(node)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -1806,7 +1807,7 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn initialize_style_data(self) {
|
||||
let data = self.unsafe_get().style_data.borrow_mut_for_layout();
|
||||
let data = unsafe { self.unsafe_get().style_data.borrow_mut_for_layout() };
|
||||
debug_assert!(data.is_none());
|
||||
*data = Some(Box::default());
|
||||
}
|
||||
|
@ -1814,7 +1815,7 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn initialize_layout_data(self, new_data: Box<GenericLayoutData>) {
|
||||
let data = self.unsafe_get().layout_data.borrow_mut_for_layout();
|
||||
let data = unsafe { self.unsafe_get().layout_data.borrow_mut_for_layout() };
|
||||
debug_assert!(data.is_none());
|
||||
*data = Some(new_data);
|
||||
}
|
||||
|
@ -1822,8 +1823,10 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn clear_style_and_layout_data(self) {
|
||||
self.unsafe_get().style_data.borrow_mut_for_layout().take();
|
||||
self.unsafe_get().layout_data.borrow_mut_for_layout().take();
|
||||
unsafe {
|
||||
self.unsafe_get().style_data.borrow_mut_for_layout().take();
|
||||
self.unsafe_get().layout_data.borrow_mut_for_layout().take();
|
||||
}
|
||||
}
|
||||
|
||||
fn is_text_input(&self) -> bool {
|
||||
|
@ -3054,7 +3057,8 @@ impl Node {
|
|||
if object.is_null() {
|
||||
panic!("Attempted to create a `Node` from an invalid pointer!")
|
||||
}
|
||||
&*(conversions::private_from_object(object) as *const Self)
|
||||
|
||||
unsafe { &*(conversions::private_from_object(object) as *const Self) }
|
||||
}
|
||||
|
||||
pub(crate) fn html_serialize(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue