diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-04-22 20:20:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 18:20:47 +0000 |
commit | a0640c8524b471462af8a352d87c38fa63337914 (patch) | |
tree | 5564446fbd289c6bd9a23d51518aaa85de286ad6 | |
parent | f65010c97d50f0e2172c9d4477cc702099d44263 (diff) | |
download | servo-a0640c8524b471462af8a352d87c38fa63337914.tar.gz servo-a0640c8524b471462af8a352d87c38fa63337914.zip |
Address issues uncovered by rust-1.78 beta (#32130)
This change makes changes to allow Servo to compile with the 1.78
version of Rust:
- Dead code is removd (Rust seems to have gotten better at detecting
it).
- The `FlowRef` `DerefMut` is updated according to @SimonSapin's advice
[^1].
- The `imports.rs` now explicitly silences warnings about unused
imports.
[^1]: https://github.com/servo/servo/issues/6503#issuecomment-2066088179
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they should not change
behavior.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->
<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->
-rw-r--r-- | components/layout/flow_ref.rs | 2 | ||||
-rw-r--r-- | components/layout_2020/flow/float.rs | 10 | ||||
-rw-r--r-- | components/layout_2020/fragment_tree/fragment.rs | 5 | ||||
-rw-r--r-- | components/layout_2020/style_ext.rs | 24 | ||||
-rw-r--r-- | components/script/dom/bindings/import.rs | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/root.rs | 32 | ||||
-rw-r--r-- | components/script/dom/htmlimageelement.rs | 5 | ||||
-rwxr-xr-x | components/script/dom/htmlinputelement.rs | 14 | ||||
-rw-r--r-- | components/script/dom/node.rs | 7 | ||||
-rw-r--r-- | components/script/dom/webgl_extensions/wrapper.rs | 6 | ||||
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 10 | ||||
-rw-r--r-- | components/script/euclidext.rs | 21 | ||||
-rw-r--r-- | components/script/lib.rs | 1 | ||||
-rw-r--r-- | ports/servoshell/headed_window.rs | 4 | ||||
-rw-r--r-- | ports/servoshell/headless_window.rs | 8 | ||||
-rw-r--r-- | ports/servoshell/window_trait.rs | 1 |
16 files changed, 6 insertions, 146 deletions
diff --git a/components/layout/flow_ref.rs b/components/layout/flow_ref.rs index 4657db77040..b9827bb7eb6 100644 --- a/components/layout/flow_ref.rs +++ b/components/layout/flow_ref.rs @@ -51,7 +51,7 @@ impl FlowRef { #[allow(unsafe_code)] #[allow(clippy::should_implement_trait)] pub fn deref_mut(this: &mut FlowRef) -> &mut dyn Flow { - let ptr: *const dyn Flow = &*this.0; + let ptr: *const dyn Flow = Arc::as_ptr(&this.0); unsafe { &mut *(ptr as *mut dyn Flow) } } } diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index c2c88128e84..5cf4f87d7d3 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -7,7 +7,7 @@ //! See CSS 2.1 § 9.5.1: <https://www.w3.org/TR/CSS2/visuren.html#float-position> use std::collections::VecDeque; -use std::fmt::{Debug, Formatter, Result as FmtResult}; +use std::fmt::Debug; use std::mem; use std::ops::Range; @@ -24,7 +24,7 @@ use crate::context::LayoutContext; use crate::dom::NodeExt; use crate::dom_traversal::{Contents, NodeAndStyleInfo}; use crate::formatting_contexts::IndependentFormattingContext; -use crate::fragment_tree::{BoxFragment, CollapsedBlockMargins, CollapsedMargin, FloatFragment}; +use crate::fragment_tree::{BoxFragment, CollapsedBlockMargins, CollapsedMargin}; use crate::geom::{LogicalRect, LogicalVec2}; use crate::positioned::PositioningContext; use crate::style_ext::{ComputedValuesExt, DisplayInside, PaddingBorderMargin}; @@ -867,12 +867,6 @@ impl FloatBandLink { } } -impl Debug for FloatFragment { - fn fmt(&self, formatter: &mut Formatter) -> FmtResult { - write!(formatter, "FloatFragment") - } -} - impl FloatBox { /// Creates a new float box. pub fn construct<'dom>( diff --git a/components/layout_2020/fragment_tree/fragment.rs b/components/layout_2020/fragment_tree/fragment.rs index 1fdff504072..2aaf4775499 100644 --- a/components/layout_2020/fragment_tree/fragment.rs +++ b/components/layout_2020/fragment_tree/fragment.rs @@ -49,11 +49,6 @@ pub(crate) enum Fragment { } #[derive(Serialize)] -pub(crate) struct FloatFragment { - pub box_fragment: BoxFragment, -} - -#[derive(Serialize)] pub(crate) struct CollapsedBlockMargins { pub collapsed_through: bool, pub start: CollapsedMargin, diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index 3430d2ffd8b..7674e053ce8 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -137,8 +137,6 @@ impl PaddingBorderMargin { } pub(crate) trait ComputedValuesExt { - fn inline_size_is_length(&self) -> bool; - fn inline_box_offsets_are_both_non_auto(&self) -> bool; fn box_offsets( &self, containing_block: &ContainingBlock, @@ -198,28 +196,6 @@ pub(crate) trait ComputedValuesExt { } impl ComputedValuesExt for ComputedValues { - fn inline_size_is_length(&self) -> bool { - let position = self.get_position(); - // FIXME: this is the wrong writing mode but we plan to remove eager content size computation. - let size = if self.writing_mode.is_horizontal() { - &position.width - } else { - &position.height - }; - matches!(size, Size::LengthPercentage(lp) if lp.0.to_length().is_some()) - } - - fn inline_box_offsets_are_both_non_auto(&self) -> bool { - let position = self.get_position(); - // FIXME: this is the wrong writing mode but we plan to remove eager content size computation. - let (a, b) = if self.writing_mode.is_horizontal() { - (&position.left, &position.right) - } else { - (&position.top, &position.bottom) - }; - !a.is_auto() && !b.is_auto() - } - fn box_offsets( &self, containing_block: &ContainingBlock, diff --git a/components/script/dom/bindings/import.rs b/components/script/dom/bindings/import.rs index 34ac97fd31a..f2c6a5e2b81 100644 --- a/components/script/dom/bindings/import.rs +++ b/components/script/dom/bindings/import.rs @@ -2,6 +2,7 @@ * 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/. */ +#[allow(unused_imports)] pub mod base { pub use std::ptr; pub use std::rc::Rc; @@ -41,6 +42,7 @@ pub mod base { pub use crate::script_runtime::JSContext as SafeJSContext; } +#[allow(unused_imports)] pub mod module { pub use std::cmp; pub use std::ffi::CString; diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index de325707ee5..f9b302fab5f 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -31,8 +31,7 @@ use std::marker::PhantomData; use std::ops::Deref; use std::{mem, ptr}; -use js::jsapi::{Heap, JSObject, JSTracer}; -use js::rust::GCMethods; +use js::jsapi::{JSObject, JSTracer}; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use script_layout_interface::TrustedNodeAddress; use style::thread_state; @@ -772,32 +771,3 @@ where &*(slice as *const [Dom<T>] as *const [LayoutDom<T>]) } } - -/// Helper trait for safer manipulations of `Option<Heap<T>>` values. -pub trait OptionalHeapSetter { - type Value; - /// Update this optional heap value with a new value. - fn set(&mut self, v: Option<Self::Value>); -} - -impl<T: GCMethods + Copy> OptionalHeapSetter for Option<Heap<T>> -where - Heap<T>: Default, -{ - type Value = T; - fn set(&mut self, v: Option<T>) { - let v = match v { - None => { - *self = None; - return; - }, - Some(v) => v, - }; - - if self.is_none() { - *self = Some(Heap::default()); - } - - self.as_ref().unwrap().set(v); - } -} diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 90a4a981710..d2bb0d57408 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -1376,7 +1376,6 @@ impl MicrotaskRunnable for ImageElementMicrotask { } pub trait LayoutHTMLImageElementHelpers { - fn image(self) -> Option<Arc<Image>>; fn image_url(self) -> Option<ServoUrl>; fn image_density(self) -> Option<f64>; fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>); @@ -1392,10 +1391,6 @@ impl<'dom> LayoutDom<'dom, HTMLImageElement> { } impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> { - fn image(self) -> Option<Arc<Image>> { - self.current_request().image.clone() - } - fn image_url(self) -> Option<ServoUrl> { self.current_request().parsed_url.clone() } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index d077e46aec0..20649baa774 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -974,8 +974,6 @@ pub trait LayoutHTMLInputElementHelpers<'dom> { fn value_for_layout(self) -> Cow<'dom, str>; fn size_for_layout(self) -> u32; fn selection_for_layout(self) -> Option<Range<usize>>; - fn checked_state_for_layout(self) -> bool; - fn indeterminate_state_for_layout(self) -> bool; } #[allow(unsafe_code)] @@ -1077,18 +1075,6 @@ impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElem _ => None, } } - - fn checked_state_for_layout(self) -> bool { - self.upcast::<Element>() - .get_state_for_layout() - .contains(ElementState::CHECKED) - } - - fn indeterminate_state_for_layout(self) -> bool { - self.upcast::<Element>() - .get_state_for_layout() - .contains(ElementState::INDETERMINATE) - } } impl TextControlElement for HTMLInputElement { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 2ddd18f9503..b3b7fca3904 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1329,8 +1329,6 @@ pub trait LayoutNodeHelpers<'dom> { unsafe fn get_flag(self, flag: NodeFlags) -> bool; unsafe fn set_flag(self, flag: NodeFlags, value: bool); - fn children_count(self) -> u32; - fn style_data(self) -> Option<&'dom StyleData>; fn layout_data(self) -> Option<&'dom GenericLayoutData>; @@ -1473,11 +1471,6 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> { (this).flags.set(flags); } - #[inline] - fn children_count(self) -> u32 { - self.unsafe_get().children_count.get() - } - // FIXME(nox): How we handle style and layout data needs to be completely // revisited so we can do that more cleanly and safely in layout 2020. #[inline] diff --git a/components/script/dom/webgl_extensions/wrapper.rs b/components/script/dom/webgl_extensions/wrapper.rs index 8549f87e766..fc9b6074e8e 100644 --- a/components/script/dom/webgl_extensions/wrapper.rs +++ b/components/script/dom/webgl_extensions/wrapper.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::any::Any; use std::ptr::NonNull; use js::jsapi::JSObject; @@ -27,7 +26,6 @@ pub trait WebGLExtensionWrapper: JSTraceable + MallocSizeOf { fn is_enabled(&self) -> bool; fn enable(&self, ext: &WebGLExtensions); fn name(&self) -> &'static str; - fn as_any(&self) -> &dyn Any; } #[crown::unrooted_must_root_lint::must_root] @@ -86,8 +84,4 @@ where fn name(&self) -> &'static str { T::name() } - - fn as_any(&self) -> &dyn Any { - self - } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 6f7d53c28bc..cf827726906 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -4960,16 +4960,6 @@ impl WebGLMessageSender { } } -pub trait Size2DExt { - fn to_u64(&self) -> Size2D<u64>; -} - -impl Size2DExt for Size2D<u32> { - fn to_u64(&self) -> Size2D<u64> { - Size2D::new(self.width as u64, self.height as u64) - } -} - fn array_buffer_type_to_sized_type(type_: Type) -> Option<SizedDataType> { match type_ { Type::Uint8 | Type::Uint8Clamped => Some(SizedDataType::Uint8), diff --git a/components/script/euclidext.rs b/components/script/euclidext.rs deleted file mode 100644 index c6eb72f89fc..00000000000 --- a/components/script/euclidext.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 euclid::default::Rect; - -pub trait RectExt { - fn to_u64(&self) -> Rect<u64>; -} - -impl RectExt for Rect<f64> { - fn to_u64(&self) -> Rect<u64> { - self.cast() - } -} - -impl RectExt for Rect<u32> { - fn to_u64(&self) -> Rect<u64> { - self.cast() - } -} diff --git a/components/script/lib.rs b/components/script/lib.rs index 2bfde9ecde0..4d984dd5990 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -42,7 +42,6 @@ pub mod document_loader; mod dom; #[warn(deprecated)] mod canvas_state; -mod euclidext; #[warn(deprecated)] pub mod fetch; #[warn(deprecated)] diff --git a/ports/servoshell/headed_window.rs b/ports/servoshell/headed_window.rs index 540bb2a3fce..8a006a7e878 100644 --- a/ports/servoshell/headed_window.rs +++ b/ports/servoshell/headed_window.rs @@ -283,10 +283,6 @@ impl WindowPortsMethods for Window { std::mem::take(&mut *self.event_queue.borrow_mut()) } - fn has_events(&self) -> bool { - !self.event_queue.borrow().is_empty() - } - fn device_hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> { Scale::new(self.winit_window.scale_factor() as f32) } diff --git a/ports/servoshell/headless_window.rs b/ports/servoshell/headless_window.rs index 93ff68da0b8..3f7499548cb 100644 --- a/ports/servoshell/headless_window.rs +++ b/ports/servoshell/headless_window.rs @@ -69,14 +69,6 @@ impl WindowPortsMethods for Window { } } - fn has_events(&self) -> bool { - self.event_queue - .read() - .ok() - .map(|queue| !queue.is_empty()) - .unwrap_or(false) - } - fn id(&self) -> winit::window::WindowId { unsafe { winit::window::WindowId::dummy() } } diff --git a/ports/servoshell/window_trait.rs b/ports/servoshell/window_trait.rs index 04d5db60fc8..490ec0415dc 100644 --- a/ports/servoshell/window_trait.rs +++ b/ports/servoshell/window_trait.rs @@ -21,7 +21,6 @@ pub const LINE_HEIGHT: f32 = 38.0; pub trait WindowPortsMethods: WindowMethods { fn get_events(&self) -> Vec<EmbedderEvent>; fn id(&self) -> winit::window::WindowId; - fn has_events(&self) -> bool; fn hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> { self.device_pixel_ratio_override() .unwrap_or_else(|| match opts::get().output_file { |