From ad12be3668de26dc1b35bb374e93b2bab58d02ae Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 22:59:02 +0000 Subject: [PATCH 01/17] allow clippy style in windows/c.rs We intentional use the Windows API style here. --- library/std/src/sys/windows/c.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index a349e24b039..ede04abf105 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -3,6 +3,7 @@ #![allow(nonstandard_style)] #![cfg_attr(test, allow(dead_code))] #![unstable(issue = "none", feature = "windows_c")] +#![allow(clippy::style)] use crate::ffi::CStr; use crate::mem; From 533de2bc4159ed929eb03f35f77b7da58311e82f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 22 Nov 2023 12:59:22 +0000 Subject: [PATCH 02/17] needless_return unneeded `return` statement --- library/std/src/sys/windows/stdio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs index a9ff909aa67..51a1a4875bb 100644 --- a/library/std/src/sys/windows/stdio.rs +++ b/library/std/src/sys/windows/stdio.rs @@ -266,7 +266,7 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result { let mut bytes_copied = self.incomplete_utf8.read(buf); if bytes_copied == buf.len() { - return Ok(bytes_copied); + Ok(bytes_copied) } else if buf.len() - bytes_copied < 4 { // Not enough space to get a UTF-8 byte. We will use the incomplete UTF8. let mut utf16_buf = [MaybeUninit::new(0); 1]; From 6c22e57c39b8fd8304ad317b42ddb7561000215f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:02:09 +0000 Subject: [PATCH 03/17] useless_conversion --- library/std/src/os/windows/io/handle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 274af08a388..b0540872c0b 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -504,7 +504,7 @@ fn as_handle(&self) -> BorrowedHandle<'_> { impl From for OwnedHandle { #[inline] fn from(file: fs::File) -> OwnedHandle { - file.into_inner().into_inner().into_inner().into() + file.into_inner().into_inner().into_inner() } } From bfbeb3ebd977997233f93c5cce11bbdfdd34237d Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:06:35 +0000 Subject: [PATCH 04/17] unnecessary_mut_passed This is where our Windows API bindings previously (and incorrectly) used `*mut` instead of `*const` pointers. Now that the bindings have been corrected, the mutable references (which auto-convert to `*mut`) are unnecessary and we can use shared references. --- library/std/src/os/windows/io/socket.rs | 4 ++-- library/std/src/sys/windows/fs.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index c80b9e28499..65f161f32e7 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -127,7 +127,7 @@ pub fn try_clone_to_owned(&self) -> io::Result { info.iAddressFamily, info.iSocketType, info.iProtocol, - &mut info, + &info, 0, sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT, ) @@ -147,7 +147,7 @@ pub fn try_clone_to_owned(&self) -> io::Result { info.iAddressFamily, info.iSocketType, info.iProtocol, - &mut info, + &info, 0, sys::c::WSA_FLAG_OVERLAPPED, ) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index d7e36b9a3ff..4deda6d97c4 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -786,7 +786,7 @@ fn open_link_no_reparse(parent: &File, name: &[u16], access: u32) -> io::Result< // tricked into following a symlink. However, it may not be available in // earlier versions of Windows. static ATTRIBUTES: AtomicU32 = AtomicU32::new(c::OBJ_DONT_REPARSE); - let mut object = c::OBJECT_ATTRIBUTES { + let object = c::OBJECT_ATTRIBUTES { ObjectName: &mut name_str, RootDirectory: parent.as_raw_handle(), Attributes: ATTRIBUTES.load(Ordering::Relaxed), @@ -795,7 +795,7 @@ fn open_link_no_reparse(parent: &File, name: &[u16], access: u32) -> io::Result< let status = c::NtCreateFile( &mut handle, access, - &mut object, + &object, &mut io_status, crate::ptr::null_mut(), 0, From fe255695f9ceb2417350d4d355ce35bfe5ad695b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:17:29 +0000 Subject: [PATCH 05/17] manual_slice_size_calculation --- library/std/src/sys/windows/c.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index ede04abf105..351ec2a48be 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -82,7 +82,7 @@ pub fn nt_success(status: NTSTATUS) -> bool { impl UNICODE_STRING { pub fn from_ref(slice: &[u16]) -> Self { - let len = slice.len() * mem::size_of::(); + let len = mem::size_of_val(slice); Self { Length: len as _, MaximumLength: len as _, Buffer: slice.as_ptr() as _ } } } From 42734599bd613efee41d0a508e0fc60ea6d86058 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:21:56 +0000 Subject: [PATCH 06/17] needless_borrows_for_generic_args the borrowed expression implements the required traits --- library/std/src/sys/windows/fs.rs | 2 +- library/std/src/sys/windows/process.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index 4deda6d97c4..a0d3401a0a6 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -156,7 +156,7 @@ fn new(root: &Arc, wfd: &c::WIN32_FIND_DATAW) -> Option { } pub fn path(&self) -> PathBuf { - self.root.join(&self.file_name()) + self.root.join(self.file_name()) } pub fn file_name(&self) -> OsString { diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index f4078d35944..f7e87a6734d 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -463,7 +463,7 @@ fn resolve_exe<'a>( // Search the directories given by `search_paths`. let result = search_paths(parent_paths, child_paths, |mut path| { - path.push(&exe_path); + path.push(exe_path); if !has_extension { path.set_extension(EXE_EXTENSION); } From 24542639aa6c72c1a6a3beb8275533b33b0687be Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:32:13 +0000 Subject: [PATCH 07/17] needless_borrow this expression creates a reference which is immediately dereferenced by the compiler --- library/std/src/sys/windows/fs.rs | 8 ++++---- library/std/src/sys/windows/handle.rs | 4 ++-- library/std/src/sys/windows/mod.rs | 2 +- library/std/src/sys/windows/stdio.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index a0d3401a0a6..f57034cc8d5 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -548,7 +548,7 @@ fn readlink(&self) -> io::Result { let user = super::args::from_wide_to_user_path( subst.iter().copied().chain([0]).collect(), )?; - Ok(PathBuf::from(OsString::from_wide(&user.strip_suffix(&[0]).unwrap_or(&user)))) + Ok(PathBuf::from(OsString::from_wide(user.strip_suffix(&[0]).unwrap_or(&user)))) } else { Ok(PathBuf::from(OsString::from_wide(subst))) } @@ -874,7 +874,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // FIXME(#24570): add more info here (e.g., mode) let mut b = f.debug_struct("File"); b.field("handle", &self.handle.as_raw_handle()); - if let Ok(path) = get_path(&self) { + if let Ok(path) = get_path(self) { b.field("path", &path); } b.finish() @@ -1193,7 +1193,7 @@ pub fn readlink(path: &Path) -> io::Result { let mut opts = OpenOptions::new(); opts.access_mode(0); opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | c::FILE_FLAG_BACKUP_SEMANTICS); - let file = File::open(&path, &opts)?; + let file = File::open(path, &opts)?; file.readlink() } @@ -1407,7 +1407,7 @@ pub fn symlink_junction, Q: AsRef>( #[allow(dead_code)] fn symlink_junction_inner(original: &Path, junction: &Path) -> io::Result<()> { let d = DirBuilder::new(); - d.mkdir(&junction)?; + d.mkdir(junction)?; let mut opts = OpenOptions::new(); opts.write(true); diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index 56d0d6c0887..7badf8fea07 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -189,7 +189,7 @@ pub fn cancel_io(&self) -> io::Result<()> { } pub fn write(&self, buf: &[u8]) -> io::Result { - self.synchronous_write(&buf, None) + self.synchronous_write(buf, None) } pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { @@ -202,7 +202,7 @@ pub fn is_write_vectored(&self) -> bool { } pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { - self.synchronous_write(&buf, Some(offset)) + self.synchronous_write(buf, Some(offset)) } pub fn try_clone(&self) -> io::Result { diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index c4e56e13be3..14e34ffec4d 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -63,7 +63,7 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) { // Normally, `thread::spawn` will call `Thread::set_name` but since this thread already // exists, we have to call it ourselves. - thread::Thread::set_name(&CStr::from_bytes_with_nul_unchecked(b"main\0")); + thread::Thread::set_name(CStr::from_bytes_with_nul_unchecked(b"main\0")); } // SAFETY: must be called only once during runtime cleanup. diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs index 51a1a4875bb..1765c221543 100644 --- a/library/std/src/sys/windows/stdio.rs +++ b/library/std/src/sys/windows/stdio.rs @@ -195,7 +195,7 @@ fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result Date: Tue, 21 Nov 2023 23:40:46 +0000 Subject: [PATCH 08/17] unnecessary_cast casting to the same type is unnecessary --- library/std/src/sys/windows/handle.rs | 6 +++--- library/std/src/sys/windows/io.rs | 6 +++--- library/std/src/sys/windows/os.rs | 2 +- library/std/src/sys/windows/process.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index 7badf8fea07..c4495f81a5a 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -81,7 +81,7 @@ pub fn read(&self, buf: &mut [u8]) -> io::Result { let res = unsafe { self.synchronous_read(buf.as_mut_ptr().cast(), buf.len(), None) }; match res { - Ok(read) => Ok(read as usize), + Ok(read) => Ok(read), // The special treatment of BrokenPipe is to deal with Windows // pipe semantics, which yields this error when *reading* from @@ -107,7 +107,7 @@ pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { unsafe { self.synchronous_read(buf.as_mut_ptr().cast(), buf.len(), Some(offset)) }; match res { - Ok(read) => Ok(read as usize), + Ok(read) => Ok(read), Err(ref e) if e.raw_os_error() == Some(c::ERROR_HANDLE_EOF as i32) => Ok(0), Err(e) => Err(e), } @@ -121,7 +121,7 @@ pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { Ok(read) => { // Safety: `read` bytes were written to the initialized portion of the buffer unsafe { - cursor.advance(read as usize); + cursor.advance(read); } Ok(()) } diff --git a/library/std/src/sys/windows/io.rs b/library/std/src/sys/windows/io.rs index 9b540ee071f..649826d25ce 100644 --- a/library/std/src/sys/windows/io.rs +++ b/library/std/src/sys/windows/io.rs @@ -36,7 +36,7 @@ pub fn advance(&mut self, n: usize) { #[inline] pub fn as_slice(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) } + unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) } } } @@ -70,12 +70,12 @@ pub fn advance(&mut self, n: usize) { #[inline] pub fn as_slice(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) } + unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) } } #[inline] pub fn as_mut_slice(&mut self) -> &mut [u8] { - unsafe { slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.len as usize) } + unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) } } } diff --git a/library/std/src/sys/windows/os.rs b/library/std/src/sys/windows/os.rs index 8cc905101de..b60fa941cb0 100644 --- a/library/std/src/sys/windows/os.rs +++ b/library/std/src/sys/windows/os.rs @@ -364,5 +364,5 @@ pub fn exit(code: i32) -> ! { } pub fn getpid() -> u32 { - unsafe { c::GetCurrentProcessId() as u32 } + unsafe { c::GetCurrentProcessId() } } diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index f7e87a6734d..a1978d71d0b 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -657,7 +657,7 @@ pub fn kill(&mut self) -> io::Result<()> { } pub fn id(&self) -> u32 { - unsafe { c::GetProcessId(self.handle.as_raw_handle()) as u32 } + unsafe { c::GetProcessId(self.handle.as_raw_handle()) } } pub fn main_thread_handle(&self) -> BorrowedHandle<'_> { @@ -918,7 +918,7 @@ fn make_proc_thread_attribute_list( }; let mut proc_thread_attribute_list = ProcThreadAttributeList( - vec![MaybeUninit::uninit(); required_size as usize].into_boxed_slice(), + vec![MaybeUninit::uninit(); required_size].into_boxed_slice(), ); // Once we've allocated the necessary memory, it's safe to invoke From b962ae132440dd88b9795313b2bddf161d9abb52 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:42:51 +0000 Subject: [PATCH 09/17] duration_subsec calling `subsec_micros()` is more concise than this calculation --- library/std/src/sys/windows/net.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index c29b863665f..6cd758ec5c3 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -162,7 +162,7 @@ pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Resul let mut timeout = c::timeval { tv_sec: cmp::min(timeout.as_secs(), c_long::MAX as u64) as c_long, - tv_usec: (timeout.subsec_nanos() / 1000) as c_long, + tv_usec: timeout.subsec_micros() as c_long, }; if timeout.tv_sec == 0 && timeout.tv_usec == 0 { From 220217af135198ed950133f9785d93df1d49097c Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:45:52 +0000 Subject: [PATCH 10/17] redundant_closure --- library/std/src/sys/windows/api.rs | 2 +- library/std/src/sys/windows/os.rs | 4 ++-- library/std/src/sys/windows/process.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/windows/api.rs b/library/std/src/sys/windows/api.rs index e9f0bbfbe2e..72ecb950341 100644 --- a/library/std/src/sys/windows/api.rs +++ b/library/std/src/sys/windows/api.rs @@ -132,7 +132,7 @@ unsafe fn set_info( size: u32, ) -> Result<(), WinError> { let result = c::SetFileInformationByHandle(handle, class, info, size); - (result != 0).then_some(()).ok_or_else(|| get_last_error()) + (result != 0).then_some(()).ok_or_else(get_last_error) } // SAFETY: The `SetFileInformation` trait ensures that this is safe. unsafe { set_info(handle, T::CLASS, info.as_ptr(), info.size()) } diff --git a/library/std/src/sys/windows/os.rs b/library/std/src/sys/windows/os.rs index b60fa941cb0..829dd5eb97a 100644 --- a/library/std/src/sys/windows/os.rs +++ b/library/std/src/sys/windows/os.rs @@ -297,7 +297,7 @@ pub fn getenv(k: &OsStr) -> Option { let k = to_u16s(k).ok()?; super::fill_utf16_buf( |buf, sz| unsafe { c::GetEnvironmentVariableW(k.as_ptr(), buf, sz) }, - |buf| OsStringExt::from_wide(buf), + OsStringExt::from_wide, ) .ok() } @@ -356,7 +356,7 @@ pub fn home_dir() -> Option { crate::env::var_os("HOME") .or_else(|| crate::env::var_os("USERPROFILE")) .map(PathBuf::from) - .or_else(|| home_dir_crt()) + .or_else(home_dir_crt) } pub fn exit(code: i32) -> ! { diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index a1978d71d0b..8a442ca4acf 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -245,7 +245,7 @@ pub fn get_envs(&self) -> CommandEnvs<'_> { } pub fn get_current_dir(&self) -> Option<&Path> { - self.cwd.as_ref().map(|cwd| Path::new(cwd)) + self.cwd.as_ref().map(Path::new) } pub unsafe fn raw_attribute( From 8c85c5b7f43ac4dd9bb9e444fdb89ca826b1f00e Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:48:59 +0000 Subject: [PATCH 11/17] unnecessary_lazy_evaluations unnecessary closure used with `bool::then` --- library/std/src/sys/windows/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs index f7f9f96ba5d..5da7de5de24 100644 --- a/library/std/src/sys/windows/path.rs +++ b/library/std/src/sys/windows/path.rs @@ -78,7 +78,7 @@ impl<'a> PrefixParserSlice<'a, '_> { fn strip_prefix(&self, prefix: &str) -> Option { self.prefix[self.index..] .starts_with(prefix.as_bytes()) - .then(|| Self { index: self.index + prefix.len(), ..*self }) + .then_some(Self { index: self.index + prefix.len(), ..*self }) } fn prefix_bytes(&self) -> &'a [u8] { From 4c084c576ac5de81164a0d6a44093d99f47c233f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:55:07 +0000 Subject: [PATCH 12/17] manual_map manual implementation of `Option::map` --- library/std/src/sys/windows/path.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs index 5da7de5de24..6f62206532c 100644 --- a/library/std/src/sys/windows/path.rs +++ b/library/std/src/sys/windows/path.rs @@ -147,12 +147,10 @@ pub fn parse_prefix(path: &OsStr) -> Option> { None } } - } else if let Some(drive) = parse_drive(path) { - // C: - Some(Disk(drive)) } else { - // no prefix - None + // If it has a drive like `C:` then it's a disk. + // Otherwise there is no prefix. + parse_drive(path).map(Disk) } } From d7e1f1cc0813727b197e13a7672517da7ff42b44 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 21 Nov 2023 23:57:11 +0000 Subject: [PATCH 13/17] op_ref taken reference of right operand --- library/std/src/sys/windows/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs index 6f62206532c..d9684f21753 100644 --- a/library/std/src/sys/windows/path.rs +++ b/library/std/src/sys/windows/path.rs @@ -250,7 +250,7 @@ pub(crate) fn get_long_path(mut path: Vec, prefer_verbatim: bool) -> io::Re // \\?\UNC\ const UNC_PREFIX: &[u16] = &[SEP, SEP, QUERY, SEP, U, N, C, SEP]; - if path.starts_with(VERBATIM_PREFIX) || path.starts_with(NT_PREFIX) || path == &[0] { + if path.starts_with(VERBATIM_PREFIX) || path.starts_with(NT_PREFIX) || path == [0] { // Early return for paths that are already verbatim or empty. return Ok(path); } else if path.len() < LEGACY_MAX_PATH { From c15adf6557a43b51bae72252b49c89635dbee325 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 22 Nov 2023 00:02:04 +0000 Subject: [PATCH 14/17] manual_range_contains --- library/std/src/sys/windows/stdio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs index 1765c221543..819a48266d9 100644 --- a/library/std/src/sys/windows/stdio.rs +++ b/library/std/src/sys/windows/stdio.rs @@ -207,7 +207,7 @@ fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result= 0xDCEE && first_code_unit_remaining <= 0xDFFF { + if matches!(first_code_unit_remaining, 0xDCEE..=0xDFFF) { // low surrogate // We just hope this works, and give up otherwise let _ = write_u16s(handle, &utf16[written..written + 1]); @@ -332,7 +332,7 @@ fn read_u16s_fixup_surrogates( // and it is not 0, so we know that `buf[amount - 1]` have been // initialized. let last_char = unsafe { buf[amount - 1].assume_init() }; - if last_char >= 0xD800 && last_char <= 0xDBFF { + if matches!(last_char, 0xD800..=0xDBFF) { // high surrogate *surrogate = last_char; amount -= 1; From 852c0383930a80c646441104a89af59f949c9804 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 22 Nov 2023 00:09:33 +0000 Subject: [PATCH 15/17] cmp_null comparing with null is better expressed by the `.is_null()` method --- library/std/src/sys/windows/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/time.rs b/library/std/src/sys/windows/time.rs index bece48e799f..09e78a29304 100644 --- a/library/std/src/sys/windows/time.rs +++ b/library/std/src/sys/windows/time.rs @@ -1,7 +1,7 @@ use crate::cmp::Ordering; use crate::fmt; use crate::mem; -use crate::ptr::{null, null_mut}; +use crate::ptr::null; use crate::sys::c; use crate::sys_common::IntoInner; use crate::time::Duration; @@ -240,7 +240,7 @@ pub fn high_resolution() -> Result { c::TIMER_ALL_ACCESS, ) }; - if handle != null_mut() { Ok(Self { handle }) } else { Err(()) } + if !handle.is_null() { Ok(Self { handle }) } else { Err(()) } } pub fn set(&self, duration: Duration) -> Result<(), ()> { // Convert the Duration to a format similar to FILETIME. From 6c8ebf174c3201ec6333e8bf2df291b88e338d35 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 22 Nov 2023 00:10:48 +0000 Subject: [PATCH 16/17] redundant_slicing --- library/std/src/sys/windows/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 14e34ffec4d..9c83d6eb8bf 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -150,7 +150,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { pub fn unrolled_find_u16s(needle: u16, haystack: &[u16]) -> Option { let ptr = haystack.as_ptr(); - let mut start = &haystack[..]; + let mut start = haystack; // For performance reasons unfold the loop eight times. while start.len() >= 8 { From b9fe367b9993c33a022411fd08e3da0081abacfd Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 22 Nov 2023 00:44:37 +0000 Subject: [PATCH 17/17] x fmt library/std --- library/std/src/sys/windows/process.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index 8a442ca4acf..51e16b9f13c 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -917,9 +917,8 @@ fn make_proc_thread_attribute_list( ) }; - let mut proc_thread_attribute_list = ProcThreadAttributeList( - vec![MaybeUninit::uninit(); required_size].into_boxed_slice(), - ); + let mut proc_thread_attribute_list = + ProcThreadAttributeList(vec![MaybeUninit::uninit(); required_size].into_boxed_slice()); // Once we've allocated the necessary memory, it's safe to invoke // `InitializeProcThreadAttributeList` to properly initialize the list.