summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/windows
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/windows')
-rw-r--r--library/std/src/sys/windows/api.rs4
-rw-r--r--library/std/src/sys/windows/c.rs9
-rw-r--r--library/std/src/sys/windows/c/windows_sys.lst4
-rw-r--r--library/std/src/sys/windows/c/windows_sys.rs9
-rw-r--r--library/std/src/sys/windows/compat.rs6
-rw-r--r--library/std/src/sys/windows/fs.rs49
-rw-r--r--library/std/src/sys/windows/handle.rs10
-rw-r--r--library/std/src/sys/windows/io.rs6
-rw-r--r--library/std/src/sys/windows/mod.rs6
-rw-r--r--library/std/src/sys/windows/net.rs2
-rw-r--r--library/std/src/sys/windows/os.rs6
-rw-r--r--library/std/src/sys/windows/path.rs16
-rw-r--r--library/std/src/sys/windows/process.rs13
-rw-r--r--library/std/src/sys/windows/stdio.rs8
-rw-r--r--library/std/src/sys/windows/time.rs4
15 files changed, 88 insertions, 64 deletions
diff --git a/library/std/src/sys/windows/api.rs b/library/std/src/sys/windows/api.rs
index e9f0bbfbe..a7ea59e85 100644
--- a/library/std/src/sys/windows/api.rs
+++ b/library/std/src/sys/windows/api.rs
@@ -48,7 +48,7 @@ use super::c;
/// converted to a `u32`. Clippy would warn about this but, alas, it's not run
/// on the standard library.
const fn win32_size_of<T: Sized>() -> u32 {
- // Const assert that the size is less than u32::MAX.
+ // Const assert that the size does not exceed u32::MAX.
// Uses a trait to workaround restriction on using generic types in inner items.
trait Win32SizeOf: Sized {
const WIN32_SIZE_OF: u32 = {
@@ -132,7 +132,7 @@ pub fn set_file_information_by_handle<T: SetFileInformation>(
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/c.rs b/library/std/src/sys/windows/c.rs
index a349e24b0..d55d9bace 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;
@@ -46,6 +47,8 @@ pub use FD_SET as fd_set;
pub use LINGER as linger;
pub use TIMEVAL as timeval;
+pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::invalid_mut(-1i32 as _);
+
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure?view=msvc-170
pub const EXIT_SUCCESS: u32 = 0;
pub const EXIT_FAILURE: u32 = 1;
@@ -81,7 +84,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::<u16>();
+ let len = mem::size_of_val(slice);
Self { Length: len as _, MaximumLength: len as _, Buffer: slice.as_ptr() as _ }
}
}
@@ -321,7 +324,7 @@ pub unsafe fn NtWriteFile(
// Functions that aren't available on every version of Windows that we support,
// but we still use them and just provide some form of a fallback implementation.
compat_fn_with_fallback! {
- pub static KERNEL32: &CStr = ansi_str!("kernel32");
+ pub static KERNEL32: &CStr = c"kernel32";
// >= Win10 1607
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
@@ -354,7 +357,7 @@ compat_fn_optional! {
}
compat_fn_with_fallback! {
- pub static NTDLL: &CStr = ansi_str!("ntdll");
+ pub static NTDLL: &CStr = c"ntdll";
pub fn NtCreateKeyedEvent(
KeyedEventHandle: LPHANDLE,
diff --git a/library/std/src/sys/windows/c/windows_sys.lst b/library/std/src/sys/windows/c/windows_sys.lst
index 38bf15b7c..f91e1054a 100644
--- a/library/std/src/sys/windows/c/windows_sys.lst
+++ b/library/std/src/sys/windows/c/windows_sys.lst
@@ -2,6 +2,7 @@
--config flatten std
--filter
// tidy-alphabetical-start
+!Windows.Win32.Foundation.INVALID_HANDLE_VALUE
Windows.Wdk.Storage.FileSystem.FILE_COMPLETE_IF_OPLOCKED
Windows.Wdk.Storage.FileSystem.FILE_CONTAINS_EXTENDED_CREATE_INFORMATION
Windows.Wdk.Storage.FileSystem.FILE_CREATE
@@ -1923,7 +1924,6 @@ Windows.Win32.Foundation.HANDLE_FLAG_INHERIT
Windows.Win32.Foundation.HANDLE_FLAG_PROTECT_FROM_CLOSE
Windows.Win32.Foundation.HANDLE_FLAGS
Windows.Win32.Foundation.HMODULE
-Windows.Win32.Foundation.INVALID_HANDLE_VALUE
Windows.Win32.Foundation.MAX_PATH
Windows.Win32.Foundation.NO_ERROR
Windows.Win32.Foundation.NTSTATUS
@@ -2483,7 +2483,6 @@ Windows.Win32.System.SystemInformation.GetSystemTimeAsFileTime
Windows.Win32.System.SystemInformation.GetWindowsDirectoryW
Windows.Win32.System.SystemInformation.PROCESSOR_ARCHITECTURE
Windows.Win32.System.SystemInformation.SYSTEM_INFO
-Windows.Win32.System.SystemServices.ALL_PROCESSOR_GROUPS
Windows.Win32.System.SystemServices.DLL_PROCESS_DETACH
Windows.Win32.System.SystemServices.DLL_THREAD_DETACH
Windows.Win32.System.SystemServices.EXCEPTION_MAXIMUM_PARAMETERS
@@ -2492,6 +2491,7 @@ Windows.Win32.System.SystemServices.IO_REPARSE_TAG_SYMLINK
Windows.Win32.System.Threading.ABOVE_NORMAL_PRIORITY_CLASS
Windows.Win32.System.Threading.AcquireSRWLockExclusive
Windows.Win32.System.Threading.AcquireSRWLockShared
+Windows.Win32.System.Threading.ALL_PROCESSOR_GROUPS
Windows.Win32.System.Threading.BELOW_NORMAL_PRIORITY_CLASS
Windows.Win32.System.Threading.CREATE_BREAKAWAY_FROM_JOB
Windows.Win32.System.Threading.CREATE_DEFAULT_ERROR_MODE
diff --git a/library/std/src/sys/windows/c/windows_sys.rs b/library/std/src/sys/windows/c/windows_sys.rs
index e0509e6a5..b38b70c89 100644
--- a/library/std/src/sys/windows/c/windows_sys.rs
+++ b/library/std/src/sys/windows/c/windows_sys.rs
@@ -4,7 +4,7 @@
// regenerate the bindings.
//
// ignore-tidy-filelength
-// Bindings generated by `windows-bindgen` 0.51.1
+// Bindings generated by `windows-bindgen` 0.52.0
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]
#[link(name = "advapi32")]
@@ -63,7 +63,7 @@ extern "system" {
lpnewfilename: PCWSTR,
lpprogressroutine: LPPROGRESS_ROUTINE,
lpdata: *const ::core::ffi::c_void,
- pbcancel: *mut i32,
+ pbcancel: *mut BOOL,
dwcopyflags: u32,
) -> BOOL;
}
@@ -619,7 +619,7 @@ extern "system" {
lpmultibytestr: PSTR,
cbmultibyte: i32,
lpdefaultchar: PCSTR,
- lpuseddefaultchar: *mut i32,
+ lpuseddefaultchar: *mut BOOL,
) -> i32;
}
#[link(name = "kernel32")]
@@ -869,7 +869,7 @@ pub const AF_INET: ADDRESS_FAMILY = 2u16;
pub const AF_INET6: ADDRESS_FAMILY = 23u16;
pub const AF_UNIX: u16 = 1u16;
pub const AF_UNSPEC: ADDRESS_FAMILY = 0u16;
-pub const ALL_PROCESSOR_GROUPS: u32 = 65535u32;
+pub const ALL_PROCESSOR_GROUPS: u16 = 65535u16;
#[repr(C)]
pub union ARM64_NT_NEON128 {
pub Anonymous: ARM64_NT_NEON128_0,
@@ -3498,7 +3498,6 @@ impl ::core::clone::Clone for INIT_ONCE {
}
pub const INIT_ONCE_INIT_FAILED: u32 = 4u32;
pub const INVALID_FILE_ATTRIBUTES: u32 = 4294967295u32;
-pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::invalid_mut(-1i32 as _);
pub const INVALID_SOCKET: SOCKET = -1i32 as _;
#[repr(C)]
pub struct IN_ADDR {
diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs
index e28dd4935..f60b3a2c7 100644
--- a/library/std/src/sys/windows/compat.rs
+++ b/library/std/src/sys/windows/compat.rs
@@ -225,9 +225,9 @@ macro_rules! compat_fn_optional {
/// Load all needed functions from "api-ms-win-core-synch-l1-2-0".
pub(super) fn load_synch_functions() {
fn try_load() -> Option<()> {
- const MODULE_NAME: &CStr = ansi_str!("api-ms-win-core-synch-l1-2-0");
- const WAIT_ON_ADDRESS: &CStr = ansi_str!("WaitOnAddress");
- const WAKE_BY_ADDRESS_SINGLE: &CStr = ansi_str!("WakeByAddressSingle");
+ const MODULE_NAME: &CStr = c"api-ms-win-core-synch-l1-2-0";
+ const WAIT_ON_ADDRESS: &CStr = c"WaitOnAddress";
+ const WAKE_BY_ADDRESS_SINGLE: &CStr = c"WakeByAddressSingle";
// Try loading the library and all the required functions.
// If any step fails, then they all fail.
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs
index d7e36b9a3..424845436 100644
--- a/library/std/src/sys/windows/fs.rs
+++ b/library/std/src/sys/windows/fs.rs
@@ -1,7 +1,7 @@
use crate::os::windows::prelude::*;
use crate::borrow::Cow;
-use crate::ffi::OsString;
+use crate::ffi::{c_void, OsString};
use crate::fmt;
use crate::io::{self, BorrowedCursor, Error, IoSlice, IoSliceMut, SeekFrom};
use crate::mem::{self, MaybeUninit};
@@ -16,8 +16,6 @@ use crate::sys::{c, cvt, Align8};
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::thread;
-use core::ffi::c_void;
-
use super::path::maybe_verbatim;
use super::{api, to_u16s, IoResult};
@@ -156,7 +154,7 @@ impl DirEntry {
}
pub fn path(&self) -> PathBuf {
- self.root.join(&self.file_name())
+ self.root.join(self.file_name())
}
pub fn file_name(&self) -> OsString {
@@ -273,7 +271,9 @@ impl OpenOptions {
(false, false, false) => c::OPEN_EXISTING,
(true, false, false) => c::OPEN_ALWAYS,
(false, true, false) => c::TRUNCATE_EXISTING,
- (true, true, false) => c::CREATE_ALWAYS,
+ // `CREATE_ALWAYS` has weird semantics so we emulate it using
+ // `OPEN_ALWAYS` and a manual truncation step. See #115745.
+ (true, true, false) => c::OPEN_ALWAYS,
(_, _, true) => c::CREATE_NEW,
})
}
@@ -289,19 +289,42 @@ impl OpenOptions {
impl File {
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
let path = maybe_verbatim(path)?;
+ let creation = opts.get_creation_mode()?;
let handle = unsafe {
c::CreateFileW(
path.as_ptr(),
opts.get_access_mode()?,
opts.share_mode,
opts.security_attributes,
- opts.get_creation_mode()?,
+ creation,
opts.get_flags_and_attributes(),
ptr::null_mut(),
)
};
let handle = unsafe { HandleOrInvalid::from_raw_handle(handle) };
- if let Ok(handle) = handle.try_into() {
+ if let Ok(handle) = OwnedHandle::try_from(handle) {
+ // Manual truncation. See #115745.
+ if opts.truncate
+ && creation == c::OPEN_ALWAYS
+ && unsafe { c::GetLastError() } == c::ERROR_ALREADY_EXISTS
+ {
+ unsafe {
+ // This originally used `FileAllocationInfo` instead of
+ // `FileEndOfFileInfo` but that wasn't supported by WINE.
+ // It's arguable which fits the semantics of `OpenOptions`
+ // better so let's just use the more widely supported method.
+ let eof = c::FILE_END_OF_FILE_INFO { EndOfFile: 0 };
+ let result = c::SetFileInformationByHandle(
+ handle.as_raw_handle(),
+ c::FileEndOfFileInfo,
+ ptr::addr_of!(eof).cast::<c_void>(),
+ mem::size_of::<c::FILE_END_OF_FILE_INFO>() as u32,
+ );
+ if result == 0 {
+ return Err(io::Error::last_os_error());
+ }
+ }
+ }
Ok(File { handle: Handle::from_inner(handle) })
} else {
Err(Error::last_os_error())
@@ -548,7 +571,7 @@ impl File {
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)))
}
@@ -786,7 +809,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 +818,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,
@@ -874,7 +897,7 @@ impl fmt::Debug for File {
// 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 +1216,7 @@ pub fn readlink(path: &Path) -> io::Result<PathBuf> {
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 +1430,7 @@ pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(
#[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 56d0d6c08..c4495f81a 100644
--- a/library/std/src/sys/windows/handle.rs
+++ b/library/std/src/sys/windows/handle.rs
@@ -81,7 +81,7 @@ impl Handle {
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 @@ impl Handle {
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 @@ impl Handle {
Ok(read) => {
// Safety: `read` bytes were written to the initialized portion of the buffer
unsafe {
- cursor.advance(read as usize);
+ cursor.advance(read);
}
Ok(())
}
@@ -189,7 +189,7 @@ impl Handle {
}
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
- self.synchronous_write(&buf, None)
+ self.synchronous_write(buf, None)
}
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
@@ -202,7 +202,7 @@ impl Handle {
}
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
- self.synchronous_write(&buf, Some(offset))
+ self.synchronous_write(buf, Some(offset))
}
pub fn try_clone(&self) -> io::Result<Self> {
diff --git a/library/std/src/sys/windows/io.rs b/library/std/src/sys/windows/io.rs
index 9b540ee07..649826d25 100644
--- a/library/std/src/sys/windows/io.rs
+++ b/library/std/src/sys/windows/io.rs
@@ -36,7 +36,7 @@ impl<'a> IoSlice<'a> {
#[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 @@ impl<'a> IoSliceMut<'a> {
#[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/mod.rs b/library/std/src/sys/windows/mod.rs
index c4e56e13b..8b722f01a 100644
--- a/library/std/src/sys/windows/mod.rs
+++ b/library/std/src/sys/windows/mod.rs
@@ -1,6 +1,6 @@
#![allow(missing_docs, nonstandard_style)]
-use crate::ffi::{CStr, OsStr, OsString};
+use crate::ffi::{OsStr, OsString};
use crate::io::ErrorKind;
use crate::mem::MaybeUninit;
use crate::os::windows::ffi::{OsStrExt, OsStringExt};
@@ -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(&c"main");
}
// SAFETY: must be called only once during runtime cleanup.
@@ -150,7 +150,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
pub fn unrolled_find_u16s(needle: u16, haystack: &[u16]) -> Option<usize> {
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 {
diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs
index c29b86366..6cd758ec5 100644
--- a/library/std/src/sys/windows/net.rs
+++ b/library/std/src/sys/windows/net.rs
@@ -162,7 +162,7 @@ impl Socket {
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 {
diff --git a/library/std/src/sys/windows/os.rs b/library/std/src/sys/windows/os.rs
index 8cc905101..829dd5eb9 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<OsString> {
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<PathBuf> {
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) -> ! {
@@ -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/path.rs b/library/std/src/sys/windows/path.rs
index 8c0e07b35..d9684f217 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> {
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] {
@@ -104,7 +104,9 @@ pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
// The meaning of verbatim paths can change when they use a different
// separator.
- if let Some(parser) = parser.strip_prefix(r"?\") && !parser.prefix_bytes().iter().any(|&x| x == b'/') {
+ if let Some(parser) = parser.strip_prefix(r"?\")
+ && !parser.prefix_bytes().iter().any(|&x| x == b'/')
+ {
// \\?\
if let Some(parser) = parser.strip_prefix(r"UNC\") {
// \\?\UNC\server\share
@@ -145,12 +147,10 @@ pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
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)
}
}
@@ -250,7 +250,7 @@ pub(crate) fn get_long_path(mut path: Vec<u16>, 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 {
diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs
index f4078d359..9ec775959 100644
--- a/library/std/src/sys/windows/process.rs
+++ b/library/std/src/sys/windows/process.rs
@@ -245,7 +245,7 @@ impl Command {
}
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<T: Copy + Send + Sync + 'static>(
@@ -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);
}
@@ -597,7 +597,7 @@ impl Stdio {
opts.read(stdio_id == c::STD_INPUT_HANDLE);
opts.write(stdio_id != c::STD_INPUT_HANDLE);
opts.security_attributes(&mut sa);
- File::open(Path::new("NUL"), &opts).map(|file| file.into_inner())
+ File::open(Path::new(r"\\.\NUL"), &opts).map(|file| file.into_inner())
}
}
}
@@ -657,7 +657,7 @@ impl Process {
}
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<'_> {
@@ -917,9 +917,8 @@ fn make_proc_thread_attribute_list(
)
};
- let mut proc_thread_attribute_list = ProcThreadAttributeList(
- vec![MaybeUninit::uninit(); required_size as usize].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.
diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs
index a9ff909aa..819a48266 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<usiz
MaybeUninit::slice_assume_init_ref(&utf16[..result as usize])
};
- let mut written = write_u16s(handle, &utf16)?;
+ let mut written = write_u16s(handle, utf16)?;
// Figure out how many bytes of as UTF-8 were written away as UTF-16.
if written == utf16.len() {
@@ -207,7 +207,7 @@ fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result<usiz
// write the missing surrogate out now.
// Buffering it would mean we have to lie about the number of bytes written.
let first_code_unit_remaining = utf16[written];
- if first_code_unit_remaining >= 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]);
@@ -266,7 +266,7 @@ impl io::Read for Stdin {
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];
@@ -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;
diff --git a/library/std/src/sys/windows/time.rs b/library/std/src/sys/windows/time.rs
index bece48e79..09e78a293 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 @@ impl WaitableTimer {
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.