diff --git a/components/layout/animation.rs b/components/layout/animation.rs index a2a3e1c5459..4e500a3d089 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -68,6 +68,7 @@ pub fn process_new_animations(rw_data: &mut LayoutTaskData, pipeline_id: Pipelin /// Recalculates style for an animation. This does *not* run with the DOM lock held. pub fn recalc_style_for_animation(flow: &mut Flow, animation: &Animation) { + #![allow(unsafe_code)] // #6376 let mut damage = RestyleDamage::empty(); flow.mutate_fragments(&mut |fragment| { if fragment.node.id() != animation.node { @@ -84,7 +85,7 @@ pub fn recalc_style_for_animation(flow: &mut Flow, animation: &Animation) { } let mut new_style = fragment.style.clone(); - animation.property_animation.update(&mut *new_style.make_unique(), progress); + animation.property_animation.update(&mut *unsafe { new_style.make_unique() }, progress); damage.insert(incremental::compute_damage(&Some(fragment.style.clone()), &new_style)); fragment.style = new_style }); diff --git a/components/layout/inline.rs b/components/layout/inline.rs index c5a896bc3c5..028626e803f 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -950,6 +950,7 @@ impl InlineFlow { fn justify_inline_fragments(fragments: &mut InlineFragments, line: &Line, slack_inline_size: Au) { + #![allow(unsafe_code)] // #6376 // Fast path. if slack_inline_size == Au(0) { return @@ -984,9 +985,9 @@ impl InlineFlow { // FIXME(pcwalton): This is an awful lot of uniqueness making. I don't see any easy way // to get rid of it without regressing the performance of the non-justified case, // though. - let run = scanned_text_fragment_info.run.make_unique(); + let run = unsafe { scanned_text_fragment_info.run.make_unique() }; { - let glyph_runs = run.glyphs.make_unique(); + let glyph_runs = unsafe { run.glyphs.make_unique() }; for mut glyph_run in glyph_runs.iter_mut() { let mut range = glyph_run.range.intersect(&fragment_range); if range.is_empty() { @@ -994,7 +995,7 @@ impl InlineFlow { } range.shift_by(-glyph_run.range.begin()); - let glyph_store = glyph_run.glyph_store.make_unique(); + let glyph_store = unsafe { glyph_run.glyph_store.make_unique() }; glyph_store.distribute_extra_space_in_range(&range, space_per_expansion_opportunity); } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 67b8d3e1d25..a8cb3198135 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -627,13 +627,14 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { } fn remove_inline_style_property(self, property: DOMString) { + #![allow(unsafe_code)] // #6376 let mut inline_declarations = self.style_attribute.borrow_mut(); if let &mut Some(ref mut declarations) = &mut *inline_declarations { let index = declarations.normal .iter() .position(|decl| decl.name() == property); if let Some(index) = index { - declarations.normal.make_unique().remove(index); + unsafe { declarations.normal.make_unique().remove(index); } return; } @@ -641,19 +642,20 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { .iter() .position(|decl| decl.name() == property); if let Some(index) = index { - declarations.important.make_unique().remove(index); + unsafe { declarations.important.make_unique().remove(index); } return; } } } fn update_inline_style(self, property_decl: PropertyDeclaration, style_priority: StylePriority) { + #![allow(unsafe_code)] // #6376 let mut inline_declarations = self.style_attribute().borrow_mut(); if let &mut Some(ref mut declarations) = &mut *inline_declarations { let existing_declarations = if style_priority == StylePriority::Important { - declarations.important.make_unique() + unsafe { declarations.important.make_unique() } } else { - declarations.normal.make_unique() + unsafe { declarations.normal.make_unique() } }; for declaration in existing_declarations.iter_mut() { diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 8d271ce846e..3f66a733358 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -4,6 +4,10 @@ // This file is a Mako template: http://www.makotemplates.org/ +// XXXManishearth remove all unsafe blocks when +// https://github.com/rust-lang/rust/issues/24880 is fixed +// See #6376 + use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::default::Default; @@ -5328,7 +5332,7 @@ impl ComputedValues { #[inline] pub fn mutate_${style_struct.name.lower()} <'a>(&'a mut self) -> &'a mut style_structs::${style_struct.name} { - &mut *self.${style_struct.ident}.make_unique() + unsafe{ &mut *self.${style_struct.ident}.make_unique() } } % endfor } @@ -5439,8 +5443,8 @@ fn cascade_with_cached_declarations( .clone() } }; - style_${style_struct.ident}.make_unique() - .${property.ident} = computed_value; + unsafe { style_${style_struct.ident}.make_unique() + .${property.ident} = computed_value; } % endif % if property.name in DERIVED_LONGHANDS: @@ -5450,13 +5454,13 @@ fn cascade_with_cached_declarations( .${property.ident}.clone(); % endif % for derived in DERIVED_LONGHANDS[property.name]: - style_${derived.style_struct.ident} + unsafe { style_${derived.style_struct.ident} .make_unique() .${derived.ident} = longhands::${derived.ident} ::derive_from_${property.ident}( computed_value, - context); + context); } % endfor % endif } @@ -5473,7 +5477,7 @@ fn cascade_with_cached_declarations( if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() || seen.get_font_family() { - compute_font_hash(&mut *style_font.make_unique()) + unsafe { compute_font_hash(&mut *style_font.make_unique()) } } ComputedValues { @@ -5685,18 +5689,18 @@ pub fn cascade(viewport_size: Size2D, .clone() } }; - style_${style_struct.ident}.make_unique() - .${property.ident} = computed_value; + unsafe { style_${style_struct.ident}.make_unique() + .${property.ident} = computed_value; } % if property.name in DERIVED_LONGHANDS: % for derived in DERIVED_LONGHANDS[property.name]: - style_${derived.style_struct.ident} + unsafe { style_${derived.style_struct.ident} .make_unique() .${derived.ident} = longhands::${derived.ident} ::derive_from_${property.ident}( computed_value, - &context); + &context); } % endfor % endif } @@ -5713,7 +5717,7 @@ pub fn cascade(viewport_size: Size2D, // The initial value of border-*-width may be changed at computed value time. { - let border = style_border.make_unique(); + let border = unsafe { style_border.make_unique() }; % for side in ["top", "right", "bottom", "left"]: // Like calling to_computed_value, which wouldn't type check. if !context.border_${side}_present { @@ -5724,7 +5728,7 @@ pub fn cascade(viewport_size: Size2D, // The initial value of display may be changed at computed value time. if !seen.get_display() { - let box_ = style_box_.make_unique(); + let box_ = unsafe { style_box_.make_unique() }; box_.display = box_.display.to_computed_value(&context); } @@ -5734,7 +5738,7 @@ pub fn cascade(viewport_size: Size2D, if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() || seen.get_font_family() { - compute_font_hash(&mut *style_font.make_unique()) + unsafe { compute_font_hash(&mut *style_font.make_unique()) } } (ComputedValues { @@ -5769,7 +5773,7 @@ pub fn cascade_anonymous(parent_style: &ComputedValues) -> ComputedValues { root_font_size: parent_style.root_font_size, }; { - let border = result.border.make_unique(); + let border = unsafe { result.border.make_unique() }; % for side in ["top", "right", "bottom", "left"]: // Like calling to_computed_value, which wouldn't type check. border.border_${side}_width = Au(0); @@ -5789,16 +5793,20 @@ pub fn cascade_anonymous(parent_style: &ComputedValues) -> ComputedValues { pub fn modify_style_for_replaced_content(style: &mut Arc) { // Reset `position` to handle cases like `
foo bar baz
`. if style.box_.display != longhands::display::computed_value::T::inline { - let mut style = style.make_unique(); - style.box_.make_unique().display = longhands::display::computed_value::T::inline; - style.box_.make_unique().position = longhands::position::computed_value::T::static_; + unsafe { + let mut style = style.make_unique(); + style.box_.make_unique().display = longhands::display::computed_value::T::inline; + style.box_.make_unique().position = longhands::position::computed_value::T::static_; + } } // Reset `vertical-align` to handle cases like `foo`. if style.box_.vertical_align != longhands::vertical_align::computed_value::T::baseline { - let mut style = style.make_unique(); - style.box_.make_unique().vertical_align = - longhands::vertical_align::computed_value::T::baseline + unsafe { + let mut style = style.make_unique(); + style.box_.make_unique().vertical_align = + longhands::vertical_align::computed_value::T::baseline + } } // Reset margins. @@ -5806,12 +5814,14 @@ pub fn modify_style_for_replaced_content(style: &mut Arc) { style.margin.margin_left != computed::LengthOrPercentageOrAuto::Length(Au(0)) || style.margin.margin_bottom != computed::LengthOrPercentageOrAuto::Length(Au(0)) || style.margin.margin_right != computed::LengthOrPercentageOrAuto::Length(Au(0)) { - let mut style = style.make_unique(); - let margin = style.margin.make_unique(); - margin.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0)); - margin.margin_left = computed::LengthOrPercentageOrAuto::Length(Au(0)); - margin.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0)); - margin.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0)); + unsafe { + let mut style = style.make_unique(); + let margin = style.margin.make_unique(); + margin.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0)); + margin.margin_left = computed::LengthOrPercentageOrAuto::Length(Au(0)); + margin.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0)); + margin.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0)); + } } } @@ -5825,40 +5835,42 @@ pub fn modify_style_for_inline_sides(style: &mut Arc, is_first_fragment_of_element: bool, is_last_fragment_of_element: bool) { fn modify_side(style: &mut Arc, side: PhysicalSide) { - let mut style = style.make_unique(); - let border = style.border.make_unique(); - match side { - PhysicalSide::Left => { - border.border_left_width = Au(0); - border.border_left_style = BorderStyle::none; - style.padding.make_unique().padding_left = - computed::LengthOrPercentage::Length(Au(0)); - style.margin.make_unique().margin_left = - computed::LengthOrPercentageOrAuto::Length(Au(0)) - } - PhysicalSide::Right => { - border.border_right_width = Au(0); - border.border_right_style = BorderStyle::none; - style.padding.make_unique().padding_right = - computed::LengthOrPercentage::Length(Au(0)); - style.margin.make_unique().margin_right = - computed::LengthOrPercentageOrAuto::Length(Au(0)) - } - PhysicalSide::Bottom => { - border.border_bottom_width = Au(0); - border.border_bottom_style = BorderStyle::none; - style.padding.make_unique().padding_bottom = - computed::LengthOrPercentage::Length(Au(0)); - style.margin.make_unique().margin_bottom = - computed::LengthOrPercentageOrAuto::Length(Au(0)) - } - PhysicalSide::Top => { - border.border_top_width = Au(0); - border.border_top_style = BorderStyle::none; - style.padding.make_unique().padding_top = - computed::LengthOrPercentage::Length(Au(0)); - style.margin.make_unique().margin_top = - computed::LengthOrPercentageOrAuto::Length(Au(0)) + unsafe { + let mut style = style.make_unique(); + let border = style.border.make_unique(); + match side { + PhysicalSide::Left => { + border.border_left_width = Au(0); + border.border_left_style = BorderStyle::none; + style.padding.make_unique().padding_left = + computed::LengthOrPercentage::Length(Au(0)); + style.margin.make_unique().margin_left = + computed::LengthOrPercentageOrAuto::Length(Au(0)) + } + PhysicalSide::Right => { + border.border_right_width = Au(0); + border.border_right_style = BorderStyle::none; + style.padding.make_unique().padding_right = + computed::LengthOrPercentage::Length(Au(0)); + style.margin.make_unique().margin_right = + computed::LengthOrPercentageOrAuto::Length(Au(0)) + } + PhysicalSide::Bottom => { + border.border_bottom_width = Au(0); + border.border_bottom_style = BorderStyle::none; + style.padding.make_unique().padding_bottom = + computed::LengthOrPercentage::Length(Au(0)); + style.margin.make_unique().margin_bottom = + computed::LengthOrPercentageOrAuto::Length(Au(0)) + } + PhysicalSide::Top => { + border.border_top_width = Au(0); + border.border_top_style = BorderStyle::none; + style.padding.make_unique().padding_top = + computed::LengthOrPercentage::Length(Au(0)); + style.margin.make_unique().margin_top = + computed::LengthOrPercentageOrAuto::Length(Au(0)) + } } } }