Repository: servo/servo
File: components/layout/formatting_contexts.rs (Rust)

Code before:

    #[inline]
    pub(crate) fn preferred_aspect_ratio(
        &self,
        padding_border_sums: &LogicalVec2<Au>,
    ) -> Option<AspectRatio> {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(replaced, _) => {
                replaced.preferred_aspect_ratio(self.style(), padding_border_sums)
            },
            // TODO: support preferred aspect ratios on non-replaced boxes.
            _ => None,
        }
    }

    pub(crate) fn attached_to_tree(&self, box_: WeakLayoutBox) {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(_, widget) => {
                if let Some(widget) = widget {
                    widget.borrow_mut().base.parent_box.replace(box_);
                }
            },
            IndependentFormattingContextContents::Flow(fc) => fc.attached_to_tree(box_),
            IndependentFormattingContextContents::Flex(fc) => fc.attached_to_tree(box_),
            IndependentFormattingContextContents::Grid(fc) => fc.attached_to_tree(box_),
            IndependentFormattingContextContents::Table(fc) => fc.attached_to_tree(box_),
        }
    }
}

impl ComputeInlineContentSizes for IndependentFormattingContextContents {
    fn compute_inline_content_sizes(
        &self,
        layout_context: &LayoutContext,
        constraint_space: &ConstraintSpace,
    ) -> InlineContentSizesResult {
        match self {
            Self::Replaced(inner, _) => {
                inner.compute_inline_content_sizes(layout_context, constraint_space)
            },
            Self::Flow(inner) => inner
                .contents
                .compute_inline_content_sizes(layout_context, constraint_space),
            Self::Flex(inner) => {
                inner.compute_inline_content_sizes(layout_context, constraint_space)
            },
            Self::Grid(inner) => {
                inner.compute_inline_content_sizes(layout_context, constraint_space)
            },
            Self::Table(inner) => {
                inner.compute_inline_content_sizes(layout_context, constraint_space)

Review comment (suggestion):
```suggestion
            IndependentFormattingContextContents::Flow(contents) => contents.attached_to_tree(box_),
            IndependentFormattingContextContents::Flex(contents) => contents.attached_to_tree(box_),
            IndependentFormattingContextContents::Grid(contents) => contents.attached_to_tree(box_),
            IndependentFormattingContextContents::Table(contents) => contents.attached_to_tree(box_),
```

Code after:

    #[inline]
    pub(crate) fn preferred_aspect_ratio(
        &self,
        padding_border_sums: &LogicalVec2<Au>,
    ) -> Option<AspectRatio> {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(replaced, _) => {
                replaced.preferred_aspect_ratio(self.style(), padding_border_sums)
            },
            // TODO: support preferred aspect ratios on non-replaced boxes.
            _ => None,
        }
    }

    pub(crate) fn attached_to_tree(&self, layout_box: WeakLayoutBox) {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(_, widget) => {
                if let Some(widget) = widget {
                    widget.borrow_mut().base.parent_box.replace(layout_box);
                }
            },
            IndependentFormattingContextContents::Flow(contents) => {
                contents.attached_to_tree(layout_box)
            },
            IndependentFormattingContextContents::Flex(contents) => {
                contents.attached_to_tree(layout_box)
            },
            IndependentFormattingContextContents::Grid(contents) => {
                contents.attached_to_tree(layout_box)
            },
            IndependentFormattingContextContents::Table(contents) => {
                contents.attached_to_tree(layout_box)
            },
        }
    }
}

impl ComputeInlineContentSizes for IndependentFormattingContextContents {
    fn compute_inline_content_sizes(
        &self,
        layout_context: &LayoutContext,
        constraint_space: &ConstraintSpace,
    ) -> InlineContentSizesResult {
        match self {
            Self::Replaced(inner, _) => {
                inner.compute_inline_content_sizes(layout_context, constraint_space)
            },
            Self::Flow(inner) => inner
                .contents
                .compute_inline_content_sizes(layout_context, constraint_space),