From 5bbbf610828e975fd308b90543359a85ef59b67f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 1 Dec 2018 17:49:30 -0800 Subject: lint: Resolve the easier clippy lints Hopefully the changes are self-explanatory and uncontroversial. This eliminates much of the noise from `cargo clippy` and, for my purposes, gives me a reasonable way to use it as a tool when writing and reviewing code. Here is the Clippy invocation I was using: cargo +nightly clippy -- -W clippy::correctness -A renamed_and_removed_lints -Aclippy::{blacklisted_name,borrowed_box,cast_lossless,cast_ptr_alignment,enum_variant_names,identity_op,if_same_then_else,mut_from_ref,needless_pass_by_value,new_without_default,new_without_default_derive,or_fun_call,ptr_arg,should_implement_trait,single_match,too_many_arguments,trivially_copy_pass_by_ref,unreadable_literal,unsafe_vector_initialization,useless_transmute} TEST=cargo check --features wl-dmabuf,gpu,usb-emulation TEST=boot linux Change-Id: I55eb1b4a72beb2f762480e3333a921909314a0a2 Reviewed-on: https://chromium-review.googlesource.com/1356911 Commit-Ready: David Tolnay Tested-by: David Tolnay Reviewed-by: Dylan Reid --- gpu_buffer/src/lib.rs | 25 +++++++++---------------- gpu_buffer/src/rendernode.rs | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) (limited to 'gpu_buffer') diff --git a/gpu_buffer/src/lib.rs b/gpu_buffer/src/lib.rs index e57053d..ad8dd63 100644 --- a/gpu_buffer/src/lib.rs +++ b/gpu_buffer/src/lib.rs @@ -236,7 +236,7 @@ impl Format { DRM_FORMAT_XRGB8888 => 4, _ => return None, }; - return Some(bpp); + Some(bpp) } } @@ -576,10 +576,10 @@ impl Buffer { let line_offset = checked_arithmetic!(yy * stride)?; let src_line = src .get_slice(line_offset, line_copy_size) - .map_err(|e| Error::Memcopy(e))?; + .map_err(Error::Memcopy)?; let dst_line = dst .get_slice(line_offset, line_copy_size) - .map_err(|e| Error::Memcopy(e))?; + .map_err(Error::Memcopy)?; src_line.copy_to_volatile_slice(dst_line); } } @@ -627,13 +627,11 @@ impl Buffer { let copy_sg_size = min(sg_size, copy_size); let src_slice = sg .get_slice(src_offset, copy_sg_size) - .map_err(|e| Error::Memcopy(e))?; + .map_err(Error::Memcopy)?; src_slice.copy_to_volatile_slice(dst_slice); src_offset = 0; - dst_slice = dst_slice - .offset(copy_sg_size) - .map_err(|e| Error::Memcopy(e))?; + dst_slice = dst_slice.offset(copy_sg_size).map_err(Error::Memcopy)?; copy_size -= copy_sg_size; if copy_size == 0 { break; @@ -647,8 +645,7 @@ impl Buffer { let line_end_skip = checked_arithmetic!(stride - line_copy_size)?; let mut remaining_line_copy_size = line_copy_size; let mut sg_opt = sgs.next(); - while !sg_opt.is_none() { - let sg = sg_opt.unwrap(); + while let Some(sg) = sg_opt { // Skip src_offset into this scatter gather item, or the entire thing if offset is // larger. let sg_size = match sg.size().checked_sub(src_offset) { @@ -662,13 +659,11 @@ impl Buffer { let copy_sg_size = min(sg_size, remaining_line_copy_size); let src_slice = sg .get_slice(src_offset, copy_sg_size) - .map_err(|e| Error::Memcopy(e))?; + .map_err(Error::Memcopy)?; src_slice.copy_to_volatile_slice(dst_slice); src_offset += copy_sg_size; - dst_slice = dst_slice - .offset(copy_sg_size) - .map_err(|e| Error::Memcopy(e))?; + dst_slice = dst_slice.offset(copy_sg_size).map_err(Error::Memcopy)?; remaining_line_copy_size -= copy_sg_size; if remaining_line_copy_size == 0 { remaining_line_copy_size = line_copy_size; @@ -678,9 +673,7 @@ impl Buffer { } src_offset += line_end_skip; - dst_slice = dst_slice - .offset(line_end_skip) - .map_err(|e| Error::Memcopy(e))?; + dst_slice = dst_slice.offset(line_end_skip).map_err(Error::Memcopy)?; } } } diff --git a/gpu_buffer/src/rendernode.rs b/gpu_buffer/src/rendernode.rs index 2c4c51b..b9849e0 100644 --- a/gpu_buffer/src/rendernode.rs +++ b/gpu_buffer/src/rendernode.rs @@ -88,7 +88,7 @@ pub fn open_device(undesired: &[&str]) -> Result { const DRM_MAX_MINOR: u32 = 15; const RENDER_NODE_START: u32 = 128; - for n in RENDER_NODE_START..(RENDER_NODE_START + DRM_MAX_MINOR + 1) { + for n in RENDER_NODE_START..=RENDER_NODE_START + DRM_MAX_MINOR { let path = Path::new(DRM_DIR_NAME).join(format!("renderD{}", n)); if let Ok(fd) = OpenOptions::new().read(true).write(true).open(path) { -- cgit 1.4.1