clippy: Fix warnings in shared and config, fonts, layout, and layout_2020 components (#32674)

This commit is contained in:
Martin Robinson 2024-07-04 16:18:58 +02:00 committed by GitHub
parent 99c1f886b8
commit 4b63043c6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 72 additions and 78 deletions

View file

@ -410,7 +410,7 @@ fn gradient_items_to_color_stops(
}
/// <https://drafts.csswg.org/css-images-4/#color-stop-fixup>
fn fixup_stops(stops: &mut Vec<ColorStop<ColorF, f32>>) -> Vec<wr::GradientStop> {
fn fixup_stops(stops: &mut [ColorStop<ColorF, f32>]) -> Vec<wr::GradientStop> {
assert!(stops.len() >= 2);
// https://drafts.csswg.org/css-images-4/#color-stop-fixup

View file

@ -176,13 +176,11 @@ where
if self.type_id() != ScriptLayoutNodeType::Element(LayoutElementType::HTMLObjectElement) {
return None;
}
let Some(element) = self.to_threadsafe().as_element() else {
return None;
};
// TODO: This is the what the legacy layout system does, but really if Servo
// supports any `<object>` that's an image, it should support those with URLs
// and `type` attributes with image mime types.
let element = self.to_threadsafe().as_element()?;
if element.get_attr(&ns!(), &local_name!("type")).is_some() {
return None;
}

View file

@ -156,14 +156,12 @@ where
.push_text(flex_text_run.text, &flex_text_run.info);
}
let Some(inline_formatting_context) = inline_formatting_context_builder.finish(
let inline_formatting_context = inline_formatting_context_builder.finish(
self.context,
self.text_decoration_line,
true, /* has_first_formatted_line */
false, /* is_single_line_text_box */
) else {
return None;
};
)?;
let block_formatting_context = BlockFormattingContext::from_block_container(
BlockContainer::InlineFormattingContext(inline_formatting_context),

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::Cell;
use std::cmp::Ordering;
use app_units::Au;
use atomic_refcell::AtomicRefMut;
@ -1111,40 +1112,44 @@ impl FlexLine<'_> {
// “Freeze over-flexed items.”
let total_violation: Au = unfrozen_items().map(violation).sum();
if total_violation == Au::zero() {
// “Freeze all items.”
// Return instead, as thats what the next loop iteration would do.
let remaining_free_space =
container_main_size - target_main_sizes_vec.iter().cloned().sum();
return (target_main_sizes_vec, remaining_free_space);
} else if total_violation > Au::zero() {
// “Freeze all the items with min violations.”
// “If the items target main size was made larger by [clamping],
// its a min violation.”
for (item_and_target_main_size, frozen) in items() {
if violation(item_and_target_main_size) > Au::zero() {
let (item, target_main_size) = item_and_target_main_size;
target_main_size.set(item.content_min_size.main);
frozen_count.set(frozen_count.get() + 1);
frozen.set(true);
match total_violation.cmp(&Au::zero()) {
Ordering::Equal => {
// “Freeze all items.”
// Return instead, as thats what the next loop iteration would do.
let remaining_free_space =
container_main_size - target_main_sizes_vec.iter().cloned().sum();
return (target_main_sizes_vec, remaining_free_space);
},
Ordering::Greater => {
// “Freeze all the items with min violations.”
// “If the items target main size was made larger by [clamping],
// its a min violation.”
for (item_and_target_main_size, frozen) in items() {
if violation(item_and_target_main_size) > Au::zero() {
let (item, target_main_size) = item_and_target_main_size;
target_main_size.set(item.content_min_size.main);
frozen_count.set(frozen_count.get() + 1);
frozen.set(true);
}
}
}
} else {
// Negative total violation
// “Freeze all the items with max violations.”
// “If the items target main size was made smaller by [clamping],
// its a max violation.”
for (item_and_target_main_size, frozen) in items() {
if violation(item_and_target_main_size) < Au::zero() {
let (item, target_main_size) = item_and_target_main_size;
let Some(max_size) = item.content_max_size.main else {
unreachable!()
};
target_main_size.set(max_size);
frozen_count.set(frozen_count.get() + 1);
frozen.set(true);
},
Ordering::Less => {
// Negative total violation
// “Freeze all the items with max violations.”
// “If the items target main size was made smaller by [clamping],
// its a max violation.”
for (item_and_target_main_size, frozen) in items() {
if violation(item_and_target_main_size) < Au::zero() {
let (item, target_main_size) = item_and_target_main_size;
let Some(max_size) = item.content_max_size.main else {
unreachable!()
};
target_main_size.set(max_size);
frozen_count.set(frozen_count.get() + 1);
frozen.set(true);
}
}
}
},
}
}
}

View file

@ -605,11 +605,7 @@ where
if self.next_character.is_none() {
self.next_character = self.iterator.next();
}
let Some(character) = self.next_character else {
return None;
};
let character = self.next_character?;
self.next_character = self.iterator.next();
Some((character, self.next_character))
}

View file

@ -19,7 +19,7 @@ use serde_json::{to_string, to_value, Value};
use crate::flow::BoxTree;
use crate::fragment_tree::FragmentTree;
thread_local!(static STATE_KEY: RefCell<Option<State>> = RefCell::new(None));
thread_local!(static STATE_KEY: RefCell<Option<State>> = const { RefCell::new(None) });
#[cfg(debug_assertions)]
static DEBUG_ID_COUNTER: AtomicUsize = AtomicUsize::new(0);

View file

@ -575,10 +575,7 @@ fn try_to_parse_image_data_url(string: &str) -> Option<Url> {
if !string.starts_with("data:") {
return None;
}
let Some(data_url) = DataUrl::process(string).ok() else {
return None;
};
let data_url = DataUrl::process(string).ok()?;
let mime_type = data_url.mime_type();
if mime_type.type_ != "image" {
return None;

View file

@ -2061,10 +2061,7 @@ impl<'a> TableLayout<'a> {
cell: &TableSlotCell,
coordinates: TableSlotCoordinates,
) -> Option<LogicalSides<Length>> {
let Some(ref collapsed_borders) = self.collapsed_borders else {
return None;
};
let collapsed_borders = self.collapsed_borders.as_ref()?;
let end_x = coordinates.x + cell.colspan;
let end_y = coordinates.y + cell.rowspan;
let mut result: LogicalSides<Length> = LogicalSides {