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

Code before:
                    anonymous_info,
                    display_inline,
                    Contents::Replaced(contents),
                    anonymous_info.node.box_slot(),
                )
            },
        }
    }
}

impl Contents {
    /// Returns true iff the `try_from` impl below would return `Err(_)`
    pub fn is_replaced(&self) -> bool {
        matches!(self, Contents::Replaced(_))
    }

    pub(crate) fn for_element(
        node: ServoThreadSafeLayoutNode<'_>,
        context: &LayoutContext,
    ) -> Self {
        // If `content` is a single image URL, the box gets replaced with a
        // replaced image.
        if let Content::Items(GenericContentItems { items, .. }) =
            node.style(&context.style_context).clone_content()
        {
            if let [GenericContentItem::Image(img)] = items.as_slice() {
                match ReplacedContents::from_image(node, context, img) {
                    Some(replaced) => return Self::Replaced(replaced),
                    // Invalid images are treated as zero-sized.
                    None => {
                        return Self::Replaced(ReplacedContents::zero_sized_invalid_image(node));
                    },
                }
            }
        }

        if let Some(replaced) = ReplacedContents::for_element(node, context) {
            return Self::Replaced(replaced);
        }
        let is_widget = matches!(
            node.type_id(),
            Some(LayoutNodeType::Element(
                LayoutElementType::HTMLInputElement |
                    LayoutElementType::HTMLSelectElement |
                    LayoutElementType::HTMLTextAreaElement
            ))
        );
        if is_widget {
            Self::Widget(NonReplacedContents::OfElement)
        } else {
            Self::NonReplaced(NonReplacedContents::OfElement)

Review comment (suggestion):
```suggestion
        if let Content::Items(GenericContentItems { items, .. }) =
            node.style(&context.style_context).clone_content()
        {
            if let [GenericContentItem::Image(image)] = items.as_slice() {
```

Code after:
            return Self::Replaced(replaced);
        }
        let is_widget = matches!(
            node.type_id(),
            Some(LayoutNodeType::Element(
                LayoutElementType::HTMLInputElement |
                    LayoutElementType::HTMLSelectElement |
                    LayoutElementType::HTMLTextAreaElement
            ))
        );
        if is_widget {
            Self::Widget(NonReplacedContents::OfElement)
        } else {
            Self::NonReplaced(NonReplacedContents::OfElement)
        }
    }

    pub(crate) fn for_pseudo_element(contents: Vec<PseudoElementContentItem>) -> Self {
        Self::NonReplaced(NonReplacedContents::OfPseudoElement(contents))
    }

    pub(crate) fn non_replaced_contents(self) -> Option<NonReplacedContents> {
        match self {
            Self::NonReplaced(contents) | Self::Widget(contents) => Some(contents),
            Self::Replaced(_) => None,
        }
    }
}

impl NonReplacedContents {
    pub(crate) fn traverse<'dom>(
        self,
        context: &LayoutContext,
        info: &NodeAndStyleInfo<'dom>,
        handler: &mut impl TraversalHandler<'dom>,
    ) {
        match self {
            NonReplacedContents::OfElement => traverse_children_of(info, context, handler),
            NonReplacedContents::OfPseudoElement(items) => {
                traverse_pseudo_element_contents(info, context, handler, items)
            },
        }
    }
}

fn get_quote_from_pair<I, S>(item: &ContentItem<I>, opening: &S, closing: &S) -> String
where
    S: ToString + ?Sized,
{
    match item {
        ContentItem::OpenQuote => opening.to_string(),