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
.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()

View file

@ -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

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>,
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(

View file

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

View file

@ -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

View file

@ -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 {

View file

@ -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,

View file

@ -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>),

View file

@ -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,

View file

@ -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,

View file

@ -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>,

View file

@ -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
}
}
}

View file

@ -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;

View file

@ -505,12 +505,9 @@ fn process_offset_parent_query_inner(
// "If any of the following holds true return null and terminate
// this algorithm: [...] The elements 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

View file

@ -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,

View file

@ -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 => {

View file

@ -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,
) {