clippy: Fix warnings in components/layout_2020 (#31611)

* clippy: fix warnings in components/layout_2020

* fix: review comments
This commit is contained in:
eri 2024-03-11 15:24:33 +01:00 committed by GitHub
parent 1d1f239ecc
commit b03411f567
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 59 additions and 69 deletions

View file

@ -430,11 +430,11 @@ impl StackingContext {
debug_assert!(self debug_assert!(self
.real_stacking_contexts_and_positioned_stacking_containers .real_stacking_contexts_and_positioned_stacking_containers
.iter() .iter()
.all(|c| match c.context_type { .all(|c| matches!(
c.context_type,
StackingContextType::RealStackingContext | StackingContextType::RealStackingContext |
StackingContextType::PositionedStackingContainer => true, StackingContextType::PositionedStackingContainer
_ => false, )));
}));
debug_assert!(self debug_assert!(self
.float_stacking_containers .float_stacking_containers
.iter() .iter()

View file

@ -1109,7 +1109,7 @@ impl<'a> FlexItem<'a> {
flex_context.layout_context, flex_context.layout_context,
&mut positioning_context, &mut positioning_context,
&item_as_containing_block, &item_as_containing_block,
&flex_context.containing_block, flex_context.containing_block,
); );
let hypothetical_cross_size = self let hypothetical_cross_size = self

View file

@ -54,7 +54,7 @@ impl BlockFormattingContext {
} }
} }
pub fn construct_for_text_runs<'dom>( pub fn construct_for_text_runs(
runs: impl Iterator<Item = TextRun>, runs: impl Iterator<Item = TextRun>,
layout_context: &LayoutContext, layout_context: &LayoutContext,
text_decoration_line: TextDecorationLine, text_decoration_line: TextDecorationLine,
@ -409,15 +409,11 @@ where
// collecting all Cow strings into a vector and passing them along to text breaking // collecting all Cow strings into a vector and passing them along to text breaking
// and shaping during final InlineFormattingContext construction. // and shaping during final InlineFormattingContext construction.
let inlines = self.current_inline_level_boxes(); let inlines = self.current_inline_level_boxes();
match inlines.last_mut().map(|last| last.borrow_mut()) { if let Some(mut last_box) = inlines.last_mut().map(|last| last.borrow_mut()) {
Some(mut last_box) => match *last_box { if let InlineLevelBox::TextRun(ref mut text_run) = *last_box {
InlineLevelBox::TextRun(ref mut text_run) => {
text_run.text.push_str(&input); text_run.text.push_str(&input);
return; return;
}, }
_ => {},
},
_ => {},
} }
inlines.push(ArcRefCell::new(InlineLevelBox::TextRun(TextRun::new( inlines.push(ArcRefCell::new(InlineLevelBox::TextRun(TextRun::new(

View file

@ -951,7 +951,7 @@ impl FloatBox {
layout_context, layout_context,
positioning_context, positioning_context,
&containing_block_for_children, &containing_block_for_children,
&containing_block, containing_block,
); );
content_size = LogicalVec2 { content_size = LogicalVec2 {
inline: inline_size, inline: inline_size,

View file

@ -1384,14 +1384,11 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
// Place all floats in this unbreakable segment. // Place all floats in this unbreakable segment.
let mut segment_items = mem::take(&mut self.current_line_segment.line_items); let mut segment_items = mem::take(&mut self.current_line_segment.line_items);
for item in segment_items.iter_mut() { for item in segment_items.iter_mut() {
match item { if let LineItem::Float(float_item) = item {
LineItem::Float(float_item) => {
self.place_float_line_item_for_commit_to_line( self.place_float_line_item_for_commit_to_line(
float_item, float_item,
line_inline_size_without_trailing_whitespace, 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 // TODO(mrobinson): Using OwnedRef here we could maybe avoid the second borrow when
// iterating through members of each inline box. // iterating through members of each inline box.
struct InlineFormattingContextChildBoxIter { struct InlineFormattingContextChildBoxIter {
@ -2006,7 +2003,7 @@ impl IndependentFormattingContext {
layout_context, layout_context,
child_positioning_context.as_mut().unwrap(), child_positioning_context.as_mut().unwrap(),
&containing_block_for_children, &containing_block_for_children,
&ifc.containing_block, ifc.containing_block,
); );
let (inline_size, block_size) = let (inline_size, block_size) =
match independent_layout.content_inline_size_for_table { 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() { for item in line_items.iter_mut() {
match item { if let LineItem::Float(float_line_item) = item {
LineItem::Float(float_line_item) => {
if float_line_item.needs_placement { if float_line_item.needs_placement {
ifc.place_float_fragment(&mut float_line_item.fragment); 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 { fn is_baseline_relative(vertical_align: GenericVerticalAlign<LengthPercentage>) -> bool {
match vertical_align { !matches!(
vertical_align,
GenericVerticalAlign::Keyword(VerticalAlignKeyword::Top) | GenericVerticalAlign::Keyword(VerticalAlignKeyword::Top) |
GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => false, GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom)
_ => true, )
}
} }
/// Whether or not a strut should be created for an inline container. Normally /// Whether or not a strut should be created for an inline container. Normally

View file

@ -587,11 +587,11 @@ impl FloatLineItem {
} }
fn is_baseline_relative(vertical_align: GenericVerticalAlign<LengthPercentage>) -> bool { fn is_baseline_relative(vertical_align: GenericVerticalAlign<LengthPercentage>) -> bool {
match vertical_align { !matches!(
vertical_align,
GenericVerticalAlign::Keyword(VerticalAlignKeyword::Top) | GenericVerticalAlign::Keyword(VerticalAlignKeyword::Top) |
GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => false, GenericVerticalAlign::Keyword(VerticalAlignKeyword::Bottom)
_ => true, )
}
} }
fn line_height(parent_style: &ComputedValues, font_metrics: &FontMetrics) -> Length { fn line_height(parent_style: &ComputedValues, font_metrics: &FontMetrics) -> Length {

View file

@ -613,6 +613,7 @@ impl BlockLevelBox {
/// ///
/// - <https://drafts.csswg.org/css2/visudet.html#blockwidth> /// - <https://drafts.csswg.org/css2/visudet.html#blockwidth>
/// - <https://drafts.csswg.org/css2/visudet.html#normal-block> /// - <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( fn layout_in_flow_non_replaced_block_level_same_formatting_context(
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext, positioning_context: &mut PositioningContext,
@ -856,7 +857,7 @@ impl NonReplacedFormattingContext {
layout_context, layout_context,
positioning_context, positioning_context,
&containing_block_for_children, &containing_block_for_children,
&containing_block, containing_block,
); );
let (block_size, inline_size) = match layout.content_inline_size_for_table { 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#block-replaced-width>
/// <https://drafts.csswg.org/css2/visudet.html#inline-replaced-width> /// <https://drafts.csswg.org/css2/visudet.html#inline-replaced-width>
/// <https://drafts.csswg.org/css2/visudet.html#inline-replaced-height> /// <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, containing_block: &ContainingBlock,
base_fragment_info: BaseFragmentInfo, base_fragment_info: BaseFragmentInfo,
style: &Arc<ComputedValues>, style: &Arc<ComputedValues>,
@ -1348,8 +1349,8 @@ fn solve_margins(
inline_size: Length, inline_size: Length,
) -> ResolvedMargins { ) -> ResolvedMargins {
let (inline_margins, effective_margin_inline_start) = let (inline_margins, effective_margin_inline_start) =
solve_inline_margins_for_in_flow_block_level(containing_block, &pbm, inline_size); 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); let block_margins = solve_block_margins_for_in_flow_block_level(pbm);
ResolvedMargins { ResolvedMargins {
margin: LogicalSides { margin: LogicalSides {
inline_start: inline_margins.0, inline_start: inline_margins.0,

View file

@ -83,6 +83,7 @@ impl BoxTree {
where where
Node: 'dom + Copy + LayoutNode<'dom> + Send + Sync, Node: 'dom + Copy + LayoutNode<'dom> + Send + Sync,
{ {
#[allow(clippy::enum_variant_names)]
enum UpdatePoint { enum UpdatePoint {
AbsolutelyPositionedBlockLevelBox(ArcRefCell<BlockLevelBox>), AbsolutelyPositionedBlockLevelBox(ArcRefCell<BlockLevelBox>),
AbsolutelyPositionedInlineLevelBox(ArcRefCell<InlineLevelBox>), AbsolutelyPositionedInlineLevelBox(ArcRefCell<InlineLevelBox>),

View file

@ -709,7 +709,7 @@ pub struct TextTransformation<InputIterator> {
pending_case_conversion_result: Option<PendingCaseConversionResult>, 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 { pub fn new(char_iterator: InputIterator, text_transform: TextTransform) -> Self {
Self { Self {
char_iterator, char_iterator,

View file

@ -117,7 +117,7 @@ impl Tag {
self.pseudo.is_some() 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 { let fragment_type = match self.pseudo {
Some(PseudoElement::Before) => FragmentType::BeforePseudoContent, Some(PseudoElement::Before) => FragmentType::BeforePseudoContent,
Some(PseudoElement::After) => FragmentType::AfterPseudoContent, Some(PseudoElement::After) => FragmentType::AfterPseudoContent,

View file

@ -74,6 +74,7 @@ pub(crate) struct BoxFragment {
} }
impl BoxFragment { impl BoxFragment {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
base_fragment_info: BaseFragmentInfo, base_fragment_info: BaseFragmentInfo,
style: ServoArc<ComputedValues>, style: ServoArc<ComputedValues>,
@ -108,6 +109,7 @@ impl BoxFragment {
) )
} }
#[allow(clippy::too_many_arguments)]
pub fn new_with_overconstrained( pub fn new_with_overconstrained(
base_fragment_info: BaseFragmentInfo, base_fragment_info: BaseFragmentInfo,
style: ServoArc<ComputedValues>, style: ServoArc<ComputedValues>,

View file

@ -56,16 +56,12 @@ pub(crate) enum AbsoluteBoxOffsets {
impl AbsoluteBoxOffsets { impl AbsoluteBoxOffsets {
pub(crate) fn both_specified(&self) -> bool { pub(crate) fn both_specified(&self) -> bool {
match self { matches!(self, AbsoluteBoxOffsets::Both { .. })
AbsoluteBoxOffsets::Both { .. } => true,
_ => false,
}
} }
pub(crate) fn adjust_offset(&mut self, new_offset: Length) { pub(crate) fn adjust_offset(&mut self, new_offset: Length) {
match *self { if let AbsoluteBoxOffsets::StaticStart { ref mut start } = *self {
AbsoluteBoxOffsets::StaticStart { ref mut start } => *start = new_offset, *start = new_offset
_ => (),
} }
} }
} }

View file

@ -6,6 +6,7 @@ mod base_fragment;
mod box_fragment; mod box_fragment;
mod containing_block; mod containing_block;
mod fragment; mod fragment;
#[allow(clippy::module_inception)]
mod fragment_tree; mod fragment_tree;
mod hoisted_shared_fragment; mod hoisted_shared_fragment;
mod positioning_fragment; mod positioning_fragment;

View file

@ -505,12 +505,9 @@ fn process_offset_parent_query_inner(
// "If any of the following holds true return null and terminate // "If any of the following holds true return null and terminate
// this algorithm: [...] The elements computed value of the // this algorithm: [...] The elements computed value of the
// `position` property is `fixed`." // `position` property is `fixed`."
let is_fixed = match fragment { let is_fixed = matches!(
Fragment::Box(fragment) if fragment.style.get_box().position == Position::Fixed => { fragment, Fragment::Box(fragment) if fragment.style.get_box().position == Position::Fixed
true );
},
_ => false,
};
if is_body_element { if is_body_element {
// "If the element is the HTML body element or [...] return zero // "If the element is the HTML body element or [...] return zero

View file

@ -88,6 +88,7 @@ pub(crate) enum DisplayInside {
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[allow(clippy::enum_variant_names)]
/// <https://drafts.csswg.org/css-display-3/#layout-specific-display> /// <https://drafts.csswg.org/css-display-3/#layout-specific-display>
pub(crate) enum DisplayLayoutInternal { pub(crate) enum DisplayLayoutInternal {
TableCaption, TableCaption,

View file

@ -704,8 +704,7 @@ where
}); });
let previous_text_decoration_line = self.current_text_decoration_line; 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; let new_row_group_index = self.builder.table.row_groups.len() - 1;
self.current_row_group_index = Some(new_row_group_index); self.current_row_group_index = Some(new_row_group_index);
@ -953,6 +952,7 @@ where
contents: Contents, contents: Contents,
box_slot: BoxSlot<'dom>, box_slot: BoxSlot<'dom>,
) { ) {
#[allow(clippy::collapsible_match)] //// TODO: Remove once the other cases are handled
match display { match display {
DisplayGeneratingBox::LayoutInternal(internal) => match internal { DisplayGeneratingBox::LayoutInternal(internal) => match internal {
DisplayLayoutInternal::TableCell => { DisplayLayoutInternal::TableCell => {

View file

@ -374,8 +374,7 @@ impl<'a> TableLayout<'a> {
// > * 100% minus the sum of the intrinsic percentage width of all prior columns in // > * 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")) // > the table (further left when direction is "ltr" (right for "rtl"))
let mut total_intrinsic_percentage_width = 0.; let mut total_intrinsic_percentage_width = 0.;
for column_index in 0..self.table.size.width { for column_measure in column_measures.iter_mut() {
let column_measure = &mut column_measures[column_index];
let final_intrinsic_percentage_width = column_measure let final_intrinsic_percentage_width = column_measure
.percentage .percentage
.0 .0
@ -822,7 +821,7 @@ impl<'a> TableLayout<'a> {
/// This is an implementation of *Distributing excess width to columns* from /// This is an implementation of *Distributing excess width to columns* from
/// <https://drafts.csswg.org/css-tables/#distributing-width-to-columns>. /// <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 all_columns = 0..self.table.size.width;
let extra_inline_size = self.assignable_width - column_sizes_sum; 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() { for row_index in 0..self.table.slots.len() {
let row = &self.table.slots[row_index]; let row = &self.table.slots[row_index];
let mut cells_laid_out_row = Vec::new(); let mut cells_laid_out_row = Vec::new();
for column_index in 0..row.len() { for (column_index, slot) in row.iter().enumerate() {
let cell = match &row[column_index] { let cell = match slot {
TableSlot::Cell(cell) => cell, TableSlot::Cell(cell) => cell,
_ => { _ => {
cells_laid_out_row.push(None); cells_laid_out_row.push(None);
@ -1088,6 +1087,7 @@ impl<'a> TableLayout<'a> {
row_sizes 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 /// 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 /// rowspanned cells. This follows the implementation of LayoutNG and the priority
/// agorithm described at <https://github.com/w3c/csswg-drafts/issues/4418>. /// 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 cells_to_distribute = Vec::new();
let mut total_percentage = 0.; 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 { for row_index in 0..self.table.size.height {
let row_measure = self let row_measure = self
.table .table
@ -1186,7 +1187,7 @@ impl<'a> TableLayout<'a> {
&self, &self,
mut excess_size: Au, mut excess_size: Au,
track_range: Range<usize>, track_range: Range<usize>,
track_sizes: &mut Vec<Au>, track_sizes: &mut [Au],
percentage_resolution_size: Option<Au>, percentage_resolution_size: Option<Au>,
rowspan_distribution: bool, rowspan_distribution: bool,
) { ) {