diff options
author | David Tolnay <dtolnay@chromium.org> | 2018-12-01 17:49:30 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-03 20:32:03 -0800 |
commit | 5bbbf610828e975fd308b90543359a85ef59b67f (patch) | |
tree | 4cd736628475d702b7ac45feb2e359c3fb74d220 /sys_util | |
parent | 21fb34fb937678d85e9bfa4c721ab4a29196c764 (diff) | |
download | crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.gz crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.bz2 crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.lz crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.xz crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.tar.zst crosvm-5bbbf610828e975fd308b90543359a85ef59b67f.zip |
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 <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'sys_util')
-rw-r--r-- | sys_util/src/guest_memory.rs | 10 | ||||
-rw-r--r-- | sys_util/src/handle_eintr.rs | 4 | ||||
-rw-r--r-- | sys_util/src/signal.rs | 2 | ||||
-rw-r--r-- | sys_util/src/sock_ctrl_msg.rs | 5 | ||||
-rw-r--r-- | sys_util/src/syslog.rs | 26 | ||||
-rw-r--r-- | sys_util/src/tempdir.rs | 2 |
6 files changed, 23 insertions, 26 deletions
diff --git a/sys_util/src/guest_memory.rs b/sys_util/src/guest_memory.rs index 604ef49..3622085 100644 --- a/sys_util/src/guest_memory.rs +++ b/sys_util/src/guest_memory.rs @@ -27,10 +27,10 @@ pub type Result<T> = result::Result<T, Error>; impl error::Error for Error { fn description(&self) -> &str { match self { - &Error::InvalidGuestAddress(_) => "Invalid Guest Address", - &Error::MemoryAccess(_, _) => "Invalid Guest Memory Access", - &Error::MemoryMappingFailed(_) => "Failed to map guest memory", - &Error::MemoryRegionOverlap => "Memory regions overlap", + Error::InvalidGuestAddress(_) => "Invalid Guest Address", + Error::MemoryAccess(_, _) => "Invalid Guest Memory Access", + Error::MemoryMappingFailed(_) => "Failed to map guest memory", + Error::MemoryRegionOverlap => "Memory regions overlap", } } } @@ -386,7 +386,7 @@ impl GuestMemory { self.do_in_region(guest_addr, |mapping, offset| { // This is safe; `do_in_region` already checks that offset is in // bounds. - Ok(unsafe { mapping.as_ptr().offset(offset as isize) } as *const u8) + Ok(unsafe { mapping.as_ptr().add(offset) } as *const u8) }) } diff --git a/sys_util/src/handle_eintr.rs b/sys_util/src/handle_eintr.rs index 4faab07..b570c36 100644 --- a/sys_util/src/handle_eintr.rs +++ b/sys_util/src/handle_eintr.rs @@ -18,7 +18,7 @@ pub trait InterruptibleResult { impl<T> InterruptibleResult for ::Result<T> { fn is_interrupted(&self) -> bool { match self { - &Err(e) if e.errno() == EINTR => true, + Err(e) if e.errno() == EINTR => true, _ => false, } } @@ -27,7 +27,7 @@ impl<T> InterruptibleResult for ::Result<T> { impl<T> InterruptibleResult for io::Result<T> { fn is_interrupted(&self) -> bool { match self { - &Err(ref e) if e.kind() == io::ErrorKind::Interrupted => true, + Err(e) if e.kind() == io::ErrorKind::Interrupted => true, _ => false, } } diff --git a/sys_util/src/signal.rs b/sys_util/src/signal.rs index 69e0fd0..fe01dcf 100644 --- a/sys_util/src/signal.rs +++ b/sys_util/src/signal.rs @@ -124,7 +124,7 @@ pub fn get_blocked_signals() -> SignalResult<Vec<c_int>> { return Err(Error::RetrieveSignalMask(ret)); } - for num in 0..(SIGRTMAX() + 1) { + for num in 0..=SIGRTMAX() { if sigismember(&old_sigset, num) > 0 { mask.push(num); } diff --git a/sys_util/src/sock_ctrl_msg.rs b/sys_util/src/sock_ctrl_msg.rs index a21b64a..337dbb9 100644 --- a/sys_util/src/sock_ctrl_msg.rs +++ b/sys_util/src/sock_ctrl_msg.rs @@ -54,8 +54,7 @@ fn CMSG_DATA(cmsg_buffer: *mut cmsghdr) -> *mut RawFd { // does some pointer arithmetic on cmsg_ptr. #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] fn get_next_cmsg(msghdr: &msghdr, cmsg: &cmsghdr, cmsg_ptr: *mut cmsghdr) -> *mut cmsghdr { - let next_cmsg = - (cmsg_ptr as *mut u8).wrapping_offset(CMSG_ALIGN!(cmsg.cmsg_len) as isize) as *mut cmsghdr; + let next_cmsg = (cmsg_ptr as *mut u8).wrapping_add(CMSG_ALIGN!(cmsg.cmsg_len)) as *mut cmsghdr; if next_cmsg .wrapping_offset(1) .wrapping_sub(msghdr.msg_control as usize) as usize @@ -311,6 +310,8 @@ pub unsafe trait IntoIovec { // Safe because this slice can not have another mutable reference and it's pointer and size are // guaranteed to be valid. unsafe impl<'a> IntoIovec for &'a [u8] { + // Clippy false positive: https://github.com/rust-lang/rust-clippy/issues/3480 + #[cfg_attr(feature = "cargo-clippy", allow(useless_asref))] fn as_ptr(&self) -> *const c_void { self.as_ref().as_ptr() as *const c_void } diff --git a/sys_util/src/syslog.rs b/sys_util/src/syslog.rs index c080041..be85d2b 100644 --- a/sys_util/src/syslog.rs +++ b/sys_util/src/syslog.rs @@ -45,7 +45,7 @@ use libc::{ use getpid; -const SYSLOG_PATH: &'static str = "/dev/log"; +const SYSLOG_PATH: &str = "/dev/log"; /// The priority (i.e. severity) of a syslog message. /// @@ -65,14 +65,14 @@ pub enum Priority { impl fmt::Display for Priority { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - &Priority::Emergency => write!(f, "EMERGENCY"), - &Priority::Alert => write!(f, "ALERT"), - &Priority::Critical => write!(f, "CRITICAL"), - &Priority::Error => write!(f, "ERROR"), - &Priority::Warning => write!(f, "WARNING"), - &Priority::Notice => write!(f, "NOTICE"), - &Priority::Info => write!(f, "INFO"), - &Priority::Debug => write!(f, "DEBUG"), + Priority::Emergency => write!(f, "EMERGENCY"), + Priority::Alert => write!(f, "ALERT"), + Priority::Critical => write!(f, "CRITICAL"), + Priority::Error => write!(f, "ERROR"), + Priority::Warning => write!(f, "WARNING"), + Priority::Notice => write!(f, "NOTICE"), + Priority::Info => write!(f, "INFO"), + Priority::Debug => write!(f, "DEBUG"), } } } @@ -417,7 +417,7 @@ fn get_localtime() -> tm { /// # } /// ``` pub fn log(pri: Priority, fac: Facility, file_name: &str, line: u32, args: fmt::Arguments) { - const MONTHS: [&'static str; 12] = [ + const MONTHS: [&str; 12] = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; @@ -457,11 +457,7 @@ pub fn log(pri: Priority, fac: Facility, file_name: &str, line: u32, args: fmt:: let (res, len) = { let mut buf_cursor = Cursor::new(&mut buf[..]); ( - write!( - &mut buf_cursor, - "[{}:{}:{}] {}\n", - pri, file_name, line, args - ), + writeln!(&mut buf_cursor, "[{}:{}:{}] {}", pri, file_name, line, args), buf_cursor.position() as usize, ) }; diff --git a/sys_util/src/tempdir.rs b/sys_util/src/tempdir.rs index 28f61c3..755865c 100644 --- a/sys_util/src/tempdir.rs +++ b/sys_util/src/tempdir.rs @@ -60,7 +60,7 @@ impl TempDir { /// will also remove the directory. Calling remove explicitly allows for better error handling. pub fn remove(mut self) -> Result<()> { let path = self.path.take(); - path.map_or(Ok(()), |ref p| fs::remove_dir_all(p))?; + path.map_or(Ok(()), fs::remove_dir_all)?; Ok(()) } |