diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 183b329468d..c55767ff7a0 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -135,7 +135,7 @@ impl Repetition { } } -pub fn source(pattern: &Pattern) -> raqote::Source { +pub fn source(pattern: &Pattern) -> raqote::Source<'_> { match pattern { Pattern::Color(a, r, g, b) => raqote::Source::Solid( raqote::SolidSource::from_unpremultiplied_argb(*a, *r, *g, *b), diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index a8065bd667c..f85222b84de 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -1376,7 +1376,7 @@ impl IOCompositor { } /// Get the message receiver for this [`IOCompositor`]. - pub fn receiver(&self) -> Ref> { + pub fn receiver(&self) -> Ref<'_, Receiver> { Ref::map(self.global.borrow(), |global| &global.compositor_receiver) } diff --git a/components/compositing/webview_renderer.rs b/components/compositing/webview_renderer.rs index b4380aa2cb7..ac0b6fd82aa 100644 --- a/components/compositing/webview_renderer.rs +++ b/components/compositing/webview_renderer.rs @@ -187,7 +187,7 @@ impl WebViewRenderer { pub(crate) fn set_frame_tree(&mut self, frame_tree: &SendableFrameTree) { let pipeline_id = frame_tree.pipeline.id; - let old_pipeline_id = std::mem::replace(&mut self.root_pipeline_id, Some(pipeline_id)); + let old_pipeline_id = self.root_pipeline_id.replace(pipeline_id); if old_pipeline_id != self.root_pipeline_id { debug!( diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index c539787a759..3d84d95636e 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -1019,7 +1019,7 @@ where fn fully_active_descendant_browsing_contexts_iter( &self, browsing_context_id: BrowsingContextId, - ) -> FullyActiveBrowsingContextsIterator { + ) -> FullyActiveBrowsingContextsIterator<'_> { FullyActiveBrowsingContextsIterator { stack: vec![browsing_context_id], pipelines: &self.pipelines, @@ -1031,7 +1031,7 @@ where fn fully_active_browsing_contexts_iter( &self, webview_id: WebViewId, - ) -> FullyActiveBrowsingContextsIterator { + ) -> FullyActiveBrowsingContextsIterator<'_> { self.fully_active_descendant_browsing_contexts_iter(BrowsingContextId::from(webview_id)) } @@ -1039,7 +1039,7 @@ where fn all_descendant_browsing_contexts_iter( &self, browsing_context_id: BrowsingContextId, - ) -> AllBrowsingContextsIterator { + ) -> AllBrowsingContextsIterator<'_> { AllBrowsingContextsIterator { stack: vec![browsing_context_id], pipelines: &self.pipelines, @@ -1157,6 +1157,7 @@ where /// Handles loading pages, navigation, and granting access to the compositor #[servo_tracing::instrument(skip_all)] fn handle_request(&mut self) { + #[allow(clippy::large_enum_variant)] #[derive(Debug)] enum Request { PipelineNamespace(PipelineNamespaceRequest), @@ -3174,7 +3175,8 @@ where ); }, }; - let is_parent_private = match self.browsing_contexts.get(&parent_browsing_context_id) { + + match self.browsing_contexts.get(&parent_browsing_context_id) { Some(ctx) => ctx.is_private, None => { return warn!( @@ -3182,8 +3184,7 @@ where parent_browsing_context_id, browsing_context_id, ); }, - }; - is_parent_private + } }; let is_private = is_private || is_parent_private; diff --git a/components/devtools/actors/inspector/page_style.rs b/components/devtools/actors/inspector/page_style.rs index 5fa07dec3fd..5d1f9cd6ad1 100644 --- a/components/devtools/actors/inspector/page_style.rs +++ b/components/devtools/actors/inspector/page_style.rs @@ -175,42 +175,41 @@ impl PageStyleActor { // For each selector (plus an empty one that represents the style attribute) // get all of the rules associated with it. - let entries = - once(("".into(), usize::MAX)) - .chain(selectors) - .filter_map(move |selector| { - let rule = match node_actor.style_rules.borrow_mut().entry(selector) { - Entry::Vacant(e) => { - let name = registry.new_name("style-rule"); - let actor = StyleRuleActor::new( - name.clone(), - node_actor.name(), - (!e.key().0.is_empty()).then_some(e.key().clone()), - ); - let rule = actor.applied(registry)?; - registry.register_later(Box::new(actor)); - e.insert(name); - rule - }, - Entry::Occupied(e) => { - let actor = registry.find::(e.get()); - actor.applied(registry)? - }, - }; - if inherited.is_some() && rule.declarations.is_empty() { - return None; - } + once(("".into(), usize::MAX)) + .chain(selectors) + .filter_map(move |selector| { + let rule = match node_actor.style_rules.borrow_mut().entry(selector) { + Entry::Vacant(e) => { + let name = registry.new_name("style-rule"); + let actor = StyleRuleActor::new( + name.clone(), + node_actor.name(), + (!e.key().0.is_empty()).then_some(e.key().clone()), + ); + let rule = actor.applied(registry)?; - Some(AppliedEntry { - rule, - // TODO: Handle pseudo elements - pseudo_element: None, - is_system: false, - inherited: inherited.clone(), - }) - }); - entries + registry.register_later(Box::new(actor)); + e.insert(name); + rule + }, + Entry::Occupied(e) => { + let actor = registry.find::(e.get()); + actor.applied(registry)? + }, + }; + if inherited.is_some() && rule.declarations.is_empty() { + return None; + } + + Some(AppliedEntry { + rule, + // TODO: Handle pseudo elements + pseudo_element: None, + is_system: false, + inherited: inherited.clone(), + }) + }) }) .collect(); let msg = GetAppliedReply { diff --git a/components/fonts/font_context.rs b/components/fonts/font_context.rs index a7df1ae3068..eb57075ffa7 100644 --- a/components/fonts/font_context.rs +++ b/components/fonts/font_context.rs @@ -320,7 +320,7 @@ impl FontContext { font_key }); - let key = *self + *self .webrender_font_instance_keys .write() .entry((font_key, pt_size, variations.clone())) @@ -334,8 +334,7 @@ impl FontContext { variations, ); font_instance_key - }); - key + }) } fn invalidate_font_groups_after_web_font_load(&self) { diff --git a/components/fonts/glyph.rs b/components/fonts/glyph.rs index 954d30da560..f5457c1127a 100644 --- a/components/fonts/glyph.rs +++ b/components/fonts/glyph.rs @@ -606,7 +606,7 @@ impl GlyphStore { pub fn iter_glyphs_for_byte_range( &self, range: &Range, - ) -> impl Iterator + use<'_> { + ) -> impl Iterator> + use<'_> { if range.begin() >= self.len() { panic!("iter_glyphs_for_range: range.begin beyond length!"); } diff --git a/components/hyper_serde/lib.rs b/components/hyper_serde/lib.rs index 663faab8904..fc786035b54 100644 --- a/components/hyper_serde/lib.rs +++ b/components/hyper_serde/lib.rs @@ -431,6 +431,10 @@ impl Serialize for Ser<'_, HeaderMap> { { let mut serializer = serializer.serialize_seq(Some(self.0.len()))?; for v in self.0 { + #[allow( + clippy::collapsible_if, + reason = "let chains are not available in 1.85" + )] if self.1 { if let Ok(v) = str::from_utf8(v) { serializer.serialize_element(v)?; diff --git a/components/layout/flexbox/layout.rs b/components/layout/flexbox/layout.rs index a76cedcff25..3f94f01528f 100644 --- a/components/layout/flexbox/layout.rs +++ b/components/layout/flexbox/layout.rs @@ -1001,7 +1001,7 @@ impl FlexContainer { } #[inline] - pub(crate) fn layout_style(&self) -> LayoutStyle { + pub(crate) fn layout_style(&self) -> LayoutStyle<'_> { LayoutStyle::Default(&self.style) } } @@ -2046,7 +2046,7 @@ impl FlexItemBox { content_box_sizes_and_pbm: &ContentBoxSizesAndPBM, config: &FlexContainerConfig, flex_context_getter: &impl Fn() -> &'a FlexContext<'a>, - ) -> FlexItem { + ) -> FlexItem<'_> { let flex_axis = config.flex_axis; let style = self.style(); let cross_axis_is_item_block_axis = cross_axis_is_item_block_axis( diff --git a/components/layout/flexbox/mod.rs b/components/layout/flexbox/mod.rs index ac51a86fcfe..4c477937306 100644 --- a/components/layout/flexbox/mod.rs +++ b/components/layout/flexbox/mod.rs @@ -151,6 +151,7 @@ impl FlexContainer { } } +#[allow(clippy::large_enum_variant)] #[derive(Debug, MallocSizeOf)] pub(crate) enum FlexLevelBox { FlexItem(FlexItemBox), diff --git a/components/layout/flow/inline/inline_box.rs b/components/layout/flow/inline/inline_box.rs index 960c489349d..26e8befeca9 100644 --- a/components/layout/flow/inline/inline_box.rs +++ b/components/layout/flow/inline/inline_box.rs @@ -66,7 +66,7 @@ impl InlineBox { } #[inline] - pub(crate) fn layout_style(&self) -> LayoutStyle { + pub(crate) fn layout_style(&self) -> LayoutStyle<'_> { LayoutStyle::Default(&self.base.style) } diff --git a/components/layout/formatting_contexts.rs b/components/layout/formatting_contexts.rs index 9b52a8888b9..5e989822a2b 100644 --- a/components/layout/formatting_contexts.rs +++ b/components/layout/formatting_contexts.rs @@ -355,7 +355,7 @@ impl IndependentFormattingContext { } #[inline] - pub(crate) fn layout_style(&self) -> LayoutStyle { + pub(crate) fn layout_style(&self) -> LayoutStyle<'_> { match &self.contents { IndependentFormattingContextContents::Replaced(fc) => fc.layout_style(&self.base), IndependentFormattingContextContents::Flow(fc) => fc.layout_style(&self.base), diff --git a/components/layout/layout_impl.rs b/components/layout/layout_impl.rs index 3c82c9734b2..869f34c6269 100644 --- a/components/layout/layout_impl.rs +++ b/components/layout/layout_impl.rs @@ -997,9 +997,11 @@ impl LayoutThread { } let root_node = root_element.as_node(); - let damage_from_environment = viewport_changed - .then_some(RestyleDamage::RELAYOUT) - .unwrap_or_default(); + let damage_from_environment = if viewport_changed { + RestyleDamage::RELAYOUT + } else { + Default::default() + }; let damage = compute_damage_and_repair_style( &layout_context.style_context, root_node.to_threadsafe(), diff --git a/components/layout/table/construct.rs b/components/layout/table/construct.rs index 55dbf0d5e95..97d312645f5 100644 --- a/components/layout/table/construct.rs +++ b/components/layout/table/construct.rs @@ -3,7 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::borrow::Cow; -use std::iter::repeat; +use std::iter::repeat_n; use atomic_refcell::AtomicRef; use layout_api::wrapper_traits::ThreadSafeLayoutNode; @@ -1165,6 +1165,6 @@ fn add_column( shared_background_style: SharedStyle::new(column_info.style.clone()), }) }); - collection.extend(repeat(column.clone()).take(span as usize)); + collection.extend(repeat_n(column.clone(), span as usize)); column } diff --git a/components/layout/table/layout.rs b/components/layout/table/layout.rs index d53b862b9b1..c85857e5d38 100644 --- a/components/layout/table/layout.rs +++ b/components/layout/table/layout.rs @@ -2754,21 +2754,21 @@ impl Table { } #[inline] - pub(crate) fn layout_style_for_grid(&self) -> LayoutStyle { + pub(crate) fn layout_style_for_grid(&self) -> LayoutStyle<'_> { LayoutStyle::Default(&self.grid_style) } } impl TableTrack { #[inline] - pub(crate) fn layout_style(&self) -> LayoutStyle { + pub(crate) fn layout_style(&self) -> LayoutStyle<'_> { LayoutStyle::Default(&self.base.style) } } impl TableTrackGroup { #[inline] - pub(crate) fn layout_style(&self) -> LayoutStyle { + pub(crate) fn layout_style(&self) -> LayoutStyle<'_> { LayoutStyle::Default(&self.base.style) } } @@ -2806,7 +2806,7 @@ impl TableLayoutStyle<'_> { impl TableSlotCell { #[inline] - fn layout_style(&self) -> LayoutStyle { + fn layout_style(&self) -> LayoutStyle<'_> { self.contents.layout_style(&self.base) } diff --git a/components/layout/taffy/layout.rs b/components/layout/taffy/layout.rs index 95e4bf8a7b6..10eb59f8b65 100644 --- a/components/layout/taffy/layout.rs +++ b/components/layout/taffy/layout.rs @@ -576,7 +576,7 @@ impl TaffyContainer { } #[inline] - pub(crate) fn layout_style(&self) -> LayoutStyle { + pub(crate) fn layout_style(&self) -> LayoutStyle<'_> { LayoutStyle::Default(&self.style) } } diff --git a/components/layout/taffy/mod.rs b/components/layout/taffy/mod.rs index dd5f382b019..9610b88e6f2 100644 --- a/components/layout/taffy/mod.rs +++ b/components/layout/taffy/mod.rs @@ -91,6 +91,7 @@ pub(crate) struct TaffyItemBox { pub(crate) taffy_level_box: TaffyItemBoxInner, } +#[allow(clippy::large_enum_variant)] #[derive(Debug, MallocSizeOf)] pub(crate) enum TaffyItemBoxInner { InFlowBox(IndependentFormattingContext), diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index fabb63ef1be..e3471b50bb6 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -88,7 +88,7 @@ where node.layout_data().is_none() || !parent_data.damage.is_empty() } - fn shared_context(&self) -> &SharedStyleContext { + fn shared_context(&self) -> &SharedStyleContext<'_> { &self.context.style_context } } diff --git a/components/media/lib.rs b/components/media/lib.rs index bf1160956c1..82774d298ef 100644 --- a/components/media/lib.rs +++ b/components/media/lib.rs @@ -214,7 +214,7 @@ impl GLPlayerExternalImages { } impl WebrenderExternalImageApi for GLPlayerExternalImages { - fn lock(&mut self, id: u64) -> (ExternalImageSource, Size2D) { + fn lock(&mut self, id: u64) -> (ExternalImageSource<'_>, Size2D) { // The GLPlayerMsgForward::Lock message inserts a fence in the // GLPlayer command queue. self.glplayer_channel diff --git a/components/net/decoder.rs b/components/net/decoder.rs index 65399cc2bbc..d572b1e2b67 100644 --- a/components/net/decoder.rs +++ b/components/net/decoder.rs @@ -285,7 +285,7 @@ impl Stream for BodyStream { return Poll::Ready(None); } } - Poll::Ready(Some(Err(io::Error::new(io::ErrorKind::Other, err)))) + Poll::Ready(Some(Err(io::Error::other(err)))) }, None => Poll::Ready(None), } diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 0f270695f1e..b77960fc772 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -832,7 +832,7 @@ fn create_about_memory(url: ServoUrl, timing_type: ResourceTimingType) -> Respon /// Handle a request from the user interface to ignore validation errors for a certificate. fn handle_allowcert_request(request: &mut Request, context: &FetchContext) -> io::Result<()> { - let error = |string| Err(io::Error::new(io::ErrorKind::Other, string)); + let error = |string| Err(io::Error::other(string)); let body = match request.body.as_mut() { Some(body) => body, diff --git a/components/net/hosts.rs b/components/net/hosts.rs index 48b74bba154..1d83957eea3 100644 --- a/components/net/hosts.rs +++ b/components/net/hosts.rs @@ -49,7 +49,7 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap { .collect() } -pub fn replace_host(host: &str) -> Cow { +pub fn replace_host(host: &str) -> Cow<'_, str> { HOST_TABLE .lock() .unwrap() diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 4d0a07177d4..540c2dd8ed2 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -2017,7 +2017,7 @@ async fn http_network_fetch( .iter() .map(|header_value| header_value.to_str().unwrap_or("")) .collect(); - let wildcard_present = header_strings.iter().any(|header_str| *header_str == "*"); + let wildcard_present = header_strings.contains(&"*"); // The spec: https://www.w3.org/TR/resource-timing-2/#sec-timing-allow-origin // says that a header string is either an origin or a wildcard so we can just do a straight // check against the document origin diff --git a/components/net/indexeddb/engines/sqlite/database_model.rs b/components/net/indexeddb/engines/sqlite/database_model.rs index ea512bfef99..0d3528c94b9 100644 --- a/components/net/indexeddb/engines/sqlite/database_model.rs +++ b/components/net/indexeddb/engines/sqlite/database_model.rs @@ -12,6 +12,7 @@ pub enum Column { Version, } +#[allow(dead_code)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct Model { pub name: String, diff --git a/components/net/indexeddb/engines/sqlite/object_store_index_model.rs b/components/net/indexeddb/engines/sqlite/object_store_index_model.rs index 4b4f201669e..1a4490327ea 100644 --- a/components/net/indexeddb/engines/sqlite/object_store_index_model.rs +++ b/components/net/indexeddb/engines/sqlite/object_store_index_model.rs @@ -14,6 +14,7 @@ pub enum Column { MultiEntryIndex, } +#[allow(dead_code)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct Model { pub id: i32, diff --git a/components/net/websocket_loader.rs b/components/net/websocket_loader.rs index 26cdf9bc50f..3a83eac08ad 100644 --- a/components/net/websocket_loader.rs +++ b/components/net/websocket_loader.rs @@ -48,6 +48,8 @@ use crate::fetch::methods::{ }; use crate::hosts::replace_host; use crate::http_loader::HttpState; + +#[allow(clippy::result_large_err)] /// Create a tungstenite Request object for the initial HTTP request. /// This request contains `Origin`, `Sec-WebSocket-Protocol`, `Authorization`, /// and `Cookie` headers as appropriate. @@ -105,6 +107,7 @@ fn create_request( Ok(request) } +#[allow(clippy::result_large_err)] /// Process an HTTP response resulting from a WS handshake. /// This ensures that any `Cookie` or HSTS headers are recognized. /// Returns an error if the protocol selected by the handshake doesn't diff --git a/components/pixels/lib.rs b/components/pixels/lib.rs index 6f49b7bad52..016927e909a 100644 --- a/components/pixels/lib.rs +++ b/components/pixels/lib.rs @@ -149,7 +149,7 @@ pub fn flip_y_rgba8_image_inplace(size: Size2D, pixels: &mut [u8]) { } } -pub fn rgba8_get_rect(pixels: &[u8], size: Size2D, rect: Rect) -> Cow<[u8]> { +pub fn rgba8_get_rect(pixels: &[u8], size: Size2D, rect: Rect) -> Cow<'_, [u8]> { assert!(!rect.is_empty()); assert!(Rect::from_size(size).contains_rect(&rect)); assert_eq!(pixels.len() % 4, 0); @@ -311,7 +311,7 @@ impl RasterImage { self.frames.len() > 1 } - pub fn frames(&self) -> impl Iterator { + pub fn frames(&self) -> impl Iterator> { self.frames.iter().map(|frame| ImageFrameView { delay: frame.delay, bytes: self.bytes.get(frame.byte_range.clone()).unwrap(), @@ -320,7 +320,7 @@ impl RasterImage { }) } - pub fn first_frame(&self) -> ImageFrameView { + pub fn first_frame(&self) -> ImageFrameView<'_> { self.frames() .next() .expect("All images should have at least one frame") diff --git a/components/script/dom/abstractrange.rs b/components/script/dom/abstractrange.rs index e3f58e1e826..8fd0cf9e750 100644 --- a/components/script/dom/abstractrange.rs +++ b/components/script/dom/abstractrange.rs @@ -45,7 +45,7 @@ impl AbstractRange { end_offset: u32, can_gc: CanGc, ) -> DomRoot { - let abstractrange = reflect_dom_object( + reflect_dom_object( Box::new(AbstractRange::new_inherited( start_container, start_offset, @@ -54,8 +54,7 @@ impl AbstractRange { )), document.window(), can_gc, - ); - abstractrange + ) } pub(crate) fn start(&self) -> &BoundaryPoint { diff --git a/components/script/dom/abstractworkerglobalscope.rs b/components/script/dom/abstractworkerglobalscope.rs index 8282d586993..89676edc9c8 100644 --- a/components/script/dom/abstractworkerglobalscope.rs +++ b/components/script/dom/abstractworkerglobalscope.rs @@ -21,7 +21,10 @@ pub(crate) trait WorkerEventLoopMethods { type Event; fn task_queue(&self) -> &TaskQueue; fn handle_event(&self, event: Self::Event, can_gc: CanGc) -> bool; - fn handle_worker_post_event(&self, worker: &TrustedWorkerAddress) -> Option; + fn handle_worker_post_event( + &self, + worker: &TrustedWorkerAddress, + ) -> Option>; fn from_control_msg(msg: Self::ControlMsg) -> Self::Event; fn from_worker_msg(msg: Self::WorkerMsg) -> Self::Event; fn from_devtools_msg(msg: DevtoolScriptControlMsg) -> Self::Event; diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 08870e60ae5..5f0294174eb 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -198,7 +198,7 @@ impl Attr { &self.identifier } - pub(crate) fn value(&self) -> Ref { + pub(crate) fn value(&self) -> Ref<'_, AttrValue> { self.value.borrow() } diff --git a/components/script/dom/audiobuffer.rs b/components/script/dom/audiobuffer.rs index 2df9ef5327f..025a608bacd 100644 --- a/components/script/dom/audiobuffer.rs +++ b/components/script/dom/audiobuffer.rs @@ -179,7 +179,7 @@ impl AudioBuffer { Some(result) } - pub(crate) fn get_channels(&self) -> Ref> { + pub(crate) fn get_channels(&self) -> Ref<'_, Option> { if self.shared_channels.borrow().is_none() { let channels = self.acquire_contents(); if channels.is_some() { diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index 2ef7bce981b..0e24c8c2fcd 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -531,7 +531,7 @@ impl BaseAudioContextMethods for BaseAudioContext { task_source.queue(task!(audio_decode_eos: move || { let this = this.root(); let decoded_audio = decoded_audio__.lock().unwrap(); - let length = if decoded_audio.len() >= 1 { + let length = if !decoded_audio.is_empty() { decoded_audio[0].len() } else { 0 diff --git a/components/script/dom/bindings/buffer_source.rs b/components/script/dom/bindings/buffer_source.rs index a271cad5643..551cf044eb2 100644 --- a/components/script/dom/bindings/buffer_source.rs +++ b/components/script/dom/bindings/buffer_source.rs @@ -887,7 +887,7 @@ impl DataBlock { *cx, range.end - range.start, // SAFETY: This is safe because we have checked there is no overlapping view - (*raw)[range.clone()].as_mut_ptr() as _, + (&mut (*raw))[range.clone()].as_mut_ptr() as _, Some(free_func), raw as _, ) diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index ce050b482a9..8a87a5b5ba8 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -111,7 +111,7 @@ impl DomRefCell { /// /// Panics if the value is currently mutably borrowed. #[track_caller] - pub(crate) fn borrow(&self) -> Ref { + pub(crate) fn borrow(&self) -> Ref<'_, T> { self.value.borrow() } @@ -124,7 +124,7 @@ impl DomRefCell { /// /// Panics if the value is currently borrowed. #[track_caller] - pub(crate) fn borrow_mut(&self) -> RefMut { + pub(crate) fn borrow_mut(&self) -> RefMut<'_, T> { self.value.borrow_mut() } @@ -138,7 +138,7 @@ impl DomRefCell { /// # Panics /// /// Panics if this is called off the script thread. - pub(crate) fn try_borrow(&self) -> Result, BorrowError> { + pub(crate) fn try_borrow(&self) -> Result, BorrowError> { assert_in_script(); self.value.try_borrow() } @@ -153,7 +153,7 @@ impl DomRefCell { /// # Panics /// /// Panics if this is called off the script thread. - pub(crate) fn try_borrow_mut(&self) -> Result, BorrowMutError> { + pub(crate) fn try_borrow_mut(&self) -> Result, BorrowMutError> { assert_in_script(); self.value.try_borrow_mut() } diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index 096950c2f1f..052b8dbccc1 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -114,8 +114,7 @@ impl TrustedPromise { self.owner_thread, live_references as *const _ as *const libc::c_void ); - // Borrow-check error requires the redundant `let promise = ...; promise` here. - let promise = match live_references + match live_references .promise_table .borrow_mut() .entry(self.dom_object) @@ -133,8 +132,7 @@ impl TrustedPromise { promise }, Vacant(_) => unreachable!(), - }; - promise + } }) } diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 599254a5ad5..e03c7392471 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -64,11 +64,11 @@ pub(crate) trait ToLayout { /// # Safety /// /// The `self` parameter to this method must meet all the requirements of [`ptr::NonNull::as_ref`]. - unsafe fn to_layout(&self) -> LayoutDom; + unsafe fn to_layout(&self) -> LayoutDom<'_, T>; } impl ToLayout for Dom { - unsafe fn to_layout(&self) -> LayoutDom { + unsafe fn to_layout(&self) -> LayoutDom<'_, T> { assert_in_layout(); LayoutDom { value: unsafe { self.as_ptr().as_ref().unwrap() }, @@ -266,7 +266,7 @@ impl MutNullableDom { /// Retrieve a copy of the inner optional `Dom` as `LayoutDom`. /// For use by layout, which can't use safe types like Temporary. #[cfg_attr(crown, allow(crown::unrooted_must_root))] - pub(crate) unsafe fn get_inner_as_layout(&self) -> Option> { + pub(crate) unsafe fn get_inner_as_layout(&self) -> Option> { assert_in_layout(); unsafe { (*self.ptr.get()).as_ref().map(|js| js.to_layout()) } } diff --git a/components/script/dom/bluetooth/bluetooth.rs b/components/script/dom/bluetooth/bluetooth.rs index b43a41a7c3b..02bcadaee92 100644 --- a/components/script/dom/bluetooth/bluetooth.rs +++ b/components/script/dom/bluetooth/bluetooth.rs @@ -87,7 +87,7 @@ impl BluetoothExtraPermissionData { self.allowed_devices.borrow_mut().push(allowed_device); } - fn get_allowed_devices(&self) -> Ref> { + fn get_allowed_devices(&self) -> Ref<'_, Vec> { self.allowed_devices.borrow() } diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index afe24148447..fa0e9fe537c 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -73,7 +73,7 @@ impl CharacterData { } #[inline] - pub(crate) fn data(&self) -> Ref { + pub(crate) fn data(&self) -> Ref<'_, DOMString> { self.data.borrow() } diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 3b89537d8dc..93df19026e8 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -76,8 +76,7 @@ impl CSSStyleOwner { let document = el.owner_document(); let shared_lock = document.style_shared_lock(); let mut attr = el.style_attribute().borrow_mut().take(); - let result = if attr.is_some() { - let lock = attr.as_ref().unwrap(); + let result = if let Some(lock) = attr.as_ref() { let mut guard = shared_lock.write(); let pdb = lock.write_with(&mut guard); f(pdb, &mut changed) diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index 6bd9db4ae08..c7f9797157d 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -591,16 +591,13 @@ impl CustomElementRegistryMethods for CustomElementRegistr return promise; } - // Steps 3, 4, 5 + // Steps 3, 4, 5, 6 let existing_promise = self.when_defined.borrow().get(&name).cloned(); - let promise = existing_promise.unwrap_or_else(|| { + existing_promise.unwrap_or_else(|| { let promise = Promise::new_in_current_realm(comp, can_gc); self.when_defined.borrow_mut().insert(name, promise.clone()); promise - }); - - // Step 6 - promise + }) } /// fn Upgrade(&self, node: &Node) { diff --git a/components/script/dom/datatransfer.rs b/components/script/dom/datatransfer.rs index defdbebc3e9..73b6d4a4d43 100644 --- a/components/script/dom/datatransfer.rs +++ b/components/script/dom/datatransfer.rs @@ -85,7 +85,7 @@ impl DataTransfer { Self::new_with_proto(window, None, can_gc, data_store) } - pub(crate) fn data_store(&self) -> Option> { + pub(crate) fn data_store(&self) -> Option> { Ref::filter_map(self.data_store.borrow(), |data_store| data_store.as_ref()).ok() } } diff --git a/components/script/dom/datatransferitem.rs b/components/script/dom/datatransferitem.rs index 41385f31ce9..3269fcdafc5 100644 --- a/components/script/dom/datatransferitem.rs +++ b/components/script/dom/datatransferitem.rs @@ -63,7 +63,7 @@ impl DataTransferItem { ) } - fn item_kind(&self) -> Option> { + fn item_kind(&self) -> Option> { Ref::filter_map(self.data_store.borrow(), |data_store| { data_store .as_ref() diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 96a3ecb7c9c..59aa4d17bf3 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -232,7 +232,10 @@ impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope { self.handle_mixed_message(event, can_gc) } - fn handle_worker_post_event(&self, worker: &TrustedWorkerAddress) -> Option { + fn handle_worker_post_event( + &self, + worker: &TrustedWorkerAddress, + ) -> Option> { let ar = AutoWorkerReset::new(self, worker.clone()); Some(ar) } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 89aa7a7deaa..044f66c276e 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -662,12 +662,12 @@ impl Document { } #[inline] - pub(crate) fn loader(&self) -> Ref { + pub(crate) fn loader(&self) -> Ref<'_, DocumentLoader> { self.loader.borrow() } #[inline] - pub(crate) fn loader_mut(&self) -> RefMut { + pub(crate) fn loader_mut(&self) -> RefMut<'_, DocumentLoader> { self.loader.borrow_mut() } @@ -1755,7 +1755,7 @@ impl Document { } } - pub(crate) fn policy_container(&self) -> Ref { + pub(crate) fn policy_container(&self) -> Ref<'_, PolicyContainer> { self.policy_container.borrow() } @@ -2385,14 +2385,14 @@ impl Document { /// A reference to the [`IFrameCollection`] of this [`Document`], holding information about /// `