From 889e5a96f23e7fc00dbd7f44fa4b609e859bbc3a Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 8 Jan 2020 15:40:47 +0000 Subject: [PATCH] Bug 1607697 - Address unwrap_or_else(callback) and functions in callback clippy lints. r=Gankro I don't think it makes much of a difference but clippy is quite vocal about it. Differential Revision: https://phabricator.services.mozilla.com/D59114 --HG-- extra : moz-landing-system : lando --- gfx/wr/webrender/src/image.rs | 2 +- gfx/wr/webrender/src/lib.rs | 3 +++ gfx/wr/webrender/src/picture.rs | 8 ++++---- gfx/wr/webrender/src/render_task.rs | 8 ++++---- gfx/wr/webrender/src/resource_cache.rs | 4 ++-- gfx/wr/webrender/src/scene_building.rs | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gfx/wr/webrender/src/image.rs b/gfx/wr/webrender/src/image.rs index 74298b88bdfb..825afc269ca0 100644 --- a/gfx/wr/webrender/src/image.rs +++ b/gfx/wr/webrender/src/image.rs @@ -600,7 +600,7 @@ pub fn compute_valid_tiles_if_bounds_change( return Some(TileRange::zero()); } - let intersection = intersection.unwrap_or(DeviceIntRect::zero()); + let intersection = intersection.unwrap_or_else(DeviceIntRect::zero); let left = prev_rect.min_x() != new_rect.min_x(); let right = prev_rect.max_x() != new_rect.max_x(); diff --git a/gfx/wr/webrender/src/lib.rs b/gfx/wr/webrender/src/lib.rs index cec3f723e9bc..23f7ae2804c3 100644 --- a/gfx/wr/webrender/src/lib.rs +++ b/gfx/wr/webrender/src/lib.rs @@ -41,6 +41,9 @@ doesn't only contain trivial geometry, it can also store another [stacking_contexts]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context */ +#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal, clippy::new_without_default, clippy::too_many_arguments))] + + // Cribbed from the |matches| crate, for simplicity. macro_rules! matches { ($expression:expr, $($pattern:tt)+) => { diff --git a/gfx/wr/webrender/src/picture.rs b/gfx/wr/webrender/src/picture.rs index 916eaef6be50..3048124df0e4 100644 --- a/gfx/wr/webrender/src/picture.rs +++ b/gfx/wr/webrender/src/picture.rs @@ -742,7 +742,7 @@ impl Tile { self.clipped_rect = self.rect .intersection(&ctx.local_rect) .and_then(|r| r.intersection(&ctx.local_clip_rect)) - .unwrap_or(PictureRect::zero()); + .unwrap_or_else(PictureRect::zero); self.world_rect = ctx.pic_to_world_mapper .map(&self.rect) @@ -938,7 +938,7 @@ impl Tile { // Ensure that the dirty rect doesn't extend outside the local tile rect. self.dirty_rect = self.dirty_rect .intersection(&self.rect) - .unwrap_or(PictureRect::zero()); + .unwrap_or_else(PictureRect::zero); // See if this tile is a simple color, in which case we can just draw // it as a rect, and avoid allocating a texture surface and drawing it. @@ -1828,7 +1828,7 @@ impl TileCacheInstance { let needed_rect_in_pic_space = desired_rect_in_pic_space .intersection(&pic_rect) - .unwrap_or(PictureRect::zero()); + .unwrap_or_else(PictureRect::zero); let p0 = needed_rect_in_pic_space.origin; let p1 = needed_rect_in_pic_space.bottom_right(); @@ -3611,7 +3611,7 @@ impl PicturePrimitive { // the tile rects below for occlusion testing to the relevant area. let local_clip_rect = tile_cache.local_rect .intersection(&tile_cache.local_clip_rect) - .unwrap_or(PictureRect::zero()); + .unwrap_or_else(PictureRect::zero); let world_clip_rect = map_pic_to_world .map(&local_clip_rect) diff --git a/gfx/wr/webrender/src/render_task.rs b/gfx/wr/webrender/src/render_task.rs index 445babac5800..d4e535a16dcf 100644 --- a/gfx/wr/webrender/src/render_task.rs +++ b/gfx/wr/webrender/src/render_task.rs @@ -1452,7 +1452,7 @@ impl RenderTask { if let RenderTaskKind::SvgFilter(ref mut filter_task) = self.kind { match filter_task.info { SvgFilterInfo::ColorMatrix(ref matrix) => { - let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new()); + let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new); if let Some(mut request) = gpu_cache.request(handle) { for i in 0..5 { request.push([matrix[i*4], matrix[i*4+1], matrix[i*4+2], matrix[i*4+3]]); @@ -1461,20 +1461,20 @@ impl RenderTask { } SvgFilterInfo::DropShadow(color) | SvgFilterInfo::Flood(color) => { - let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new()); + let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new); if let Some(mut request) = gpu_cache.request(handle) { request.push(color.to_array()); } } SvgFilterInfo::ComponentTransfer(ref data) => { - let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new()); + let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new); if let Some(request) = gpu_cache.request(handle) { data.update(request); } } SvgFilterInfo::Composite(ref operator) => { if let CompositeOperator::Arithmetic(k_vals) = operator { - let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(|| GpuCacheHandle::new()); + let handle = filter_task.extra_gpu_cache_handle.get_or_insert_with(GpuCacheHandle::new); if let Some(mut request) = gpu_cache.request(handle) { request.push(*k_vals); } diff --git a/gfx/wr/webrender/src/resource_cache.rs b/gfx/wr/webrender/src/resource_cache.rs index 16ec7bb48fbf..3a431dc7ab33 100644 --- a/gfx/wr/webrender/src/resource_cache.rs +++ b/gfx/wr/webrender/src/resource_cache.rs @@ -937,7 +937,7 @@ impl ResourceCache { tile, ).into(); - rect.intersection(&tile_rect).unwrap_or(DeviceIntRect::zero()) + rect.intersection(&tile_rect).unwrap_or_else(DeviceIntRect::zero) }) } (None, Some(..)) => DirtyRect::All, @@ -1020,7 +1020,7 @@ impl ResourceCache { match (image.valid_tiles_after_bounds_change, valid_tiles_after_bounds_change) { (Some(old), Some(ref mut new)) => { - *new = new.intersection(&old).unwrap_or(TileRange::zero()); + *new = new.intersection(&old).unwrap_or_else(TileRange::zero); } (Some(old), None) => { valid_tiles_after_bounds_change = Some(old); diff --git a/gfx/wr/webrender/src/scene_building.rs b/gfx/wr/webrender/src/scene_building.rs index 23059f6a3256..d227a5b9fcf9 100644 --- a/gfx/wr/webrender/src/scene_building.rs +++ b/gfx/wr/webrender/src/scene_building.rs @@ -664,7 +664,7 @@ impl<'a> SceneBuilder<'a> { scroll_root, slice.prim_list, background_color, - slice.shared_clips.unwrap_or(Vec::new()), + slice.shared_clips.unwrap_or_else(Vec::new), &mut self.interners, &mut self.prim_store, &mut self.clip_store,