Skip to content

Commit

Permalink
Auto merge of #19199 - emilio:no-unused-unsafe, r=nox
Browse files Browse the repository at this point in the history
style: Stop allowing unused_unsafe.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19199)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 15, 2017
2 parents d117694 + f0d749a commit 40adc3f
Show file tree
Hide file tree
Showing 13 changed files with 2,634 additions and 2,660 deletions.
4 changes: 2 additions & 2 deletions components/style/context.rs
Expand Up @@ -471,11 +471,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);
}
}
}
Expand Down
5,176 changes: 2,588 additions & 2,588 deletions components/style/gecko/generated/atom_macro.rs

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions components/style/gecko/media_queries.rs
Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions components/style/gecko/regen_atoms.py
Expand Up @@ -195,13 +195,11 @@ def __exit__(self, type, value, traceback):
'''

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]
Expand Down
7 changes: 2 additions & 5 deletions components/style/gecko/snapshot.rs
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 8 additions & 10 deletions components/style/gecko/wrapper.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions components/style/gecko_bindings/sugar/ns_css_value.rs
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion components/style/gecko_bindings/sugar/ns_t_array.rs
Expand Up @@ -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;
}
}
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions components/style/gecko_string_cache/mod.rs
Expand Up @@ -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.
Expand Down
9 changes: 0 additions & 9 deletions components/style/lib.rs
Expand Up @@ -26,15 +26,6 @@
#![deny(warnings)]
#![deny(missing_docs)]

// FIXME(bholley): We need to blanket-allow unsafe code in order to make the
// gecko atom!() macro work. When Rust 1.14 is released [1], we can uncomment
// the commented-out attributes in regen_atoms.py and go back to denying unsafe
// code by default.
//
// [1] https://github.com/rust-lang/rust/issues/15701#issuecomment-251900615
//#![deny(unsafe_code)]
#![allow(unused_unsafe)]

#![recursion_limit = "500"] // For define_css_keyword_enum! in -moz-appearance

extern crate app_units;
Expand Down
36 changes: 17 additions & 19 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions components/style/rule_tree/mod.rs
Expand Up @@ -590,9 +590,7 @@ impl PrevSiblingOrFreeCount {
}

unsafe fn as_free_count(&self) -> &AtomicUsize {
unsafe {
mem::transmute(&self.0)
}
mem::transmute(&self.0)
}
}

Expand Down

0 comments on commit 40adc3f

Please sign in to comment.