From 1bb71fbf5061fe7b27e27dc9f198c8989dff1bde Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 10 Jun 2022 13:57:37 -0700 Subject: [PATCH] Fix a few clippy lints. --- src/imp/libc/offset.rs | 2 +- src/io_uring.rs | 1 + src/param/mod.rs | 2 +- tests/io/from_into.rs | 3 +- tests/net/addr.rs | 4 +-- tests/path/arg.rs | 74 +++++++++--------------------------------- 6 files changed, 22 insertions(+), 64 deletions(-) diff --git a/src/imp/libc/offset.rs b/src/imp/libc/offset.rs index d7b4cdb5..3002e8bd 100644 --- a/src/imp/libc/offset.rs +++ b/src/imp/libc/offset.rs @@ -1,4 +1,4 @@ -//! Automatically enable "large file" support features. +//! Automatically enable “large file” support features. #[cfg(not(windows))] use super::c; diff --git a/src/io_uring.rs b/src/io_uring.rs index 55da62a2..b68f82c6 100644 --- a/src/io_uring.rs +++ b/src/io_uring.rs @@ -1047,6 +1047,7 @@ fn io_uring_layouts() { // Check that we have all the fields. let _test = $name { + // Safety: All of io_uring's types can be zero-initialized. $($field: unsafe { core::mem::zeroed() }),* }; diff --git a/src/param/mod.rs b/src/param/mod.rs index 5050c323..79b79d53 100644 --- a/src/param/mod.rs +++ b/src/param/mod.rs @@ -1,7 +1,7 @@ //! Process parameters. //! //! These values correspond to `sysconf` in POSIX, and the auxv array in Linux. -//! Despite the POSIX name "sysconf", these aren't *system* configuration +//! Despite the POSIX name “sysconf”, these aren't *system* configuration //! parameters; they're *process* configuration parameters, as they may differ //! between different processes on the same system. diff --git a/tests/io/from_into.rs b/tests/io/from_into.rs index 449b885f..94d91599 100644 --- a/tests/io/from_into.rs +++ b/tests/io/from_into.rs @@ -19,8 +19,7 @@ fn test_owned() { let raw = file.as_raw_fd(); assert_eq!(raw, file.as_fd().as_raw_fd()); - let owned: rustix::io::OwnedFd = file.into(); - let inner = owned.into_raw_fd(); + let inner = file.into_raw_fd(); assert_eq!(raw, inner); let new = unsafe { rustix::io::OwnedFd::from_raw_fd(inner) }; diff --git a/tests/net/addr.rs b/tests/net/addr.rs index 9b5accd5..12441313 100644 --- a/tests/net/addr.rs +++ b/tests/net/addr.rs @@ -9,13 +9,13 @@ fn encode_decode() { unsafe { let orig = SocketAddrV4::new(Ipv4Addr::new(2, 3, 5, 6), 33); let mut encoded = std::mem::MaybeUninit::::uninit(); - let len = SocketAddrAny::V4(orig.clone()).write(encoded.as_mut_ptr()); + let len = SocketAddrAny::V4(orig).write(encoded.as_mut_ptr()); let decoded = SocketAddrAny::read(encoded.as_ptr(), len).unwrap(); assert_eq!(decoded, SocketAddrAny::V4(orig)); let orig = SocketAddrV6::new(Ipv6Addr::new(2, 3, 5, 6, 8, 9, 11, 12), 33, 34, 36); let mut encoded = std::mem::MaybeUninit::::uninit(); - let len = SocketAddrAny::V6(orig.clone()).write(encoded.as_mut_ptr()); + let len = SocketAddrAny::V6(orig).write(encoded.as_mut_ptr()); let decoded = SocketAddrAny::read(encoded.as_ptr(), len).unwrap(); assert_eq!(decoded, SocketAddrAny::V6(orig)); diff --git a/tests/path/arg.rs b/tests/path/arg.rs index 860829e1..0eb511be 100644 --- a/tests/path/arg.rs +++ b/tests/path/arg.rs @@ -22,10 +22,7 @@ fn test_arg() { assert_eq!("hello", Arg::as_str(&t).unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: &OsStr = OsStr::new("hello"); assert_eq!("hello", t.as_str().unwrap()); @@ -37,10 +34,7 @@ fn test_arg() { assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: &Path = Path::new("hello"); assert_eq!("hello", t.as_str().unwrap()); @@ -52,10 +46,7 @@ fn test_arg() { assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: &CStr = cstr!("hello"); assert_eq!("hello", t.as_str().unwrap()); @@ -70,19 +61,13 @@ fn test_arg() { cstr!("hello"), Borrow::borrow(&Arg::as_cow_c_str(&t).unwrap()) ); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Components = Path::new("hello").components(); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Component = Path::new("hello").components().next().unwrap(); assert_eq!("hello", t.as_str().unwrap()); @@ -94,64 +79,43 @@ fn test_arg() { assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Cow<'_, str> = Cow::Borrowed("hello"); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Cow<'_, str> = Cow::Owned("hello".to_owned()); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Cow<'_, OsStr> = Cow::Borrowed(OsStr::new("hello")); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Cow<'_, OsStr> = Cow::Owned(OsString::from("hello".to_owned())); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Cow<'_, CStr> = Cow::Borrowed(cstr!("hello")); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Cow<'_, CStr> = Cow::Owned(cstr!("hello").to_owned()); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: &[u8] = b"hello"; assert_eq!("hello", t.as_str().unwrap()); @@ -163,10 +127,7 @@ fn test_arg() { assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!( - cstr!("hello"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); #[cfg(feature = "itoa")] { @@ -175,10 +136,7 @@ fn test_arg() { assert_eq!("43110".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(cstr!("43110"), Borrow::borrow(&t.as_cow_c_str().unwrap())); assert_eq!(cstr!("43110"), t.as_c_str()); - assert_eq!( - cstr!("43110"), - Borrow::borrow(&t.clone().into_c_str().unwrap()) - ); + assert_eq!(cstr!("43110"), Borrow::borrow(&t.into_c_str().unwrap())); } } @@ -195,7 +153,7 @@ fn test_invalid() { ); assert_eq!( b"hello\xc0world\0", - Borrow::::borrow(&t.clone().into_c_str().unwrap()).to_bytes_with_nul() + Borrow::::borrow(&t.into_c_str().unwrap()).to_bytes_with_nul() ); } @@ -205,5 +163,5 @@ fn test_embedded_nul() { assert_eq!("hello\0world", t.as_str().unwrap()); assert_eq!("hello\0world".to_owned(), Arg::to_string_lossy(&t)); assert_eq!(t.as_cow_c_str().unwrap_err(), io::Errno::INVAL); - assert_eq!(t.clone().into_c_str().unwrap_err(), io::Errno::INVAL); + assert_eq!(t.into_c_str().unwrap_err(), io::Errno::INVAL); }