Repository: servo/servo
File: components/layout/flow/inline/mod.rs (Rust)

Code before:
                })
            },
            InlineItem::OutOfFlowAbsolutelyPositionedBox(..) => true,
            InlineItem::OutOfFlowFloatBox(..) => true,
            InlineItem::Atomic(..) => false,
            InlineItem::AnonymousBlock(block_box) => block_box
                .borrow()
                .contents
                .find_block_margin_collapsing_with_parent(
                    layout_context,
                    collected_margin,
                    containing_block_for_children,
                ),
        })
    }

    pub(crate) fn attached_to_tree(&self, box_: WeakLayoutBox) {
        let mut parent_box_stack = vec![box_];
        for inline_item in &self.inline_items {
            match inline_item {
                InlineItem::StartInlineBox(inline_box) => {
                    inline_box
                        .borrow_mut()
                        .base
                        .parent_box
                        .replace(parent_box_stack.last().unwrap().clone());
                    parent_box_stack.push(WeakLayoutBox::InlineLevel(
                        WeakInlineItem::StartInlineBox(inline_box.downgrade()),
                    ));
                },
                InlineItem::EndInlineBox => {
                    parent_box_stack.pop();
                },
                InlineItem::TextRun(text_run) => {
                    text_run
                        .borrow_mut()
                        .parent_box
                        .replace(parent_box_stack.last().unwrap().clone().clone());
                },
                _ => inline_item.with_base_mut(|base| {
                    base.parent_box
                        .replace(parent_box_stack.last().unwrap().clone());
                }),
            }
        }
    }
}

impl InlineContainerState {
    fn new(
        style: ServoArc<ComputedValues>,

Review comment (suggestion):
```suggestion
                        .replace(current_layout_box());
```

Code after:
                            )
                    })
                })
            },
            InlineItem::OutOfFlowAbsolutelyPositionedBox(..) => true,
            InlineItem::OutOfFlowFloatBox(..) => true,
            InlineItem::Atomic(..) => false,
            InlineItem::AnonymousBlock(block_box) => block_box
                .borrow()
                .contents
                .find_block_margin_collapsing_with_parent(
                    layout_context,
                    collected_margin,
                    containing_block_for_children,
                ),
        })
    }

    pub(crate) fn attached_to_tree(&self, layout_box: WeakLayoutBox) {
        let mut parent_box_stack = Vec::new();
        let current_parent_box = |parent_box_stack: &[WeakLayoutBox]| {
            parent_box_stack.last().unwrap_or(&layout_box).clone()
        };
        for inline_item in &self.inline_items {
            match inline_item {
                InlineItem::StartInlineBox(inline_box) => {
                    inline_box
                        .borrow_mut()
                        .base
                        .parent_box
                        .replace(current_parent_box(&parent_box_stack));
                    parent_box_stack.push(WeakLayoutBox::InlineLevel(
                        WeakInlineItem::StartInlineBox(inline_box.downgrade()),
                    ));
                },
                InlineItem::EndInlineBox => {
                    parent_box_stack.pop();
                },
                InlineItem::TextRun(text_run) => {
                    text_run
                        .borrow_mut()
                        .parent_box
                        .replace(current_parent_box(&parent_box_stack));
                },
                _ => inline_item.with_base_mut(|base| {
                    base.parent_box
                        .replace(current_parent_box(&parent_box_stack));
                }),
            }
        }
    }