mirror of
https://github.com/openharmony/third_party_rust_rustix.git
synced 2026-07-19 23:03:36 -04:00
Fix a few clippy lints.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! Automatically enable "large file" support features.
|
||||
//! Automatically enable “large file” support features.
|
||||
|
||||
#[cfg(not(windows))]
|
||||
use super::c;
|
||||
|
||||
@@ -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() }),*
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
|
||||
@@ -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) };
|
||||
|
||||
+2
-2
@@ -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::<SocketAddrStorage>::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::<SocketAddrStorage>::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));
|
||||
|
||||
|
||||
+16
-58
@@ -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::<CStr>::borrow(&t.clone().into_c_str().unwrap()).to_bytes_with_nul()
|
||||
Borrow::<CStr>::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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user