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 let Some(replaced) = ReplacedContents::for_element(node, context) {
            if let Some(element) = node.as_element() {
                if let Some(shadow_root) = element.shadow_root() {
                    if shadow_root.is_ua_widget() {
                        let non_replaced_contents = NonReplacedContents::OfElement;
                        return Self::ReplacedWithWidget(replaced, non_replaced_contents);
                    }
                }
            }
            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> {

Review comment (suggestion):
As suggestion to combine into 1 line (naming of `NonReplacedContents` is enougth to understand what it is)
` return Self::ReplacedWithWidget(replaced, NonReplacedContents::OfElement);`

Code after:
                    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 let Some(replaced) = ReplacedContents::for_element(node, context) {
            if let Some(element) = node.as_element() {
                if let Some(shadow_root) = element.shadow_root() {
                    if shadow_root.is_ua_widget() {
                        return Self::ReplacedWithWidget(replaced, NonReplacedContents::OfElement);
                    }
                }
            }
            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) |