aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreri <eri@inventati.org>2024-03-11 15:24:33 +0100
committerGitHub <noreply@github.com>2024-03-11 14:24:33 +0000
commitb03411f56771dfb45ec4c8a3d9888caac65abaf9 (patch)
treea721801581950ca871062a7508019b9bfe6e793c
parent1d1f239ecc8bccef7869425f1fb4925fecf0e2c1 (diff)
downloadservo-b03411f56771dfb45ec4c8a3d9888caac65abaf9.tar.gz
servo-b03411f56771dfb45ec4c8a3d9888caac65abaf9.zip
clippy: Fix warnings in `components/layout_2020` (#31611)
* clippy: fix warnings in components/layout_2020 * fix: review comments
-rw-r--r--components/layout_2020/display_list/stacking_context.rs8
-rw-r--r--components/layout_2020/flexbox/layout.rs2
-rw-r--r--components/layout_2020/flow/construct.rs16
-rw-r--r--components/layout_2020/flow/float.rs2
-rw-r--r--components/layout_2020/flow/inline.rs38
-rw-r--r--components/layout_2020/flow/line.rs8
-rw-r--r--components/layout_2020/flow/mod.rs9
-rw-r--r--components/layout_2020/flow/root.rs1
-rw-r--r--components/layout_2020/flow/text_run.rs2
-rw-r--r--components/layout_2020/fragment_tree/base_fragment.rs2
-rw-r--r--components/layout_2020/fragment_tree/box_fragment.rs2
-rw-r--r--components/layout_2020/fragment_tree/hoisted_shared_fragment.rs10
-rw-r--r--components/layout_2020/fragment_tree/mod.rs1
-rw-r--r--components/layout_2020/query.rs9
-rw-r--r--components/layout_2020/style_ext.rs1
-rw-r--r--components/layout_2020/table/construct.rs4
-rw-r--r--components/layout_2020/table/layout.rs13
17 files changed, 59 insertions, 69 deletions
diff --git a/components/layout_2020/display_list/stacking_context.rs b/components/layout_2020/display_list/stacking_context.rs
index 47819d0bd10..68be4cc312b 100644
--- a/components/layout_2020/display_list/stacking_context.rs
+++ b/components/layout_2020/display_list/stacking_context.rs
@@ -430,11 +430,11 @@ impl StackingContext {
debug_assert!(self
.real_stacking_contexts_and_positioned_stacking_containers
.iter()
- .all(|c| match c.context_type {
+ .all(|c| matches!(
+ c.context_type,
StackingContextType::RealStackingContext |
- StackingContextType::PositionedStackingContainer => true,
- _ => false,
- }));
+ StackingContextType::PositionedStackingContainer
+ )));
debug_assert!(self
.float_stacking_containers
.iter()
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index c379dc451fc..5041c707709 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -1109,7 +1109,7 @@ impl<'a> FlexItem<'a> {
flex_context.layout_context,
&mut positioning_context,
&item_as_containing_block,
- &flex_context.containing_block,
+ flex_context.containing_block,
);
let hypothetical_cross_size = self
diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs
index cd2dfffc4d0..78ac76d2c6a 100644
--- a/components/layout_2020/flow/construct.rs
+++ b/components/layout_2020/flow/construct.rs
@@ -54,7 +54,7 @@ impl BlockFormattingContext {
}
}
- pub fn construct_for_text_runs<'dom>(
+ pub fn construct_for_text_runs(
runs: impl Iterator<Item = TextRun>,
layout_context: &LayoutContext,
text_decoration_line: TextDecorationLine,
@@ -409,15 +409,11 @@ where
// collecting all Cow strings into a vector and passing them along to text breaking
// and shaping during final InlineFormattingContext construction.
let inlines = self.current_inline_level_boxes();
- match inlines.last_mut().map(|last| last.borrow_mut()) {
- Some(mut last_box) => match *last_box {
- InlineLevelBox::TextRun(ref mut text_run) => {
- text_run.text.push_str(&input);
- return;
- },
- _ => {},
- },
- _ => {},
+ if let Some(mut last_box) = inlines.last_mut().map(|last| last.borrow_mut()) {
+ if let InlineLevelBox::TextRun(ref mut text_run) = *last_box {
+ text_run.text.push_str(&input);
+ return;
+ }
}
inlines.push(ArcRefCell::new(InlineLevelBox::TextRun(TextRun::new(
diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs
index fa40ae1bb22..739b3503a67 100644
--- a/components/layout_2020/flow/float.rs
+++ b/components/layout_2020/flow/float.rs
@@ -951,7 +951,7 @@ impl FloatBox {
layout_context,
positioning_context,
&containing_block_for_children,
- &containing_block,
+ containing_block,
);
content_size = LogicalVec2 {
inline: inline_size,
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs
index 6bf88502d4a..c30e01c59da 100644
--- a/components/layout_2020/flow/inline.rs
+++ b/components/layout_2020/flow/inline.rs
@@ -1384,14 +1384,11 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
// Place all floats in this unbreakable segment.
let mut segment_items = mem::take(&mut self.current_line_segment.line_items);
for item in segment_items.iter_mut() {
- match item {
- LineItem::Float(float_item) => {
- self.place_float_line_item_for_commit_to_line(
- float_item,
- line_inline_size_without_trailing_whitespace,
- );
- },
- _ => {},
+ if let LineItem::Float(float_item) = item {
+ self.place_float_line_item_for_commit_to_line(
+ float_item,
+ line_inline_size_without_trailing_whitespace,
+ );
}
}
@@ -1450,7 +1447,7 @@ impl InlineFormattingContext {
}
}
- fn foreach<'a>(&self, mut func: impl FnMut(InlineFormattingContextIterItem)) {
+ fn foreach(&self, mut func: impl FnMut(InlineFormattingContextIterItem)) {
// TODO(mrobinson): Using OwnedRef here we could maybe avoid the second borrow when
// iterating through members of each inline box.
struct InlineFormattingContextChildBoxIter {
@@ -2006,7 +2003,7 @@ impl IndependentFormattingContext {
layout_context,
child_positioning_context.as_mut().unwrap(),
&containing_block_for_children,
- &ifc.containing_block,
+ ifc.containing_block,
);
let (inline_size, block_size) =
match independent_layout.content_inline_size_for_table {
@@ -2134,15 +2131,12 @@ impl FloatBox {
}
}
-fn place_pending_floats(ifc: &mut InlineFormattingContextState, line_items: &mut Vec<LineItem>) {
+fn place_pending_floats(ifc: &mut InlineFormattingContextState, line_items: &mut [LineItem]) {
for item in line_items.iter_mut() {
- match item {
- LineItem::Float(float_line_item) => {
- if float_line_item.needs_placement {
- ifc.place_float_fragment(&mut float_line_item.fragment);
- }
- },
- _ => {},
+ if let LineItem::Float(float_line_item) = item {
+ if float_line_item.needs_placement {
+ ifc.place_float_fragment(&mut float_line_item.fragment);
+ }
}
}
}
@@ -2157,11 +2151,11 @@ fn line_height(parent_style: &ComputedValues, font_metrics: &FontMetrics) -> Len
}
fn is_baseline_relative(vertical_align: GenericVerticalAlign<LengthPercentage>) -> bool {
- match vertical_align {
+ !matches!(
+ vertical_align,
GenericVerticalAlign::Keyword(VerticalAlignKeyword::Top) |
- GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => false,
- _ => true,
- }
+ GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom)
+ )
}
/// Whether or not a strut should be created for an inline container. Normally
diff --git a/components/layout_2020/flow/line.rs b/components/layout_2020/flow/line.rs
index dce1d304fa9..1e2317b70d3 100644
--- a/components/layout_2020/flow/line.rs
+++ b/components/layout_2020/flow/line.rs
@@ -587,11 +587,11 @@ impl FloatLineItem {
}
fn is_baseline_relative(vertical_align: GenericVerticalAlign<LengthPercentage>) -> bool {
- match vertical_align {
+ !matches!(
+ vertical_align,
GenericVerticalAlign::Keyword(VerticalAlignKeyword::Top) |
- GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => false,
- _ => true,
- }
+ GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom)
+ )
}
fn line_height(parent_style: &ComputedValues, font_metrics: &FontMetrics) -> Length {
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index d118f040c00..4ebaf01946d 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -613,6 +613,7 @@ impl BlockLevelBox {
///
/// - <https://drafts.csswg.org/css2/visudet.html#blockwidth>
/// - <https://drafts.csswg.org/css2/visudet.html#normal-block>
+#[allow(clippy::too_many_arguments)]
fn layout_in_flow_non_replaced_block_level_same_formatting_context(
layout_context: &LayoutContext,
positioning_context: &mut PositioningContext,
@@ -856,7 +857,7 @@ impl NonReplacedFormattingContext {
layout_context,
positioning_context,
&containing_block_for_children,
- &containing_block,
+ containing_block,
);
let (block_size, inline_size) = match layout.content_inline_size_for_table {
@@ -1162,7 +1163,7 @@ impl NonReplacedFormattingContext {
/// <https://drafts.csswg.org/css2/visudet.html#block-replaced-width>
/// <https://drafts.csswg.org/css2/visudet.html#inline-replaced-width>
/// <https://drafts.csswg.org/css2/visudet.html#inline-replaced-height>
-fn layout_in_flow_replaced_block_level<'a>(
+fn layout_in_flow_replaced_block_level(
containing_block: &ContainingBlock,
base_fragment_info: BaseFragmentInfo,
style: &Arc<ComputedValues>,
@@ -1348,8 +1349,8 @@ fn solve_margins(
inline_size: Length,
) -> ResolvedMargins {
let (inline_margins, effective_margin_inline_start) =
- solve_inline_margins_for_in_flow_block_level(containing_block, &pbm, inline_size);
- let block_margins = solve_block_margins_for_in_flow_block_level(&pbm);
+ solve_inline_margins_for_in_flow_block_level(containing_block, pbm, inline_size);
+ let block_margins = solve_block_margins_for_in_flow_block_level(pbm);
ResolvedMargins {
margin: LogicalSides {
inline_start: inline_margins.0,
diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs
index cd2ab4dfe8a..b41d7b6b999 100644
--- a/components/layout_2020/flow/root.rs
+++ b/components/layout_2020/flow/root.rs
@@ -83,6 +83,7 @@ impl BoxTree {
where
Node: 'dom + Copy + LayoutNode<'dom> + Send + Sync,
{
+ #[allow(clippy::enum_variant_names)]
enum UpdatePoint {
AbsolutelyPositionedBlockLevelBox(ArcRefCell<BlockLevelBox>),
AbsolutelyPositionedInlineLevelBox(ArcRefCell<InlineLevelBox>),
diff --git a/components/layout_2020/flow/text_run.rs b/components/layout_2020/flow/text_run.rs
index 7b7dc3d42a7..2667c474d9e 100644
--- a/components/layout_2020/flow/text_run.rs
+++ b/components/layout_2020/flow/text_run.rs
@@ -709,7 +709,7 @@ pub struct TextTransformation<InputIterator> {
pending_case_conversion_result: Option<PendingCaseConversionResult>,
}
-impl<'a, InputIterator> TextTransformation<InputIterator> {
+impl<InputIterator> TextTransformation<InputIterator> {
pub fn new(char_iterator: InputIterator, text_transform: TextTransform) -> Self {
Self {
char_iterator,
diff --git a/components/layout_2020/fragment_tree/base_fragment.rs b/components/layout_2020/fragment_tree/base_fragment.rs
index d84dde30111..ac29bcc976d 100644
--- a/components/layout_2020/fragment_tree/base_fragment.rs
+++ b/components/layout_2020/fragment_tree/base_fragment.rs
@@ -117,7 +117,7 @@ impl Tag {
self.pseudo.is_some()
}
- pub(crate) fn to_display_list_fragment_id(&self) -> u64 {
+ pub(crate) fn to_display_list_fragment_id(self) -> u64 {
let fragment_type = match self.pseudo {
Some(PseudoElement::Before) => FragmentType::BeforePseudoContent,
Some(PseudoElement::After) => FragmentType::AfterPseudoContent,
diff --git a/components/layout_2020/fragment_tree/box_fragment.rs b/components/layout_2020/fragment_tree/box_fragment.rs
index 031285360a7..6f191b25a58 100644
--- a/components/layout_2020/fragment_tree/box_fragment.rs
+++ b/components/layout_2020/fragment_tree/box_fragment.rs
@@ -74,6 +74,7 @@ pub(crate) struct BoxFragment {
}
impl BoxFragment {
+ #[allow(clippy::too_many_arguments)]
pub fn new(
base_fragment_info: BaseFragmentInfo,
style: ServoArc<ComputedValues>,
@@ -108,6 +109,7 @@ impl BoxFragment {
)
}
+ #[allow(clippy::too_many_arguments)]
pub fn new_with_overconstrained(
base_fragment_info: BaseFragmentInfo,
style: ServoArc<ComputedValues>,
diff --git a/components/layout_2020/fragment_tree/hoisted_shared_fragment.rs b/components/layout_2020/fragment_tree/hoisted_shared_fragment.rs
index 62822d4d610..ee6ce9870d6 100644
--- a/components/layout_2020/fragment_tree/hoisted_shared_fragment.rs
+++ b/components/layout_2020/fragment_tree/hoisted_shared_fragment.rs
@@ -56,16 +56,12 @@ pub(crate) enum AbsoluteBoxOffsets {
impl AbsoluteBoxOffsets {
pub(crate) fn both_specified(&self) -> bool {
- match self {
- AbsoluteBoxOffsets::Both { .. } => true,
- _ => false,
- }
+ matches!(self, AbsoluteBoxOffsets::Both { .. })
}
pub(crate) fn adjust_offset(&mut self, new_offset: Length) {
- match *self {
- AbsoluteBoxOffsets::StaticStart { ref mut start } => *start = new_offset,
- _ => (),
+ if let AbsoluteBoxOffsets::StaticStart { ref mut start } = *self {
+ *start = new_offset
}
}
}
diff --git a/components/layout_2020/fragment_tree/mod.rs b/components/layout_2020/fragment_tree/mod.rs
index 4579638685a..8738f2a6af7 100644
--- a/components/layout_2020/fragment_tree/mod.rs
+++ b/components/layout_2020/fragment_tree/mod.rs
@@ -6,6 +6,7 @@ mod base_fragment;
mod box_fragment;
mod containing_block;
mod fragment;
+#[allow(clippy::module_inception)]
mod fragment_tree;
mod hoisted_shared_fragment;
mod positioning_fragment;
diff --git a/components/layout_2020/query.rs b/components/layout_2020/query.rs
index e7e8cdf8667..c4cab2c0b13 100644
--- a/components/layout_2020/query.rs
+++ b/components/layout_2020/query.rs
@@ -505,12 +505,9 @@ fn process_offset_parent_query_inner(
// "If any of the following holds true return null and terminate
// this algorithm: [...] The element’s computed value of the
// `position` property is `fixed`."
- let is_fixed = match fragment {
- Fragment::Box(fragment) if fragment.style.get_box().position == Position::Fixed => {
- true
- },
- _ => false,
- };
+ let is_fixed = matches!(
+ fragment, Fragment::Box(fragment) if fragment.style.get_box().position == Position::Fixed
+ );
if is_body_element {
// "If the element is the HTML body element or [...] return zero
diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs
index b4a5325eaca..233bdca0076 100644
--- a/components/layout_2020/style_ext.rs
+++ b/components/layout_2020/style_ext.rs
@@ -88,6 +88,7 @@ pub(crate) enum DisplayInside {
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+#[allow(clippy::enum_variant_names)]
/// <https://drafts.csswg.org/css-display-3/#layout-specific-display>
pub(crate) enum DisplayLayoutInternal {
TableCaption,
diff --git a/components/layout_2020/table/construct.rs b/components/layout_2020/table/construct.rs
index b43861ff3c2..5aff025c1ce 100644
--- a/components/layout_2020/table/construct.rs
+++ b/components/layout_2020/table/construct.rs
@@ -704,8 +704,7 @@ where
});
let previous_text_decoration_line = self.current_text_decoration_line;
- self.current_text_decoration_line =
- self.current_text_decoration_line | info.style.clone_text_decoration_line();
+ self.current_text_decoration_line |= info.style.clone_text_decoration_line();
let new_row_group_index = self.builder.table.row_groups.len() - 1;
self.current_row_group_index = Some(new_row_group_index);
@@ -953,6 +952,7 @@ where
contents: Contents,
box_slot: BoxSlot<'dom>,
) {
+ #[allow(clippy::collapsible_match)] //// TODO: Remove once the other cases are handled
match display {
DisplayGeneratingBox::LayoutInternal(internal) => match internal {
DisplayLayoutInternal::TableCell => {
diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs
index ec538864533..1ecc1baa447 100644
--- a/components/layout_2020/table/layout.rs
+++ b/components/layout_2020/table/layout.rs
@@ -374,8 +374,7 @@ impl<'a> TableLayout<'a> {
// > * 100% minus the sum of the intrinsic percentage width of all prior columns in
// > the table (further left when direction is "ltr" (right for "rtl"))
let mut total_intrinsic_percentage_width = 0.;
- for column_index in 0..self.table.size.width {
- let column_measure = &mut column_measures[column_index];
+ for column_measure in column_measures.iter_mut() {
let final_intrinsic_percentage_width = column_measure
.percentage
.0
@@ -822,7 +821,7 @@ impl<'a> TableLayout<'a> {
/// This is an implementation of *Distributing excess width to columns* from
/// <https://drafts.csswg.org/css-tables/#distributing-width-to-columns>.
- fn distribute_extra_width_to_columns(&self, column_sizes: &mut Vec<Au>, column_sizes_sum: Au) {
+ fn distribute_extra_width_to_columns(&self, column_sizes: &mut [Au], column_sizes_sum: Au) {
let all_columns = 0..self.table.size.width;
let extra_inline_size = self.assignable_width - column_sizes_sum;
@@ -971,8 +970,8 @@ impl<'a> TableLayout<'a> {
for row_index in 0..self.table.slots.len() {
let row = &self.table.slots[row_index];
let mut cells_laid_out_row = Vec::new();
- for column_index in 0..row.len() {
- let cell = match &row[column_index] {
+ for (column_index, slot) in row.iter().enumerate() {
+ let cell = match slot {
TableSlot::Cell(cell) => cell,
_ => {
cells_laid_out_row.push(None);
@@ -1088,6 +1087,7 @@ impl<'a> TableLayout<'a> {
row_sizes
}
+ #[allow(clippy::ptr_arg)] // Needs to be a vec because of the function above
/// After doing layout of table rows, calculate final row size and distribute space across
/// rowspanned cells. This follows the implementation of LayoutNG and the priority
/// agorithm described at <https://github.com/w3c/csswg-drafts/issues/4418>.
@@ -1098,6 +1098,7 @@ impl<'a> TableLayout<'a> {
) {
let mut cells_to_distribute = Vec::new();
let mut total_percentage = 0.;
+ #[allow(clippy::needless_range_loop)] // It makes sense to use it here
for row_index in 0..self.table.size.height {
let row_measure = self
.table
@@ -1186,7 +1187,7 @@ impl<'a> TableLayout<'a> {
&self,
mut excess_size: Au,
track_range: Range<usize>,
- track_sizes: &mut Vec<Au>,
+ track_sizes: &mut [Au],
percentage_resolution_size: Option<Au>,
rowspan_distribution: bool,
) {