aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/config/pref_util.rs6
-rw-r--r--components/fonts/font.rs3
-rw-r--r--components/fonts/platform/freetype/font.rs4
-rw-r--r--components/layout/display_list/items.rs2
-rw-r--r--components/layout/flow.rs7
-rw-r--r--components/layout/layout_debug.rs2
-rw-r--r--components/layout/text.rs1
-rw-r--r--components/layout/text_run.rs2
-rw-r--r--components/layout/traversal.rs6
-rw-r--r--components/layout_2020/display_list/gradient.rs2
-rw-r--r--components/layout_2020/dom.rs4
-rw-r--r--components/layout_2020/flexbox/construct.rs6
-rw-r--r--components/layout_2020/flexbox/layout.rs69
-rw-r--r--components/layout_2020/flow/inline/text_run.rs6
-rw-r--r--components/layout_2020/layout_debug.rs2
-rw-r--r--components/layout_2020/replaced.rs5
-rw-r--r--components/layout_2020/table/layout.rs5
-rw-r--r--components/shared/base/id.rs5
-rw-r--r--components/shared/net/lib.rs11
-rw-r--r--components/shared/script/lib.rs2
20 files changed, 72 insertions, 78 deletions
diff --git a/components/config/pref_util.rs b/components/config/pref_util.rs
index c0def153d44..f79b0d7e22e 100644
--- a/components/config/pref_util.rs
+++ b/components/config/pref_util.rs
@@ -3,7 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap;
-use std::convert::TryInto;
use std::fmt;
use std::str::FromStr;
use std::sync::RwLock;
@@ -158,10 +157,7 @@ impl From<PrefValue> for [f64; 4] {
fn from(other: PrefValue) -> [f64; 4] {
match other {
PrefValue::Array(values) if values.len() == 4 => {
- let f = values
- .into_iter()
- .filter_map(|v| v.try_into().ok())
- .collect::<Vec<f64>>();
+ let f = values.into_iter().map(Into::into).collect::<Vec<f64>>();
if f.len() == 4 {
[f[0], f[1], f[2], f[3]]
} else {
diff --git a/components/fonts/font.rs b/components/fonts/font.rs
index 14f5af4197e..918186ecc0c 100644
--- a/components/fonts/font.rs
+++ b/components/fonts/font.rs
@@ -329,8 +329,7 @@ impl Font {
}
}
- let is_single_preserved_newline = text.len() == 1 && text.chars().next() == Some('\n');
-
+ let is_single_preserved_newline = text.len() == 1 && text.starts_with('\n');
let start_time = Instant::now();
let mut glyphs = GlyphStore::new(
text.len(),
diff --git a/components/fonts/platform/freetype/font.rs b/components/fonts/platform/freetype/font.rs
index f3872298133..831ab717479 100644
--- a/components/fonts/platform/freetype/font.rs
+++ b/components/fonts/platform/freetype/font.rs
@@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use std::convert::TryInto;
use std::os::raw::c_long;
use std::sync::Arc;
use std::{mem, ptr};
@@ -106,12 +105,11 @@ fn create_face(data: Arc<Vec<u8>>, face_index: u32) -> Result<FT_Face, &'static
let library = FreeTypeLibraryHandle::get().lock();
// This is to support 32bit Android where FT_Long is defined as i32.
- let face_index = face_index.try_into().unwrap();
let result = FT_New_Memory_Face(
library.freetype_library,
data.as_ptr(),
data.len() as FT_Long,
- face_index,
+ face_index as FT_Long,
&mut face,
);
diff --git a/components/layout/display_list/items.rs b/components/layout/display_list/items.rs
index 92117a118df..d65b9ea6ba7 100644
--- a/components/layout/display_list/items.rs
+++ b/components/layout/display_list/items.rs
@@ -109,7 +109,7 @@ impl DisplayList {
/// Return the bounds of this display list based on the dimensions of the root
/// stacking context.
pub fn bounds(&self) -> LayoutRect {
- match self.list.get(0) {
+ match self.list.first() {
Some(DisplayItem::PushStackingContext(item)) => item.stacking_context.bounds,
Some(_) => unreachable!("Root element of display list not stacking context."),
None => LayoutRect::zero(),
diff --git a/components/layout/flow.rs b/components/layout/flow.rs
index 8cdaa6d521d..7f098d2a0cb 100644
--- a/components/layout/flow.rs
+++ b/components/layout/flow.rs
@@ -74,8 +74,11 @@ use crate::table_wrapper::TableWrapperFlow;
/// This marker trait indicates that a type is a struct with `#[repr(C)]` whose first field
/// is of type `BaseFlow` or some type that also implements this trait.
///
-/// In other words, the memory representation of `BaseFlow` must be a prefix
-/// of the memory representation of types implementing `HasBaseFlow`.
+/// # Safety
+///
+/// The memory representation of `BaseFlow` must be a prefix of the memory representation of types
+/// implementing `HasBaseFlow`. If this isn't the case, calling [`GetBaseFlow::base`] or
+/// [`GetBaseFlow::mut_base`] could lead to memory errors.
#[allow(unsafe_code)]
pub unsafe trait HasBaseFlow {}
diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs
index 54d9c72a191..a50b92948a5 100644
--- a/components/layout/layout_debug.rs
+++ b/components/layout/layout_debug.rs
@@ -18,7 +18,7 @@ use serde_json::{to_string, to_value, Value};
use crate::flow::GetBaseFlow;
use crate::flow_ref::FlowRef;
-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);
diff --git a/components/layout/text.rs b/components/layout/text.rs
index 86f549d464a..ec8901b93c8 100644
--- a/components/layout/text.rs
+++ b/components/layout/text.rs
@@ -833,6 +833,7 @@ fn is_specific(script: Script) -> bool {
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+#[allow(clippy::enum_variant_names)]
pub enum CompressionMode {
CompressNone,
CompressWhitespace,
diff --git a/components/layout/text_run.rs b/components/layout/text_run.rs
index d860cb97890..3dd9542f572 100644
--- a/components/layout/text_run.rs
+++ b/components/layout/text_run.rs
@@ -21,7 +21,7 @@ use xi_unicode::LineBreakLeafIter;
thread_local! {
static INDEX_OF_FIRST_GLYPH_RUN_CACHE: Cell<Option<(*const TextRun, ByteIndex, usize)>> =
- Cell::new(None)
+ const { Cell::new(None) }
}
/// A single "paragraph" of text in one font size and style.
diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs
index 47f2cfc55fd..8a1612e1f14 100644
--- a/components/layout/traversal.rs
+++ b/components/layout/traversal.rs
@@ -187,8 +187,12 @@ where
fn process(&mut self, node: &ConcreteThreadSafeLayoutNode);
}
-#[allow(unsafe_code)]
+/// # Safety
+///
+/// This function modifies the DOM node represented by the `node` argument, so it is imperitive
+/// that no other thread is modifying the node at the same time.
#[inline]
+#[allow(unsafe_code)]
pub unsafe fn construct_flows_at_ancestors<'dom>(
context: &LayoutContext,
mut node: impl LayoutNode<'dom>,
diff --git a/components/layout_2020/display_list/gradient.rs b/components/layout_2020/display_list/gradient.rs
index 582b7ea19de..4c1b8da0355 100644
--- a/components/layout_2020/display_list/gradient.rs
+++ b/components/layout_2020/display_list/gradient.rs
@@ -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
diff --git a/components/layout_2020/dom.rs b/components/layout_2020/dom.rs
index 24ad7f16ed7..c602153cc60 100644
--- a/components/layout_2020/dom.rs
+++ b/components/layout_2020/dom.rs
@@ -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;
}
diff --git a/components/layout_2020/flexbox/construct.rs b/components/layout_2020/flexbox/construct.rs
index a21618d674e..72ee0223705 100644
--- a/components/layout_2020/flexbox/construct.rs
+++ b/components/layout_2020/flexbox/construct.rs
@@ -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),
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index 001908e6fe8..624451a4d97 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -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 that’s 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 item’s target main size was made larger by [clamping],
- // it’s 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 that’s 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 item’s target main size was made larger by [clamping],
+ // it’s 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 item’s target main size was made smaller by [clamping],
- // it’s 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 item’s target main size was made smaller by [clamping],
+ // it’s 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);
+ }
}
- }
+ },
}
}
}
diff --git a/components/layout_2020/flow/inline/text_run.rs b/components/layout_2020/flow/inline/text_run.rs
index d22e7a7c693..bb2a2d7c393 100644
--- a/components/layout_2020/flow/inline/text_run.rs
+++ b/components/layout_2020/flow/inline/text_run.rs
@@ -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))
}
diff --git a/components/layout_2020/layout_debug.rs b/components/layout_2020/layout_debug.rs
index da3c1886971..811254279fb 100644
--- a/components/layout_2020/layout_debug.rs
+++ b/components/layout_2020/layout_debug.rs
@@ -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);
diff --git a/components/layout_2020/replaced.rs b/components/layout_2020/replaced.rs
index 0dbb71ce6fc..5c285f9f7d2 100644
--- a/components/layout_2020/replaced.rs
+++ b/components/layout_2020/replaced.rs
@@ -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;
diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs
index 1f4b5b511e5..b2b5209912b 100644
--- a/components/layout_2020/table/layout.rs
+++ b/components/layout_2020/table/layout.rs
@@ -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 {
diff --git a/components/shared/base/id.rs b/components/shared/base/id.rs
index 06f69547bb7..339356bf35b 100644
--- a/components/shared/base/id.rs
+++ b/components/shared/base/id.rs
@@ -193,7 +193,7 @@ impl PipelineNamespace {
namespace_id_method! {next_blob_id, BlobId, self, BlobIndex}
}
-thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
+thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = const { Cell::new(None) });
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
@@ -271,7 +271,8 @@ impl fmt::Display for BrowsingContextGroupId {
}
}
-thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell<Option<TopLevelBrowsingContextId>> = Cell::new(None));
+thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell<Option<TopLevelBrowsingContextId>> =
+ const { Cell::new(None) });
#[derive(
Clone, Copy, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
diff --git a/components/shared/net/lib.rs b/components/shared/net/lib.rs
index 1fccc8a18c4..db3519f30ad 100644
--- a/components/shared/net/lib.rs
+++ b/components/shared/net/lib.rs
@@ -4,6 +4,7 @@
#![deny(unsafe_code)]
+use std::fmt::Display;
use std::time::{SystemTime, UNIX_EPOCH};
use base::id::HistoryStateId;
@@ -118,9 +119,9 @@ pub enum ReferrerPolicy {
StrictOriginWhenCrossOrigin,
}
-impl ToString for ReferrerPolicy {
- fn to_string(&self) -> String {
- match self {
+impl Display for ReferrerPolicy {
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let string = match self {
ReferrerPolicy::NoReferrer => "no-referrer",
ReferrerPolicy::NoReferrerWhenDowngrade => "no-referrer-when-downgrade",
ReferrerPolicy::Origin => "origin",
@@ -129,8 +130,8 @@ impl ToString for ReferrerPolicy {
ReferrerPolicy::UnsafeUrl => "unsafe-url",
ReferrerPolicy::StrictOrigin => "strict-origin",
ReferrerPolicy::StrictOriginWhenCrossOrigin => "strict-origin-when-cross-origin",
- }
- .to_string()
+ };
+ write!(formatter, "{string}")
}
}
diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs
index 90e12a22663..ff6e2baeefb 100644
--- a/components/shared/script/lib.rs
+++ b/components/shared/script/lib.rs
@@ -79,7 +79,7 @@ unsafe impl Send for UntrustedNodeAddress {}
impl From<WebRenderUntrustedNodeAddress> for UntrustedNodeAddress {
fn from(o: WebRenderUntrustedNodeAddress) -> Self {
- UntrustedNodeAddress(o.0 as *const c_void)
+ UntrustedNodeAddress(o.0)
}
}