style: Remove some uses of unused unsafe.

This commit is contained in:
Emilio Cobos Álvarez 2017-11-13 22:37:45 +01:00
parent 2efbf2230a
commit 69ddb9501b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
10 changed files with 45 additions and 60 deletions

View file

@ -488,11 +488,11 @@ impl<E: TElement> SequentialTask<E> {
Unused(_) => unreachable!(), Unused(_) => unreachable!(),
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
UpdateAnimations { el, before_change_style, tasks } => { UpdateAnimations { el, before_change_style, tasks } => {
unsafe { el.update_animations(before_change_style, tasks) }; el.update_animations(before_change_style, tasks);
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
PostAnimation { el, tasks } => { PostAnimation { el, tasks } => {
unsafe { el.process_post_animation(tasks) }; el.process_post_animation(tasks);
} }
} }
} }

View file

@ -157,18 +157,16 @@ impl Device {
/// Returns the current media type of the device. /// Returns the current media type of the device.
pub fn media_type(&self) -> MediaType { pub fn media_type(&self) -> MediaType {
unsafe { // Gecko allows emulating random media with mIsEmulatingMedia and
// Gecko allows emulating random media with mIsEmulatingMedia and // mMediaEmulated.
// mMediaEmulated. let context = self.pres_context();
let context = self.pres_context(); let medium_to_use = if context.mIsEmulatingMedia() != 0 {
let medium_to_use = if context.mIsEmulatingMedia() != 0 { context.mMediaEmulated.mRawPtr
context.mMediaEmulated.mRawPtr } else {
} else { context.mMedium
context.mMedium };
};
MediaType(CustomIdent(Atom::from(medium_to_use))) MediaType(CustomIdent(Atom::from(medium_to_use)))
}
} }
/// Returns the current viewport size in app units. /// Returns the current viewport size in app units.

View file

@ -195,13 +195,11 @@ cfg_if! {{
''' '''
RULE_TEMPLATE = ('("{atom}") =>\n ' RULE_TEMPLATE = ('("{atom}") =>\n '
'{{ ' '{{{{ '
# FIXME(bholley): Uncomment this when rust 1.14 is released. '#[allow(unsafe_code)] #[allow(unused_unsafe)]'
# See the comment in components/style/lib.rs.
# ' #[allow(unsafe_code)] #[allow(unused_unsafe)] '
'unsafe {{ $crate::string_cache::atom_macro::atom_from_static' 'unsafe {{ $crate::string_cache::atom_macro::atom_from_static'
'($crate::string_cache::atom_macro::{name} as *mut _) }}' '($crate::string_cache::atom_macro::{name} as *mut _) }}'
' }};') ' }}}};')
MACRO = ''' MACRO = '''
#[macro_export] #[macro_export]

View file

@ -37,9 +37,7 @@ impl SnapshotMap {
debug_assert!(element.has_snapshot()); debug_assert!(element.has_snapshot());
unsafe { unsafe {
let element = let element = ::std::mem::transmute::<&E, &GeckoElement>(element);
unsafe { ::std::mem::transmute::<&E, &GeckoElement>(element) };
bindings::Gecko_GetElementSnapshot(self, element.0).as_ref() bindings::Gecko_GetElementSnapshot(self, element.0).as_ref()
} }
} }
@ -171,8 +169,7 @@ impl ElementSnapshot for GeckoElementSnapshot {
} }
let ptr = unsafe { let ptr = unsafe {
bindings::Gecko_SnapshotAtomAttrValue(self, bindings::Gecko_SnapshotAtomAttrValue(self, atom!("id").as_ptr())
atom!("id").as_ptr())
}; };
if ptr.is_null() { if ptr.is_null() {

View file

@ -402,7 +402,7 @@ impl<'lb> GeckoXBLBinding<'lb> {
} }
fn anon_content(&self) -> *const nsIContent { fn anon_content(&self) -> *const nsIContent {
unsafe { self.0.mContent.raw::<nsIContent>() } self.0.mContent.raw::<nsIContent>()
} }
fn inherits_style(&self) -> bool { fn inherits_style(&self) -> bool {
@ -510,8 +510,8 @@ impl<'le> GeckoElement<'le> {
unsafe { Gecko_SetNodeFlags(self.as_node().0, flags) } unsafe { Gecko_SetNodeFlags(self.as_node().0, flags) }
} }
fn unset_flags(&self, flags: u32) { unsafe fn unset_flags(&self, flags: u32) {
unsafe { Gecko_UnsetNodeFlags(self.as_node().0, flags) } Gecko_UnsetNodeFlags(self.as_node().0, flags)
} }
/// Returns true if this element has descendants for lazy frame construction. /// 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) { unsafe fn clear_data(&self) {
let ptr = self.0.mServoData.get(); let ptr = self.0.mServoData.get();
unsafe { self.unset_flags(ELEMENT_HAS_SNAPSHOT as u32 |
self.unset_flags(ELEMENT_HAS_SNAPSHOT as u32 | ELEMENT_HANDLED_SNAPSHOT as u32 |
ELEMENT_HANDLED_SNAPSHOT as u32 | structs::Element_kAllServoDescendantBits |
structs::Element_kAllServoDescendantBits | NODE_NEEDS_FRAME as u32);
NODE_NEEDS_FRAME as u32);
}
if !ptr.is_null() { if !ptr.is_null() {
debug!("Dropping ElementData for {:?}", self); 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()); self.0.mServoData.set(ptr::null_mut());
// Perform a mutable borrow of the data in debug builds. This // Perform a mutable borrow of the data in debug builds. This

View file

@ -226,9 +226,7 @@ impl nsCSSValue {
/// Panics if the unit is not `eCSSUnit_Degree` `eCSSUnit_Grad`, `eCSSUnit_Turn` /// Panics if the unit is not `eCSSUnit_Degree` `eCSSUnit_Grad`, `eCSSUnit_Turn`
/// or `eCSSUnit_Radian`. /// or `eCSSUnit_Radian`.
pub fn get_angle(&self) -> Angle { 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. /// Sets Angle value to this nsCSSValue.

View file

@ -99,7 +99,7 @@ impl<T> nsTArray<T> {
/// This will not leak since it only works on POD types (and thus doesn't assert) /// 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 { pub unsafe fn set_len_pod(&mut self, len: u32) where T: Copy {
self.ensure_capacity(len as usize); self.ensure_capacity(len as usize);
let header = unsafe { self.header_mut() }; let header = self.header_mut();
header.mLength = len; header.mLength = len;
} }
} }

View file

@ -35,7 +35,7 @@ impl nsTimingFunction {
self.mType = function_type; self.mType = function_type;
unsafe { unsafe {
let ref mut gecko_cubic_bezier = 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.mX1 = x1;
gecko_cubic_bezier.mY1 = y1; gecko_cubic_bezier.mY1 = y1;
gecko_cubic_bezier.mX2 = x2; gecko_cubic_bezier.mX2 = x2;

View file

@ -266,9 +266,7 @@ impl Atom {
#[inline] #[inline]
pub unsafe fn from_addrefed(ptr: *mut nsAtom) -> Self { pub unsafe fn from_addrefed(ptr: *mut nsAtom) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
unsafe { Atom(WeakAtom::new(ptr))
Atom(WeakAtom::new(ptr))
}
} }
/// Convert this atom into an addrefed nsAtom pointer. /// Convert this atom into an addrefed nsAtom pointer.

View file

@ -222,7 +222,7 @@ impl ComputedValuesInner {
pseudo_ty: structs::CSSPseudoElementType, pseudo_ty: structs::CSSPseudoElementType,
pseudo_tag: *mut structs::nsAtom pseudo_tag: *mut structs::nsAtom
) -> Arc<ComputedValues> { ) -> Arc<ComputedValues> {
let arc = unsafe { let arc = {
let arc: Arc<ComputedValues> = Arc::new(uninitialized()); let arc: Arc<ComputedValues> = Arc::new(uninitialized());
bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _, bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _,
parent, pres_context, parent, pres_context,
@ -1215,7 +1215,7 @@ pub fn convert_transform(
set_single_transform_function(servo, gecko); set_single_transform_function(servo, gecko);
} }
} }
unsafe { output.set_move(list) }; output.set_move(list);
} }
fn clone_single_transform_function( fn clone_single_transform_function(
@ -2280,7 +2280,7 @@ fn static_assert() {
gecko.assign_utf8(&*servo); 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) { 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)"> <%def name="impl_copy_animation_or_transition_value(type, ident, gecko_ffi_name)">
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn copy_${type}_${ident}_from(&mut self, other: &Self) { 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; let count = other.gecko.m${type.capitalize()}${gecko_ffi_name}Count;
self.gecko.m${type.capitalize()}${gecko_ffi_name}Count = count; self.gecko.m${type.capitalize()}${gecko_ffi_name}Count = count;
@ -2978,7 +2978,7 @@ fn static_assert() {
let v = v.into_iter(); let v = v.into_iter();
debug_assert!(v.len() != 0); debug_assert!(v.len() != 0);
let input_len = v.len(); 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; 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()) { 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(); let v = v.into_iter();
debug_assert!(v.len() != 0); debug_assert!(v.len() != 0);
let input_len = v.len(); 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; 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()) { 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); debug_assert!(v.len() != 0);
let input_len = v.len(); 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; self.gecko.mAnimation${gecko_ffi_name}Count = input_len as u32;
@ -3309,7 +3309,7 @@ fn static_assert() {
let v = v.into_iter(); let v = v.into_iter();
if v.len() != 0 { 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; self.gecko.mTransitionPropertyCount = v.len() as u32;
for (servo, gecko) in v.zip(self.gecko.mTransitions.iter_mut()) { for (servo, gecko) in v.zip(self.gecko.mTransitions.iter_mut()) {
match servo { match servo {
@ -3365,7 +3365,7 @@ fn static_assert() {
pub fn copy_transition_property_from(&mut self, other: &Self) { pub fn copy_transition_property_from(&mut self, other: &Self) {
use gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_variable; use gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_variable;
use gecko_bindings::structs::nsCSSPropertyID::eCSSProperty_UNKNOWN; 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; let count = other.gecko.mTransitionPropertyCount;
self.gecko.mTransitionPropertyCount = count; self.gecko.mTransitionPropertyCount = count;
@ -3397,7 +3397,7 @@ fn static_assert() {
{ {
let v = v.into_iter(); let v = v.into_iter();
debug_assert!(v.len() != 0); 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; self.gecko.mAnimationNameCount = v.len() as u32;
for (servo, gecko) in v.zip(self.gecko.mAnimations.iter_mut()) { for (servo, gecko) in v.zip(self.gecko.mAnimations.iter_mut()) {
@ -3452,7 +3452,7 @@ fn static_assert() {
debug_assert_ne!(v.len(), 0); debug_assert_ne!(v.len(), 0);
let input_len = v.len(); 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; self.gecko.mAnimationIterationCountCount = input_len as u32;
for (gecko, servo) in self.gecko.mAnimations.iter_mut().zip(v.cycle()) { 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; use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
unsafe { unsafe {
let count = other.gecko.${image_layers_field}.mImageCount; let count = other.gecko.${image_layers_field}.mImageCount;
unsafe { Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, count as usize,
count as usize, LayerType::${shorthand.capitalize()});
LayerType::${shorthand.capitalize()});
}
for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut() for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
.zip(other.gecko.${image_layers_field}.mLayers.iter()) .zip(other.gecko.${image_layers_field}.mLayers.iter())
@ -4204,7 +4202,7 @@ fn static_assert() {
gecko.second.assign_utf8(&servo.1); 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) { pub fn copy_quotes_from(&mut self, other: &Self) {
@ -5235,7 +5233,7 @@ clip-path
} else if servo.0 == atom!("stroke-opacity") { } else if servo.0 == atom!("stroke-opacity") {
self.gecko.mContextPropsBits |= structs::NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY as u8; 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 => { eStyleContentType_Image => {
unsafe { unsafe {
let gecko_image_request = let gecko_image_request =
unsafe { &**gecko_content.mContent.mImage.as_ref() }; &**gecko_content.mContent.mImage.as_ref();
ContentItem::Url( ContentItem::Url(
SpecifiedUrl::from_image_request(gecko_image_request) SpecifiedUrl::from_image_request(gecko_image_request)
.expect("mContent could not convert to SpecifiedUrl") .expect("mContent could not convert to SpecifiedUrl")