From ea5cf751696ec8c24e7303b042d534a32c2a9a24 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Mon, 12 Aug 2024 22:16:47 -0700 Subject: [PATCH] clippy: Fix various clippy warnings throughout the code (#33003) * replace u64::max_value() with u64::MAX Signed-off-by: Ashwin Naren * removed redundant import Signed-off-by: Ashwin Naren * Fixed dereference Signed-off-by: Ashwin Naren * Fixed a probable bug Signed-off-by: Ashwin Naren * fixed imports Signed-off-by: Ashwin Naren * fixed dereference Signed-off-by: Ashwin Naren * dereference formatting Signed-off-by: Ashwin Naren * removed unnessicary number imports Signed-off-by: Ashwin Naren * removed unnessicary number imports Signed-off-by: Ashwin Naren * removed excess borrow Signed-off-by: Ashwin Naren * ran mach fmt Signed-off-by: Ashwin Naren * fixed doc comment Signed-off-by: Ashwin Naren * removed deref on an immutable reference Signed-off-by: Ashwin Naren * fixed minor syntax error Signed-off-by: Ashwin Naren * reverted clamping Signed-off-by: Ashwin Naren * formatting Signed-off-by: Ashwin Naren * reverted final clamp Signed-off-by: Ashwin Naren --------- Signed-off-by: Ashwin Naren Co-authored-by: Ashwin Naren --- components/canvas/webgl_thread.rs | 4 ++-- components/compositing/compositor.rs | 4 ++-- components/devtools/actors/inspector/accessibility.rs | 2 +- components/devtools/actors/inspector/css_properties.rs | 2 +- components/devtools/actors/inspector/node.rs | 2 +- components/devtools/actors/inspector/walker.rs | 2 +- components/devtools/actors/tab.rs | 2 +- components/devtools/actors/watcher.rs | 10 +++++----- components/fonts/glyph.rs | 2 +- components/layout/inline.rs | 2 +- components/layout_2020/display_list/mod.rs | 2 +- components/layout_2020/flexbox/layout.rs | 4 ++-- .../layout_2020/fragment_tree/containing_block.rs | 3 ++- components/net/http_cache.rs | 8 ++------ components/profile/time.rs | 2 +- components/rand/lib.rs | 1 - components/shared/webrender/rendering_context.rs | 2 +- 17 files changed, 25 insertions(+), 29 deletions(-) diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index 1ab3ce95bb3..95cd5758586 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -2878,8 +2878,8 @@ fn flip_pixels_y( // Clamp a size to the current GL context's max viewport fn clamp_viewport(gl: &Gl, size: Size2D) -> Size2D { - let mut max_viewport = [i32::max_value(), i32::max_value()]; - let mut max_renderbuffer = [i32::max_value()]; + let mut max_viewport = [i32::MAX, i32::MAX]; + let mut max_renderbuffer = [i32::MAX]; #[allow(unsafe_code)] unsafe { gl.get_integer_v(gl::MAX_VIEWPORT_DIMS, &mut max_viewport); diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 60505911e7d..4f4be0cfeda 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -1824,9 +1824,9 @@ impl IOCompositor { if previous_pipeline_id.replace(pipeline_id) != Some(pipeline_id) { let scroll_result = self .pipeline_details - .get_mut(&pipeline_id)? + .get_mut(pipeline_id)? .scroll_tree - .scroll_node_or_ancestor(&scroll_tree_node, scroll_location); + .scroll_node_or_ancestor(scroll_tree_node, scroll_location); if let Some((external_id, offset)) = scroll_result { return Some((*pipeline_id, external_id, offset)); } diff --git a/components/devtools/actors/inspector/accessibility.rs b/components/devtools/actors/inspector/accessibility.rs index f5a40b9995e..2b4ccb0e33e 100644 --- a/components/devtools/actors/inspector/accessibility.rs +++ b/components/devtools/actors/inspector/accessibility.rs @@ -72,7 +72,7 @@ impl Actor for AccessibilityActor { /// - `getTraits`: Informs the DevTools client about the configuration of the accessibility actor /// /// - `getWalker`: Returns a new AccessibleWalker actor (not to be confused with the general - /// inspector Walker actor) + /// inspector Walker actor) fn handle_message( &self, registry: &ActorRegistry, diff --git a/components/devtools/actors/inspector/css_properties.rs b/components/devtools/actors/inspector/css_properties.rs index cdd27b82b38..0b411292189 100644 --- a/components/devtools/actors/inspector/css_properties.rs +++ b/components/devtools/actors/inspector/css_properties.rs @@ -42,7 +42,7 @@ impl Actor for CssPropertiesActor { /// The css properties actor can handle the following messages: /// /// - `getCSSDatabase`: Returns a big list of every supported css property so that the - /// inspector can show the available options + /// inspector can show the available options fn handle_message( &self, _registry: &ActorRegistry, diff --git a/components/devtools/actors/inspector/node.rs b/components/devtools/actors/inspector/node.rs index 845d394ffaa..650b0c6bf54 100644 --- a/components/devtools/actors/inspector/node.rs +++ b/components/devtools/actors/inspector/node.rs @@ -89,7 +89,7 @@ impl Actor for NodeActor { /// The node actor can handle the following messages: /// /// - `modifyAttributes`: Asks the script to change a value in the attribute of the - /// corresponding node + /// corresponding node /// /// - `getUniqueSelector`: Returns the display name of this node fn handle_message( diff --git a/components/devtools/actors/inspector/walker.rs b/components/devtools/actors/inspector/walker.rs index 8589fd1a494..72ddd01209c 100644 --- a/components/devtools/actors/inspector/walker.rs +++ b/components/devtools/actors/inspector/walker.rs @@ -120,7 +120,7 @@ impl Actor for WalkerActor { /// - `getOffsetParent`: Placeholder /// /// - `querySelector`: Recursively looks for the specified selector in the tree, reutrning the - /// node and its ascendents + /// node and its ascendents fn handle_message( &self, registry: &ActorRegistry, diff --git a/components/devtools/actors/tab.rs b/components/devtools/actors/tab.rs index e6538e38a38..b4c228d9559 100644 --- a/components/devtools/actors/tab.rs +++ b/components/devtools/actors/tab.rs @@ -77,7 +77,7 @@ impl Actor for TabDescriptorActor { /// - `getFavicon`: Should return the tab favicon, but it is not yet supported. /// /// - `getWatcher`: Returns a `WatcherActor` linked to the tab's `BrowsingContext`. It is used - /// to describe the debugging capabilities of this tab. + /// to describe the debugging capabilities of this tab. fn handle_message( &self, registry: &ActorRegistry, diff --git a/components/devtools/actors/watcher.rs b/components/devtools/actors/watcher.rs index 55a19da8039..55358067b5b 100644 --- a/components/devtools/actors/watcher.rs +++ b/components/devtools/actors/watcher.rs @@ -160,17 +160,17 @@ impl Actor for WatcherActor { /// The watcher actor can handle the following messages: /// /// - `watchTargets`: Returns a list of objects to debug. Since we only support web views, it - /// returns the associated `BrowsingContextActor`. Every target sent creates a - /// `target-available-form` event. + /// returns the associated `BrowsingContextActor`. Every target sent creates a + /// `target-available-form` event. /// /// - `watchResources`: Start watching certain resource types. This sends - /// `resource-available-form` events. + /// `resource-available-form` events. /// /// - `getNetworkParentActor`: Returns the network parent actor. It doesn't seem to do much at - /// the moment. + /// the moment. /// /// - `getTargetConfigurationActor`: Returns the configuration actor for a specific target, so - /// that the server can update its settings. + /// that the server can update its settings. /// /// - `getThreadConfigurationActor`: The same but with the configuration actor for the thread fn handle_message( diff --git a/components/fonts/glyph.rs b/components/fonts/glyph.rs index 420d43b0774..450478ea5ae 100644 --- a/components/fonts/glyph.rs +++ b/components/fonts/glyph.rs @@ -5,7 +5,7 @@ use std::cmp::{Ordering, PartialOrd}; use std::sync::Arc; use std::vec::Vec; -use std::{fmt, mem, u16}; +use std::{fmt, mem}; use app_units::Au; use euclid::default::Point2D; diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 6d8f49d34d0..6c984b9e40f 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -5,7 +5,7 @@ use std::cmp::max; use std::collections::VecDeque; use std::sync::Arc; -use std::{fmt, i32, isize, mem}; +use std::{fmt, mem}; use app_units::{Au, MIN_AU}; use base::print_tree::PrintTree; diff --git a/components/layout_2020/display_list/mod.rs b/components/layout_2020/display_list/mod.rs index 0898c8dc661..657c99184e9 100644 --- a/components/layout_2020/display_list/mod.rs +++ b/components/layout_2020/display_list/mod.rs @@ -1006,7 +1006,7 @@ impl<'a> BuilderForBoxFragment<'a> { repeat_vertical: border_image_repeat.1.to_webrender(), }); builder.wr().push_border( - &common, + common, border_image_area.to_box2d(), border_image_widths, details, diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs index f4b19cd4194..581c8b4770d 100644 --- a/components/layout_2020/flexbox/layout.rs +++ b/components/layout_2020/flexbox/layout.rs @@ -220,7 +220,7 @@ impl FlexContainer { let mut item_infos = vec![]; let container_is_horizontal = self.style.writing_mode.is_horizontal(); - let flex_direction = used_flex_direction(&*self.style); + let flex_direction = used_flex_direction(&self.style); let flex_axis = FlexAxis::from(flex_direction); let flex_wrap = self.style.get_position().flex_wrap; let flex_wrap_reverse = match flex_wrap { @@ -1262,7 +1262,7 @@ impl InitialFlexLineLayout<'_> { let mut max_ascent = Au::zero(); let mut max_descent = Au::zero(); let mut max_outer_hypothetical_cross_size = Au::zero(); - for (item_result, item) in item_layout_results.iter().zip(&*items) { + for (item_result, item) in item_layout_results.iter().zip(items) { // TODO: check inline-axis is parallel to main axis, check no auto cross margins if matches!( item.align_self.0.value(), diff --git a/components/layout_2020/fragment_tree/containing_block.rs b/components/layout_2020/fragment_tree/containing_block.rs index 042c3e34a6a..f7bda18f35f 100644 --- a/components/layout_2020/fragment_tree/containing_block.rs +++ b/components/layout_2020/fragment_tree/containing_block.rs @@ -28,7 +28,8 @@ pub(crate) struct ContainingBlockManager<'a, T> { /// element is split across multiple lines, the containing block is /// undefined. /// 2. Otherwise, the containing block is formed by the padding edge of the - /// ancestor." + /// ancestor. + /// /// /// If the ancestor forms a containing block for all descendants (see below), /// this value will be None and absolute descendants will use the containing diff --git a/components/net/http_cache.rs b/components/net/http_cache.rs index 0a8db1b5e07..e9719f4cff0 100644 --- a/components/net/http_cache.rs +++ b/components/net/http_cache.rs @@ -416,7 +416,7 @@ fn handle_range_request( // whose body is in the ResponseBody::Receiving state. (&(Bound::Included(beginning), Bound::Included(end)), Some(complete_resource)) => { if let ResponseBody::Done(ref body) = *complete_resource.body.lock().unwrap() { - if end == u64::max_value() { + if end == u64::MAX { // Prevent overflow on the addition below. return None; } @@ -552,11 +552,7 @@ fn handle_range_request( } else { continue; }; - if total < res_beginning || - total < res_end || - offset == 0 || - offset == u64::max_value() - { + if total < res_beginning || total < res_end || offset == 0 || offset == u64::MAX { // Prevent overflow in the below operations from occuring. continue; } diff --git a/components/profile/time.rs b/components/profile/time.rs index f07e273735d..836cded25d4 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -9,8 +9,8 @@ use std::collections::{BTreeMap, HashMap}; use std::fs::File; use std::io::{self, Write}; use std::path::Path; +use std::thread; use std::time::Duration; -use std::{f64, thread, u32, u64}; use ipc_channel::ipc::{self, IpcReceiver}; use profile_traits::time::{ diff --git a/components/rand/lib.rs b/components/rand/lib.rs index 042736ed5af..fafd8238307 100644 --- a/components/rand/lib.rs +++ b/components/rand/lib.rs @@ -5,7 +5,6 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::Mutex; -use std::u64; use lazy_static::lazy_static; use log::trace; diff --git a/components/shared/webrender/rendering_context.rs b/components/shared/webrender/rendering_context.rs index c9f4057fd58..d72ab8ed46b 100644 --- a/components/shared/webrender/rendering_context.rs +++ b/components/shared/webrender/rendering_context.rs @@ -97,7 +97,7 @@ impl RenderingContext { let device = &mut self.0.device.borrow_mut(); let context = &self.0.context.borrow(); let surface_access = SurfaceAccess::GPUOnly; - device.create_surface(&context, surface_access, surface_type) + device.create_surface(context, surface_access, surface_type) } pub fn destroy_surface(&self, mut surface: Surface) -> Result<(), Error> {