clippy: Fix warnings in components/shared (#31627)

* clippy: fix warnings in `components/shared`

* fix: formatting derive

* fix: rename new to default
This commit is contained in:
eri 2024-03-12 18:22:05 +01:00 committed by GitHub
parent 4efebf1e62
commit 21939c2ba8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 36 additions and 50 deletions

View file

@ -49,11 +49,11 @@ pub struct StyleData {
pub parallel: DomParallelInfo,
}
impl StyleData {
pub fn new() -> Self {
impl Default for StyleData {
fn default() -> Self {
Self {
element_data: AtomicRefCell::new(ElementData::default()),
parallel: DomParallelInfo::new(),
parallel: DomParallelInfo::default(),
}
}
}
@ -86,20 +86,12 @@ impl StyleAndOpaqueLayoutData {
}
/// Information that we need stored in each DOM node.
#[derive(MallocSizeOf)]
#[derive(Default, MallocSizeOf)]
pub struct DomParallelInfo {
/// The number of children remaining to process during bottom-up traversal.
pub children_to_process: AtomicIsize,
}
impl DomParallelInfo {
pub fn new() -> DomParallelInfo {
DomParallelInfo {
children_to_process: AtomicIsize::new(0),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LayoutNodeType {
Element(LayoutElementType),

View file

@ -199,11 +199,11 @@ pub struct PendingRestyle {
pub damage: RestyleDamage,
}
impl PendingRestyle {
impl Default for PendingRestyle {
/// Creates a new empty pending restyle.
#[inline]
pub fn new() -> Self {
PendingRestyle {
fn default() -> Self {
Self {
snapshot: None,
hint: RestyleHint::empty(),
damage: RestyleDamage::empty(),

View file

@ -50,17 +50,11 @@ impl PseudoElementType {
}
pub fn is_before(&self) -> bool {
match *self {
PseudoElementType::Before => true,
_ => false,
}
matches!(*self, PseudoElementType::Before)
}
pub fn is_replaced_content(&self) -> bool {
match *self {
PseudoElementType::Before | PseudoElementType::After => true,
_ => false,
}
matches!(*self, PseudoElementType::Before | PseudoElementType::After)
}
pub fn style_pseudo_element(&self) -> PseudoElement {
@ -138,9 +132,8 @@ where
ConcreteNode: LayoutNode<'dom>,
{
fn new(root: ConcreteNode) -> TreeIterator<ConcreteNode> {
let mut stack = vec![];
stack.push(root);
TreeIterator { stack: stack }
let stack = vec![root];
TreeIterator { stack }
}
pub fn next_skipping_children(&mut self) -> Option<ConcreteNode> {
@ -155,7 +148,9 @@ where
type Item = ConcreteNode;
fn next(&mut self) -> Option<ConcreteNode> {
let ret = self.stack.pop();
ret.map(|node| self.stack.extend(node.rev_children()));
if let Some(node) = ret {
self.stack.extend(node.rev_children())
}
ret
}
}