mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Remove some uses of unused unsafe.
This commit is contained in:
parent
2efbf2230a
commit
69ddb9501b
10 changed files with 45 additions and 60 deletions
|
@ -488,11 +488,11 @@ impl<E: TElement> SequentialTask<E> {
|
|||
Unused(_) => unreachable!(),
|
||||
#[cfg(feature = "gecko")]
|
||||
UpdateAnimations { el, before_change_style, tasks } => {
|
||||
unsafe { el.update_animations(before_change_style, tasks) };
|
||||
el.update_animations(before_change_style, tasks);
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
PostAnimation { el, tasks } => {
|
||||
unsafe { el.process_post_animation(tasks) };
|
||||
el.process_post_animation(tasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,18 +157,16 @@ impl Device {
|
|||
|
||||
/// Returns the current media type of the device.
|
||||
pub fn media_type(&self) -> MediaType {
|
||||
unsafe {
|
||||
// Gecko allows emulating random media with mIsEmulatingMedia and
|
||||
// mMediaEmulated.
|
||||
let context = self.pres_context();
|
||||
let medium_to_use = if context.mIsEmulatingMedia() != 0 {
|
||||
context.mMediaEmulated.mRawPtr
|
||||
} else {
|
||||
context.mMedium
|
||||
};
|
||||
// Gecko allows emulating random media with mIsEmulatingMedia and
|
||||
// mMediaEmulated.
|
||||
let context = self.pres_context();
|
||||
let medium_to_use = if context.mIsEmulatingMedia() != 0 {
|
||||
context.mMediaEmulated.mRawPtr
|
||||
} else {
|
||||
context.mMedium
|
||||
};
|
||||
|
||||
MediaType(CustomIdent(Atom::from(medium_to_use)))
|
||||
}
|
||||
MediaType(CustomIdent(Atom::from(medium_to_use)))
|
||||
}
|
||||
|
||||
/// Returns the current viewport size in app units.
|
||||
|
|
|
@ -195,13 +195,11 @@ cfg_if! {{
|
|||
'''
|
||||
|
||||
RULE_TEMPLATE = ('("{atom}") =>\n '
|
||||
'{{ '
|
||||
# FIXME(bholley): Uncomment this when rust 1.14 is released.
|
||||
# See the comment in components/style/lib.rs.
|
||||
# ' #[allow(unsafe_code)] #[allow(unused_unsafe)] '
|
||||
'{{{{ '
|
||||
'#[allow(unsafe_code)] #[allow(unused_unsafe)]'
|
||||
'unsafe {{ $crate::string_cache::atom_macro::atom_from_static'
|
||||
'($crate::string_cache::atom_macro::{name} as *mut _) }}'
|
||||
' }};')
|
||||
' }}}};')
|
||||
|
||||
MACRO = '''
|
||||
#[macro_export]
|
||||
|
|
|
@ -37,9 +37,7 @@ impl SnapshotMap {
|
|||
debug_assert!(element.has_snapshot());
|
||||
|
||||
unsafe {
|
||||
let element =
|
||||
unsafe { ::std::mem::transmute::<&E, &GeckoElement>(element) };
|
||||
|
||||
let element = ::std::mem::transmute::<&E, &GeckoElement>(element);
|
||||
bindings::Gecko_GetElementSnapshot(self, element.0).as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -171,8 +169,7 @@ impl ElementSnapshot for GeckoElementSnapshot {
|
|||
}
|
||||
|
||||
let ptr = unsafe {
|
||||
bindings::Gecko_SnapshotAtomAttrValue(self,
|
||||
atom!("id").as_ptr())
|
||||
bindings::Gecko_SnapshotAtomAttrValue(self, atom!("id").as_ptr())
|
||||
};
|
||||
|
||||
if ptr.is_null() {
|
||||
|
|
|
@ -402,7 +402,7 @@ impl<'lb> GeckoXBLBinding<'lb> {
|
|||
}
|
||||
|
||||
fn anon_content(&self) -> *const nsIContent {
|
||||
unsafe { self.0.mContent.raw::<nsIContent>() }
|
||||
self.0.mContent.raw::<nsIContent>()
|
||||
}
|
||||
|
||||
fn inherits_style(&self) -> bool {
|
||||
|
@ -510,8 +510,8 @@ impl<'le> GeckoElement<'le> {
|
|||
unsafe { Gecko_SetNodeFlags(self.as_node().0, flags) }
|
||||
}
|
||||
|
||||
fn unset_flags(&self, flags: u32) {
|
||||
unsafe { Gecko_UnsetNodeFlags(self.as_node().0, flags) }
|
||||
unsafe fn unset_flags(&self, flags: u32) {
|
||||
Gecko_UnsetNodeFlags(self.as_node().0, flags)
|
||||
}
|
||||
|
||||
/// Returns true if this element has descendants for lazy frame construction.
|
||||
|
@ -1224,15 +1224,13 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
|
||||
unsafe fn clear_data(&self) {
|
||||
let ptr = self.0.mServoData.get();
|
||||
unsafe {
|
||||
self.unset_flags(ELEMENT_HAS_SNAPSHOT as u32 |
|
||||
ELEMENT_HANDLED_SNAPSHOT as u32 |
|
||||
structs::Element_kAllServoDescendantBits |
|
||||
NODE_NEEDS_FRAME as u32);
|
||||
}
|
||||
self.unset_flags(ELEMENT_HAS_SNAPSHOT as u32 |
|
||||
ELEMENT_HANDLED_SNAPSHOT as u32 |
|
||||
structs::Element_kAllServoDescendantBits |
|
||||
NODE_NEEDS_FRAME as u32);
|
||||
if !ptr.is_null() {
|
||||
debug!("Dropping ElementData for {:?}", self);
|
||||
let data = unsafe { Box::from_raw(self.0.mServoData.get()) };
|
||||
let data = Box::from_raw(self.0.mServoData.get());
|
||||
self.0.mServoData.set(ptr::null_mut());
|
||||
|
||||
// Perform a mutable borrow of the data in debug builds. This
|
||||
|
|
|
@ -226,9 +226,7 @@ impl nsCSSValue {
|
|||
/// Panics if the unit is not `eCSSUnit_Degree` `eCSSUnit_Grad`, `eCSSUnit_Turn`
|
||||
/// or `eCSSUnit_Radian`.
|
||||
pub fn get_angle(&self) -> Angle {
|
||||
unsafe {
|
||||
Angle::from_gecko_values(self.float_unchecked(), self.mUnit)
|
||||
}
|
||||
Angle::from_gecko_values(self.float_unchecked(), self.mUnit)
|
||||
}
|
||||
|
||||
/// Sets Angle value to this nsCSSValue.
|
||||
|
|
|
@ -99,7 +99,7 @@ impl<T> nsTArray<T> {
|
|||
/// This will not leak since it only works on POD types (and thus doesn't assert)
|
||||
pub unsafe fn set_len_pod(&mut self, len: u32) where T: Copy {
|
||||
self.ensure_capacity(len as usize);
|
||||
let header = unsafe { self.header_mut() };
|
||||
let header = self.header_mut();
|
||||
header.mLength = len;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ impl nsTimingFunction {
|
|||
self.mType = function_type;
|
||||
unsafe {
|
||||
let ref mut gecko_cubic_bezier =
|
||||
unsafe { self.__bindgen_anon_1.mFunc.as_mut() };
|
||||
self.__bindgen_anon_1.mFunc.as_mut();
|
||||
gecko_cubic_bezier.mX1 = x1;
|
||||
gecko_cubic_bezier.mY1 = y1;
|
||||
gecko_cubic_bezier.mX2 = x2;
|
||||
|
|
|
@ -266,9 +266,7 @@ impl Atom {
|
|||
#[inline]
|
||||
pub unsafe fn from_addrefed(ptr: *mut nsAtom) -> Self {
|
||||
assert!(!ptr.is_null());
|
||||
unsafe {
|
||||
Atom(WeakAtom::new(ptr))
|
||||
}
|
||||
Atom(WeakAtom::new(ptr))
|
||||
}
|
||||
|
||||
/// Convert this atom into an addrefed nsAtom pointer.
|
||||
|
|
|
@ -222,7 +222,7 @@ impl ComputedValuesInner {
|
|||
pseudo_ty: structs::CSSPseudoElementType,
|
||||
pseudo_tag: *mut structs::nsAtom
|
||||
) -> Arc<ComputedValues> {
|
||||
let arc = unsafe {
|
||||
let arc = {
|
||||
let arc: Arc<ComputedValues> = Arc::new(uninitialized());
|
||||
bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _,
|
||||
parent, pres_context,
|
||||
|
@ -1215,7 +1215,7 @@ pub fn convert_transform(
|
|||
set_single_transform_function(servo, gecko);
|
||||
}
|
||||
}
|
||||
unsafe { output.set_move(list) };
|
||||
output.set_move(list);
|
||||
}
|
||||
|
||||
fn clone_single_transform_function(
|
||||
|
@ -2280,7 +2280,7 @@ fn static_assert() {
|
|||
gecko.assign_utf8(&*servo);
|
||||
}
|
||||
|
||||
unsafe { self.gecko.mGridTemplateAreas.set_move(refptr.get()) }
|
||||
self.gecko.mGridTemplateAreas.set_move(refptr.get())
|
||||
}
|
||||
|
||||
pub fn copy_grid_template_areas_from(&mut self, other: &Self) {
|
||||
|
@ -2944,7 +2944,7 @@ fn static_assert() {
|
|||
<%def name="impl_copy_animation_or_transition_value(type, ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn copy_${type}_${ident}_from(&mut self, other: &Self) {
|
||||
unsafe { self.gecko.m${type.capitalize()}s.ensure_len(other.gecko.m${type.capitalize()}s.len()) };
|
||||
self.gecko.m${type.capitalize()}s.ensure_len(other.gecko.m${type.capitalize()}s.len());
|
||||
|
||||
let count = other.gecko.m${type.capitalize()}${gecko_ffi_name}Count;
|
||||
self.gecko.m${type.capitalize()}${gecko_ffi_name}Count = count;
|
||||
|
@ -2978,7 +2978,7 @@ fn static_assert() {
|
|||
let v = v.into_iter();
|
||||
debug_assert!(v.len() != 0);
|
||||
let input_len = v.len();
|
||||
unsafe { self.gecko.m${type.capitalize()}s.ensure_len(input_len) };
|
||||
self.gecko.m${type.capitalize()}s.ensure_len(input_len);
|
||||
|
||||
self.gecko.m${type.capitalize()}${gecko_ffi_name}Count = input_len as u32;
|
||||
for (gecko, servo) in self.gecko.m${type.capitalize()}s.iter_mut().zip(v.cycle()) {
|
||||
|
@ -3003,7 +3003,7 @@ fn static_assert() {
|
|||
let v = v.into_iter();
|
||||
debug_assert!(v.len() != 0);
|
||||
let input_len = v.len();
|
||||
unsafe { self.gecko.m${type.capitalize()}s.ensure_len(input_len) };
|
||||
self.gecko.m${type.capitalize()}s.ensure_len(input_len);
|
||||
|
||||
self.gecko.m${type.capitalize()}TimingFunctionCount = input_len as u32;
|
||||
for (gecko, servo) in self.gecko.m${type.capitalize()}s.iter_mut().zip(v.cycle()) {
|
||||
|
@ -3059,7 +3059,7 @@ fn static_assert() {
|
|||
|
||||
debug_assert!(v.len() != 0);
|
||||
let input_len = v.len();
|
||||
unsafe { self.gecko.mAnimations.ensure_len(input_len) };
|
||||
self.gecko.mAnimations.ensure_len(input_len);
|
||||
|
||||
self.gecko.mAnimation${gecko_ffi_name}Count = input_len as u32;
|
||||
|
||||
|
@ -3309,7 +3309,7 @@ fn static_assert() {
|
|||
let v = v.into_iter();
|
||||
|
||||
if v.len() != 0 {
|
||||
unsafe { self.gecko.mTransitions.ensure_len(v.len()) };
|
||||
self.gecko.mTransitions.ensure_len(v.len());
|
||||
self.gecko.mTransitionPropertyCount = v.len() as u32;
|
||||
for (servo, gecko) in v.zip(self.gecko.mTransitions.iter_mut()) {
|
||||
match servo {
|
||||
|
@ -3365,7 +3365,7 @@ fn static_assert() {
|
|||
pub fn copy_transition_property_from(&mut self, other: &Self) {
|
||||
use gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_variable;
|
||||
use gecko_bindings::structs::nsCSSPropertyID::eCSSProperty_UNKNOWN;
|
||||
unsafe { self.gecko.mTransitions.ensure_len(other.gecko.mTransitions.len()) };
|
||||
self.gecko.mTransitions.ensure_len(other.gecko.mTransitions.len());
|
||||
|
||||
let count = other.gecko.mTransitionPropertyCount;
|
||||
self.gecko.mTransitionPropertyCount = count;
|
||||
|
@ -3397,7 +3397,7 @@ fn static_assert() {
|
|||
{
|
||||
let v = v.into_iter();
|
||||
debug_assert!(v.len() != 0);
|
||||
unsafe { self.gecko.mAnimations.ensure_len(v.len()) };
|
||||
self.gecko.mAnimations.ensure_len(v.len());
|
||||
|
||||
self.gecko.mAnimationNameCount = v.len() as u32;
|
||||
for (servo, gecko) in v.zip(self.gecko.mAnimations.iter_mut()) {
|
||||
|
@ -3452,7 +3452,7 @@ fn static_assert() {
|
|||
|
||||
debug_assert_ne!(v.len(), 0);
|
||||
let input_len = v.len();
|
||||
unsafe { self.gecko.mAnimations.ensure_len(input_len) };
|
||||
self.gecko.mAnimations.ensure_len(input_len);
|
||||
|
||||
self.gecko.mAnimationIterationCountCount = input_len as u32;
|
||||
for (gecko, servo) in self.gecko.mAnimations.iter_mut().zip(v.cycle()) {
|
||||
|
@ -4002,11 +4002,9 @@ fn static_assert() {
|
|||
use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
|
||||
unsafe {
|
||||
let count = other.gecko.${image_layers_field}.mImageCount;
|
||||
unsafe {
|
||||
Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
|
||||
count as usize,
|
||||
LayerType::${shorthand.capitalize()});
|
||||
}
|
||||
Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
|
||||
count as usize,
|
||||
LayerType::${shorthand.capitalize()});
|
||||
|
||||
for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
|
||||
.zip(other.gecko.${image_layers_field}.mLayers.iter())
|
||||
|
@ -4204,7 +4202,7 @@ fn static_assert() {
|
|||
gecko.second.assign_utf8(&servo.1);
|
||||
}
|
||||
|
||||
unsafe { self.gecko.mQuotes.set_move(refptr.get()) }
|
||||
self.gecko.mQuotes.set_move(refptr.get())
|
||||
}
|
||||
|
||||
pub fn copy_quotes_from(&mut self, other: &Self) {
|
||||
|
@ -5235,7 +5233,7 @@ clip-path
|
|||
} else if servo.0 == atom!("stroke-opacity") {
|
||||
self.gecko.mContextPropsBits |= structs::NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY as u8;
|
||||
}
|
||||
unsafe { gecko.mRawPtr = servo.0.into_addrefed() }
|
||||
gecko.mRawPtr = servo.0.into_addrefed();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5655,7 +5653,7 @@ clip-path
|
|||
eStyleContentType_Image => {
|
||||
unsafe {
|
||||
let gecko_image_request =
|
||||
unsafe { &**gecko_content.mContent.mImage.as_ref() };
|
||||
&**gecko_content.mContent.mImage.as_ref();
|
||||
ContentItem::Url(
|
||||
SpecifiedUrl::from_image_request(gecko_image_request)
|
||||
.expect("mContent could not convert to SpecifiedUrl")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue