mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
script: Wrap unsafe code in components/script/bindings
in unsafe {}
(#38544)
Clippy now checks to see if unsafe code is wrapped in unsafe blocks. We have this lint disabled for `script` and `script_bindings` because of a lot of legacy code that doesn't do this. The lint is useful though as it makes it more obvious what code is unsafe. This is an incremental step toward being able to turn this lint on for `script`. This has the benefit of silencing warnings that show up in some IDEs that use rust-analyzer. Testing: This should not change behavior at all and is thus covered by existing tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
fef104cff7
commit
931025c16e
13 changed files with 147 additions and 114 deletions
|
@ -71,7 +71,7 @@ impl<T: DomObject> ToLayout<T> for Dom<T> {
|
|||
unsafe fn to_layout(&self) -> LayoutDom<T> {
|
||||
assert_in_layout();
|
||||
LayoutDom {
|
||||
value: self.as_ptr().as_ref().unwrap(),
|
||||
value: unsafe { self.as_ptr().as_ref().unwrap() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ impl LayoutDom<'_, Node> {
|
|||
assert_in_layout();
|
||||
let TrustedNodeAddress(addr) = inner;
|
||||
LayoutDom {
|
||||
value: &*(addr as *const Node),
|
||||
value: unsafe { &*(addr as *const Node) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ impl<T: DomObject> MutNullableDom<T> {
|
|||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
pub(crate) unsafe fn get_inner_as_layout(&self) -> Option<LayoutDom<T>> {
|
||||
assert_in_layout();
|
||||
(*self.ptr.get()).as_ref().map(|js| js.to_layout())
|
||||
unsafe { (*self.ptr.get()).as_ref().map(|js| js.to_layout()) }
|
||||
}
|
||||
|
||||
/// Get a rooted value out of this object
|
||||
|
@ -385,7 +385,7 @@ impl<T: DomObject> MallocSizeOf for DomOnceCell<T> {
|
|||
unsafe impl<T: DomObject> JSTraceable for DomOnceCell<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
if let Some(ptr) = self.ptr.get() {
|
||||
ptr.trace(trc);
|
||||
unsafe { ptr.trace(trc) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ where
|
|||
// This doesn't compile if Dom and LayoutDom don't have the same
|
||||
// representation.
|
||||
let _ = mem::transmute::<Dom<T>, LayoutDom<T>>;
|
||||
&*(slice as *const [Dom<T>] as *const [LayoutDom<T>])
|
||||
unsafe { &*(slice as *const [Dom<T>] as *const [LayoutDom<T>]) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue