From 800ff08f046ed013a5ef62e383c8e71a125b84be Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 15 Sep 2026 14:14:20 +0200 Subject: [PATCH 1/5] Enable `--generate-link-to-definition` rustdoc option on std docs --- library/std/src/lib.rs | 13 ++ library/std/src/os/darwin/fs.rs | 94 ++++++-- library/std/src/os/linux/process.rs | 36 ++- library/std/src/os/wasi/fs.rs | 24 +- library/std/src/os/windows/ffi.rs | 8 +- library/std/src/os/windows/fs.rs | 108 ++++++--- library/std/src/os/windows/io/handle.rs | 124 ++++++---- library/std/src/os/windows/io/raw.rs | 92 +++++--- library/std/src/os/windows/io/socket.rs | 106 +++++---- library/std/src/os/windows/net/addr.rs | 26 ++- library/std/src/os/windows/net/listener.rs | 16 +- library/std/src/os/windows/net/stream.rs | 40 +++- library/std/src/os/windows/process.rs | 256 +++++++++++++-------- library/std/src/os/windows/thread.rs | 8 +- library/std/src/sys/process/unix/unix.rs | 12 +- src/bootstrap/src/core/build_steps/doc.rs | 9 +- 16 files changed, 648 insertions(+), 324 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 8ed3a46bf3189..69bdc3256a9b7 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -449,6 +449,19 @@ since = "1.90.0" )] +// Macro used when rendering with `rustdoc` to replace code with `loop {}`. +#[allow(unused_macros)] +macro_rules! no_code { + ($($code:tt)*) => { + #[cfg(not(doc))] + { + $($code)* + } + #[cfg(doc)] + loop {} + } +} + // The Rust prelude // The compiler expects the prelude definition to be defined before its use statement. pub mod prelude; diff --git a/library/std/src/os/darwin/fs.rs b/library/std/src/os/darwin/fs.rs index b41391f19dccf..5349892dbd1c1 100644 --- a/library/std/src/os/darwin/fs.rs +++ b/library/std/src/os/darwin/fs.rs @@ -89,70 +89,114 @@ impl MetadataExt for Metadata { #[allow(deprecated)] #[cfg(any(doc, target_os = "macos", target_os = "ios"))] fn as_raw_stat(&self) -> &super::raw::stat { - unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const super::raw::stat) } + no_code! { + unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const super::raw::stat) } + } } fn st_dev(&self) -> u64 { - self.as_inner().as_inner().st_dev as u64 + no_code! { + self.as_inner().as_inner().st_dev as u64 + } } fn st_ino(&self) -> u64 { - self.as_inner().as_inner().st_ino as u64 + no_code! { + self.as_inner().as_inner().st_ino as u64 + } } fn st_mode(&self) -> u32 { - self.as_inner().as_inner().st_mode as u32 + no_code! { + self.as_inner().as_inner().st_mode as u32 + } } fn st_nlink(&self) -> u64 { - self.as_inner().as_inner().st_nlink as u64 + no_code! { + self.as_inner().as_inner().st_nlink as u64 + } } fn st_uid(&self) -> u32 { - self.as_inner().as_inner().st_uid as u32 + no_code! { + self.as_inner().as_inner().st_uid as u32 + } } fn st_gid(&self) -> u32 { - self.as_inner().as_inner().st_gid as u32 + no_code! { + self.as_inner().as_inner().st_gid as u32 + } } fn st_rdev(&self) -> u64 { - self.as_inner().as_inner().st_rdev as u64 + no_code! { + self.as_inner().as_inner().st_rdev as u64 + } } fn st_size(&self) -> u64 { - self.as_inner().as_inner().st_size as u64 + no_code! { + self.as_inner().as_inner().st_size as u64 + } } fn st_atime(&self) -> i64 { - self.as_inner().as_inner().st_atime as i64 + no_code! { + self.as_inner().as_inner().st_atime as i64 + } } fn st_atime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_atime_nsec as i64 + no_code! { + self.as_inner().as_inner().st_atime_nsec as i64 + } } fn st_mtime(&self) -> i64 { - self.as_inner().as_inner().st_mtime as i64 + no_code! { + self.as_inner().as_inner().st_mtime as i64 + } } fn st_mtime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_mtime_nsec as i64 + no_code! { + self.as_inner().as_inner().st_mtime_nsec as i64 + } } fn st_ctime(&self) -> i64 { - self.as_inner().as_inner().st_ctime as i64 + no_code! { + self.as_inner().as_inner().st_ctime as i64 + } } fn st_ctime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_ctime_nsec as i64 + no_code! { + self.as_inner().as_inner().st_ctime_nsec as i64 + } } fn st_birthtime(&self) -> i64 { - self.as_inner().as_inner().st_birthtime as i64 + no_code! { + self.as_inner().as_inner().st_birthtime as i64 + } } fn st_birthtime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_birthtime_nsec as i64 + no_code! { + self.as_inner().as_inner().st_birthtime_nsec as i64 + } } fn st_blksize(&self) -> u64 { - self.as_inner().as_inner().st_blksize as u64 + no_code! { + self.as_inner().as_inner().st_blksize as u64 + } } fn st_blocks(&self) -> u64 { - self.as_inner().as_inner().st_blocks as u64 + no_code! { + self.as_inner().as_inner().st_blocks as u64 + } } fn st_gen(&self) -> u32 { - self.as_inner().as_inner().st_gen as u32 + no_code! { + self.as_inner().as_inner().st_gen as u32 + } } fn st_flags(&self) -> u32 { - self.as_inner().as_inner().st_flags as u32 + no_code! { + self.as_inner().as_inner().st_flags as u32 + } } fn st_lspare(&self) -> u32 { - self.as_inner().as_inner().st_lspare as u32 + no_code! { + self.as_inner().as_inner().st_lspare as u32 + } } #[cfg(target_os = "macos")] fn st_qspare(&self) -> [u64; 2] { @@ -172,7 +216,9 @@ pub impl(self) trait FileTimesExt { #[stable(feature = "file_set_times", since = "1.75.0")] impl FileTimesExt for fs::FileTimes { fn set_created(mut self, t: SystemTime) -> Self { - self.as_inner_mut().set_created(t.into_inner()); - self + no_code! { + self.as_inner_mut().set_created(t.into_inner()); + self + } } } diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index e0ddaa85cb82e..26f2057b6d942 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -62,7 +62,9 @@ impl PidFd { /// /// [`Child::kill`]: process::Child::kill pub fn kill(&self) -> Result<()> { - self.inner.kill() + no_code! { + self.inner.kill() + } } /// Waits for the child to exit completely, returning the status that it exited with. @@ -75,7 +77,9 @@ impl PidFd { /// /// [`Child::wait`]: process::Child::wait pub fn wait(&self) -> Result { - self.inner.wait().map(FromInner::from_inner) + no_code! { + self.inner.wait().map(FromInner::from_inner) + } } /// Attempts to collect the exit status of the child if it has already exited. @@ -85,7 +89,9 @@ impl PidFd { /// /// [`Child::try_wait`]: process::Child::try_wait pub fn try_wait(&self) -> Result> { - Ok(self.inner.try_wait()?.map(FromInner::from_inner)) + no_code! { + Ok(self.inner.try_wait()?.map(FromInner::from_inner)) + } } } @@ -111,37 +117,49 @@ impl IntoInner for PidFd { impl AsRawFd for PidFd { #[inline] fn as_raw_fd(&self) -> RawFd { - self.as_inner().as_inner().as_raw_fd() + no_code! { + self.as_inner().as_inner().as_raw_fd() + } } } impl FromRawFd for PidFd { unsafe fn from_raw_fd(fd: RawFd) -> Self { - Self::from_inner(InnerPidFd::from_raw_fd(fd)) + no_code! { + Self::from_inner(InnerPidFd::from_raw_fd(fd)) + } } } impl IntoRawFd for PidFd { fn into_raw_fd(self) -> RawFd { - self.into_inner().into_inner().into_raw_fd() + no_code! { + self.into_inner().into_inner().into_raw_fd() + } } } impl AsFd for PidFd { fn as_fd(&self) -> BorrowedFd<'_> { - self.as_inner().as_inner().as_fd() + no_code! { + self.as_inner().as_inner().as_fd() + } } } impl From for PidFd { fn from(fd: OwnedFd) -> Self { - Self::from_inner(InnerPidFd::from_inner(FileDesc::from_inner(fd))) + no_code! { + Self::from_inner(InnerPidFd::from_inner(FileDesc::from_inner(fd))) + } } } impl From for OwnedFd { fn from(pid_fd: PidFd) -> Self { - pid_fd.into_inner().into_inner().into_inner() + no_code! { + pid_fd.into_inner().into_inner().into_inner() + } } } diff --git a/library/std/src/os/wasi/fs.rs b/library/std/src/os/wasi/fs.rs index 369e5d4b0fb9d..96a18ff934ff0 100644 --- a/library/std/src/os/wasi/fs.rs +++ b/library/std/src/os/wasi/fs.rs @@ -334,13 +334,19 @@ pub trait MetadataExt { impl MetadataExt for fs::Metadata { fn dev(&self) -> u64 { - self.as_inner().as_inner().st_dev + no_code! { + self.as_inner().as_inner().st_dev + } } fn ino(&self) -> u64 { - self.as_inner().as_inner().st_ino + no_code! { + self.as_inner().as_inner().st_ino + } } fn nlink(&self) -> u64 { - self.as_inner().as_inner().st_nlink + no_code! { + self.as_inner().as_inner().st_nlink + } } } @@ -359,13 +365,19 @@ pub trait FileTypeExt { impl FileTypeExt for fs::FileType { fn is_block_device(&self) -> bool { - self.as_inner().is(libc::S_IFBLK) + no_code! { + self.as_inner().is(libc::S_IFBLK) + } } fn is_char_device(&self) -> bool { - self.as_inner().is(libc::S_IFCHR) + no_code! { + self.as_inner().is(libc::S_IFCHR) + } } fn is_socket(&self) -> bool { - self.as_inner().is(libc::S_IFSOCK) + no_code! { + self.as_inner().is(libc::S_IFSOCK) + } } } diff --git a/library/std/src/os/windows/ffi.rs b/library/std/src/os/windows/ffi.rs index b27a116f60388..d21dace2346ce 100644 --- a/library/std/src/os/windows/ffi.rs +++ b/library/std/src/os/windows/ffi.rs @@ -89,7 +89,9 @@ pub impl(self) trait OsStringExt { #[stable(feature = "rust1", since = "1.0.0")] impl OsStringExt for OsString { fn from_wide(wide: &[u16]) -> OsString { - FromInner::from_inner(Buf { inner: Wtf8Buf::from_wide(wide) }) + no_code! { + FromInner::from_inner(Buf { inner: Wtf8Buf::from_wide(wide) }) + } } } @@ -126,7 +128,9 @@ pub impl(self) trait OsStrExt { impl OsStrExt for OsStr { #[inline] fn encode_wide(&self) -> EncodeWide<'_> { - EncodeWide { inner: self.as_inner().inner.encode_wide() } + no_code! { + EncodeWide { inner: self.as_inner().inner.encode_wide() } + } } } diff --git a/library/std/src/os/windows/fs.rs b/library/std/src/os/windows/fs.rs index 865cc90e83156..ec60272e8c89d 100644 --- a/library/std/src/os/windows/fs.rs +++ b/library/std/src/os/windows/fs.rs @@ -494,28 +494,38 @@ pub trait OpenOptionsExt { #[stable(feature = "open_options_ext", since = "1.10.0")] impl OpenOptionsExt for OpenOptions { fn access_mode(&mut self, access: u32) -> &mut OpenOptions { - self.as_inner_mut().access_mode(access); - self + no_code! { + self.as_inner_mut().access_mode(access); + self + } } fn share_mode(&mut self, share: u32) -> &mut OpenOptions { - self.as_inner_mut().share_mode(share); - self + no_code! { + self.as_inner_mut().share_mode(share); + self + } } fn custom_flags(&mut self, flags: u32) -> &mut OpenOptions { - self.as_inner_mut().custom_flags(flags); - self + no_code! { + self.as_inner_mut().custom_flags(flags); + self + } } fn attributes(&mut self, attributes: u32) -> &mut OpenOptions { - self.as_inner_mut().attributes(attributes); - self + no_code! { + self.as_inner_mut().attributes(attributes); + self + } } fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions { - self.as_inner_mut().security_qos_flags(flags); - self + no_code! { + self.as_inner_mut().security_qos_flags(flags); + self + } } } @@ -537,13 +547,17 @@ pub impl(self) trait OpenOptionsExt2 { #[unstable(feature = "windows_freeze_file_times", issue = "149715")] impl OpenOptionsExt2 for OpenOptions { fn freeze_last_access_time(&mut self, freeze: bool) -> &mut Self { - self.as_inner_mut().freeze_last_access_time(freeze); - self + no_code! { + self.as_inner_mut().freeze_last_access_time(freeze); + self + } } fn freeze_last_write_time(&mut self, freeze: bool) -> &mut Self { - self.as_inner_mut().freeze_last_write_time(freeze); - self + no_code! { + self.as_inner_mut().freeze_last_write_time(freeze); + self + } } } @@ -595,7 +609,9 @@ pub impl(self) trait PermissionsExt { #[unstable(feature = "windows_permissions_ext", issue = "152956")] impl PermissionsExt for fs::Permissions { fn file_attributes(&self) -> u32 { - self.as_inner().file_attributes() + no_code! { + self.as_inner().file_attributes() + } } fn set_file_attributes(&mut self, mask: u32) { @@ -806,31 +822,49 @@ pub trait MetadataExt { #[stable(feature = "metadata_ext", since = "1.1.0")] impl MetadataExt for Metadata { fn file_attributes(&self) -> u32 { - self.as_inner().attrs() + no_code! { + self.as_inner().attrs() + } } fn creation_time(&self) -> u64 { - self.as_inner().created_u64() + no_code! { + self.as_inner().created_u64() + } } fn last_access_time(&self) -> u64 { - self.as_inner().accessed_u64() + no_code! { + self.as_inner().accessed_u64() + } } fn last_write_time(&self) -> u64 { - self.as_inner().modified_u64() + no_code! { + self.as_inner().modified_u64() + } } fn file_size(&self) -> u64 { - self.as_inner().size() + no_code! { + self.as_inner().size() + } } fn volume_serial_number(&self) -> Option { - self.as_inner().volume_serial_number() + no_code! { + self.as_inner().volume_serial_number() + } } fn number_of_links(&self) -> Option { - self.as_inner().number_of_links() + no_code! { + self.as_inner().number_of_links() + } } fn file_index(&self) -> Option { - self.as_inner().file_index() + no_code! { + self.as_inner().file_index() + } } fn change_time(&self) -> Option { - self.as_inner().changed_u64() + no_code! { + self.as_inner().changed_u64() + } } } @@ -850,10 +884,14 @@ pub impl(self) trait FileTypeExt { #[stable(feature = "windows_file_type_ext", since = "1.64.0")] impl FileTypeExt for fs::FileType { fn is_symlink_dir(&self) -> bool { - self.as_inner().is_symlink_dir() + no_code! { + self.as_inner().is_symlink_dir() + } } fn is_symlink_file(&self) -> bool { - self.as_inner().is_symlink_file() + no_code! { + self.as_inner().is_symlink_file() + } } } @@ -868,8 +906,10 @@ pub impl(self) trait FileTimesExt { #[stable(feature = "file_set_times", since = "1.75.0")] impl FileTimesExt for fs::FileTimes { fn set_created(mut self, t: SystemTime) -> Self { - self.as_inner_mut().set_created(t.into_inner()); - self + no_code! { + self.as_inner_mut().set_created(t.into_inner()); + self + } } } @@ -912,7 +952,9 @@ impl FileTimesExt for fs::FileTimes { #[stable(feature = "symlink", since = "1.1.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "fs_symlink_file")] pub fn symlink_file, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - sys::fs::symlink_inner(original.as_ref(), link.as_ref(), false) + no_code! { + sys::fs::symlink_inner(original.as_ref(), link.as_ref(), false) + } } /// Creates a new symlink to a directory on the filesystem. @@ -954,7 +996,9 @@ pub fn symlink_file, Q: AsRef>(original: P, link: Q) -> io: #[stable(feature = "symlink", since = "1.1.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "fs_symlink_dir")] pub fn symlink_dir, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - sys::fs::symlink_inner(original.as_ref(), link.as_ref(), true) + no_code! { + sys::fs::symlink_inner(original.as_ref(), link.as_ref(), true) + } } /// Creates a junction point. @@ -966,5 +1010,7 @@ pub fn symlink_dir, Q: AsRef>(original: P, link: Q) -> io:: /// If either path is not a local file path then this will fail. #[unstable(feature = "junction_point", issue = "121709")] pub fn junction_point, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - sys::fs::junction_point(original.as_ref(), link.as_ref()) + no_code! { + sys::fs::junction_point(original.as_ref(), link.as_ref()) + } } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index ec20baf2bf2ce..96db1c06318b9 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -194,9 +194,11 @@ impl TryFrom for OwnedHandle { impl Drop for HandleOrNull { #[inline] fn drop(&mut self) { - if self.is_valid() { - unsafe { - let _ = sys::c::CloseHandle(self.0); + no_code! { + if self.is_valid() { + unsafe { + let _ = sys::c::CloseHandle(self.0); + } } } } @@ -216,7 +218,9 @@ impl BorrowedHandle<'_> { /// object as the existing `BorrowedHandle` instance. #[stable(feature = "io_safety", since = "1.63.0")] pub fn try_clone_to_owned(&self) -> io::Result { - self.duplicate(0, false, sys::c::DUPLICATE_SAME_ACCESS) + no_code! { + self.duplicate(0, false, sys::c::DUPLICATE_SAME_ACCESS) + } } pub(crate) fn duplicate( @@ -225,30 +229,32 @@ impl BorrowedHandle<'_> { inherit: bool, options: u32, ) -> io::Result { - let handle = self.as_raw_handle(); - - // `Stdin`, `Stdout`, and `Stderr` can all hold null handles, such as - // in a process with a detached console. `DuplicateHandle` would fail - // if we passed it a null handle, but we can treat null as a valid - // handle which doesn't do any I/O, and allow it to be duplicated. - if handle.is_null() { - return unsafe { Ok(OwnedHandle::from_raw_handle(handle)) }; - } + no_code! { + let handle = self.as_raw_handle(); + + // `Stdin`, `Stdout`, and `Stderr` can all hold null handles, such as + // in a process with a detached console. `DuplicateHandle` would fail + // if we passed it a null handle, but we can treat null as a valid + // handle which doesn't do any I/O, and allow it to be duplicated. + if handle.is_null() { + return unsafe { Ok(OwnedHandle::from_raw_handle(handle)) }; + } - let mut ret = ptr::null_mut(); - cvt(unsafe { - let cur_proc = sys::c::GetCurrentProcess(); - sys::c::DuplicateHandle( - cur_proc, - handle, - cur_proc, - &mut ret, - access, - inherit as sys::c::BOOL, - options, - ) - })?; - unsafe { Ok(OwnedHandle::from_raw_handle(ret)) } + let mut ret = ptr::null_mut(); + cvt(unsafe { + let cur_proc = sys::c::GetCurrentProcess(); + sys::c::DuplicateHandle( + cur_proc, + handle, + cur_proc, + &mut ret, + access, + inherit as sys::c::BOOL, + options, + ) + })?; + unsafe { Ok(OwnedHandle::from_raw_handle(ret)) } + } } } @@ -272,9 +278,11 @@ impl TryFrom for OwnedHandle { impl Drop for HandleOrInvalid { #[inline] fn drop(&mut self) { - if self.is_valid() { - unsafe { - let _ = sys::c::CloseHandle(self.0); + no_code! { + if self.is_valid() { + unsafe { + let _ = sys::c::CloseHandle(self.0); + } } } } @@ -492,7 +500,9 @@ impl AsHandle for &mut T { impl AsHandle for crate::sync::Arc { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { - (**self).as_handle() + no_code! { + (**self).as_handle() + } } } @@ -500,7 +510,9 @@ impl AsHandle for crate::sync::Arc { impl AsHandle for crate::rc::Rc { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { - (**self).as_handle() + no_code! { + (**self).as_handle() + } } } @@ -508,7 +520,9 @@ impl AsHandle for crate::rc::Rc { impl AsHandle for crate::rc::UniqueRc { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { - (**self).as_handle() + no_code! { + (**self).as_handle() + } } } @@ -516,7 +530,9 @@ impl AsHandle for crate::rc::UniqueRc { impl AsHandle for Box { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { - (**self).as_handle() + no_code! { + (**self).as_handle() + } } } @@ -543,7 +559,9 @@ impl AsHandle for OwnedHandle { impl AsHandle for fs::File { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { - self.as_inner().as_handle() + no_code! { + self.as_inner().as_handle() + } } } @@ -552,7 +570,9 @@ impl From for OwnedHandle { /// Takes ownership of a [`File`](fs::File)'s underlying file handle. #[inline] fn from(file: fs::File) -> OwnedHandle { - file.into_inner().into_inner().into_inner() + no_code! { + file.into_inner().into_inner().into_inner() + } } } @@ -561,7 +581,9 @@ impl From for fs::File { /// Returns a [`File`](fs::File) that takes ownership of the given handle. #[inline] fn from(owned: OwnedHandle) -> Self { - Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned))) + no_code! { + Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned))) + } } } @@ -676,28 +698,36 @@ impl AsHandle for crate::thread::JoinHandle { impl From> for OwnedHandle { #[inline] fn from(join_handle: crate::thread::JoinHandle) -> OwnedHandle { - join_handle.into_inner().into_handle().into_inner() + no_code! { + join_handle.into_inner().into_handle().into_inner() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsHandle for io::PipeReader { fn as_handle(&self) -> BorrowedHandle<'_> { - self.0.as_handle() + no_code! { + self.0.as_handle() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for OwnedHandle { fn from(pipe: io::PipeReader) -> Self { - pipe.into_inner().into_inner() + no_code! { + pipe.into_inner().into_inner() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsHandle for io::PipeWriter { fn as_handle(&self) -> BorrowedHandle<'_> { - self.0.as_handle() + no_code! { + self.0.as_handle() + } } } @@ -747,20 +777,26 @@ unsafe_impl_handle_asrefs!(crate::fs::File, io::PipeWriter, io::PipeReader,); #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for OwnedHandle { fn from(pipe: io::PipeWriter) -> Self { - pipe.into_inner().into_inner() + no_code! { + pipe.into_inner().into_inner() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for io::PipeReader { fn from(owned_handle: OwnedHandle) -> Self { - Self::from_inner(FromInner::from_inner(owned_handle)) + no_code! { + Self::from_inner(FromInner::from_inner(owned_handle)) + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for io::PipeWriter { fn from(owned_handle: OwnedHandle) -> Self { - Self::from_inner(FromInner::from_inner(owned_handle)) + no_code! { + Self::from_inner(FromInner::from_inner(owned_handle)) + } } } diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index d050c28832517..bd1601fc5c5fd 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -94,7 +94,9 @@ pub trait IntoRawHandle { impl AsRawHandle for fs::File { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.as_inner().as_raw_handle() as RawHandle + no_code! { + self.as_inner().as_raw_handle() as RawHandle + } } } @@ -156,11 +158,13 @@ pub(super) fn stdio_handle(raw: RawHandle) -> RawHandle { impl FromRawHandle for fs::File { #[inline] unsafe fn from_raw_handle(handle: RawHandle) -> fs::File { - unsafe { - let handle = handle as sys::c::HANDLE; - fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner( - OwnedHandle::from_raw_handle(handle), - ))) + no_code! { + unsafe { + let handle = handle as sys::c::HANDLE; + fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner( + OwnedHandle::from_raw_handle(handle), + ))) + } } } } @@ -169,7 +173,9 @@ impl FromRawHandle for fs::File { impl IntoRawHandle for fs::File { #[inline] fn into_raw_handle(self) -> RawHandle { - self.into_inner().into_raw_handle() as *mut _ + no_code! { + self.into_inner().into_raw_handle() as *mut _ + } } } @@ -238,21 +244,27 @@ pub trait IntoRawSocket { impl AsRawSocket for net::TcpStream { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.as_inner().socket().as_raw_socket() + no_code! { + self.as_inner().socket().as_raw_socket() + } } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawSocket for net::TcpListener { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.as_inner().socket().as_raw_socket() + no_code! { + self.as_inner().socket().as_raw_socket() + } } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawSocket for net::UdpSocket { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.as_inner().socket().as_raw_socket() + no_code! { + self.as_inner().socket().as_raw_socket() + } } } @@ -260,9 +272,11 @@ impl AsRawSocket for net::UdpSocket { impl FromRawSocket for net::TcpStream { #[inline] unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream { - unsafe { - let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); - net::TcpStream::from_inner(sys::net::TcpStream::from_inner(sock)) + no_code! { + unsafe { + let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); + net::TcpStream::from_inner(sys::net::TcpStream::from_inner(sock)) + } } } } @@ -270,9 +284,11 @@ impl FromRawSocket for net::TcpStream { impl FromRawSocket for net::TcpListener { #[inline] unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener { - unsafe { - let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); - net::TcpListener::from_inner(sys::net::TcpListener::from_inner(sock)) + no_code! { + unsafe { + let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); + net::TcpListener::from_inner(sys::net::TcpListener::from_inner(sock)) + } } } } @@ -280,9 +296,11 @@ impl FromRawSocket for net::TcpListener { impl FromRawSocket for net::UdpSocket { #[inline] unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket { - unsafe { - let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); - net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(sock)) + no_code! { + unsafe { + let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); + net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(sock)) + } } } } @@ -291,7 +309,9 @@ impl FromRawSocket for net::UdpSocket { impl IntoRawSocket for net::TcpStream { #[inline] fn into_raw_socket(self) -> RawSocket { - self.into_inner().into_socket().into_inner().into_raw_socket() + no_code! { + self.into_inner().into_socket().into_inner().into_raw_socket() + } } } @@ -299,7 +319,9 @@ impl IntoRawSocket for net::TcpStream { impl IntoRawSocket for net::TcpListener { #[inline] fn into_raw_socket(self) -> RawSocket { - self.into_inner().into_socket().into_inner().into_raw_socket() + no_code! { + self.into_inner().into_socket().into_inner().into_raw_socket() + } } } @@ -307,48 +329,62 @@ impl IntoRawSocket for net::TcpListener { impl IntoRawSocket for net::UdpSocket { #[inline] fn into_raw_socket(self) -> RawSocket { - self.into_inner().into_socket().into_inner().into_raw_socket() + no_code! { + self.into_inner().into_socket().into_inner().into_raw_socket() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsRawHandle for io::PipeReader { fn as_raw_handle(&self) -> RawHandle { - self.0.as_raw_handle() + no_code! { + self.0.as_raw_handle() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl FromRawHandle for io::PipeReader { unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self { - unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } + no_code! { + unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl IntoRawHandle for io::PipeReader { fn into_raw_handle(self) -> RawHandle { - self.0.into_raw_handle() + no_code! { + self.0.into_raw_handle() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsRawHandle for io::PipeWriter { fn as_raw_handle(&self) -> RawHandle { - self.0.as_raw_handle() + no_code! { + self.0.as_raw_handle() + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl FromRawHandle for io::PipeWriter { unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self { - unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } + no_code! { + unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } + } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl IntoRawHandle for io::PipeWriter { fn into_raw_handle(self) -> RawHandle { - self.0.into_raw_handle() + no_code! { + self.0.into_raw_handle() + } } } diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index d625a9ac52730..dd4476bac4bd0 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -79,14 +79,16 @@ impl OwnedSocket { #[allow(implicit_provenance_casts)] #[cfg(not(target_vendor = "uwp"))] pub(crate) fn set_no_inherit(&self) -> io::Result<()> { - cvt(unsafe { - sys::c::SetHandleInformation( - self.as_raw_socket() as sys::c::HANDLE, - sys::c::HANDLE_FLAG_INHERIT, - 0, - ) - }) - .map(drop) + no_code! { + cvt(unsafe { + sys::c::SetHandleInformation( + self.as_raw_socket() as sys::c::HANDLE, + sys::c::HANDLE_FLAG_INHERIT, + 0, + ) + }) + .map(drop) + } } #[cfg(target_vendor = "uwp")] @@ -100,35 +102,16 @@ impl BorrowedSocket<'_> { /// object as the existing `BorrowedSocket` instance. #[stable(feature = "io_safety", since = "1.63.0")] pub fn try_clone_to_owned(&self) -> io::Result { - let mut info = unsafe { mem::zeroed::() }; - let result = unsafe { - sys::c::WSADuplicateSocketW( - self.as_raw_socket() as sys::c::SOCKET, - sys::c::GetCurrentProcessId(), - &mut info, - ) - }; - sys::net::cvt(result)?; - let socket = unsafe { - sys::c::WSASocketW( - info.iAddressFamily, - info.iSocketType, - info.iProtocol, - &info, - 0, - sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT, - ) - }; - - if socket != sys::c::INVALID_SOCKET { - unsafe { Ok(OwnedSocket::from_raw_socket(socket as RawSocket)) } - } else { - let error = unsafe { sys::c::WSAGetLastError() }; - - if error != sys::c::WSAEPROTOTYPE && error != sys::c::WSAEINVAL { - return Err(io::Error::from_raw_os_error(error)); - } - + no_code! { + let mut info = unsafe { mem::zeroed::() }; + let result = unsafe { + sys::c::WSADuplicateSocketW( + self.as_raw_socket() as sys::c::SOCKET, + sys::c::GetCurrentProcessId(), + &mut info, + ) + }; + sys::net::cvt(result)?; let socket = unsafe { sys::c::WSASocketW( info.iAddressFamily, @@ -136,18 +119,39 @@ impl BorrowedSocket<'_> { info.iProtocol, &info, 0, - sys::c::WSA_FLAG_OVERLAPPED, + sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT, ) }; - if socket == sys::c::INVALID_SOCKET { - return Err(last_error()); - } - - unsafe { - let socket = OwnedSocket::from_raw_socket(socket as RawSocket); - socket.set_no_inherit()?; - Ok(socket) + if socket != sys::c::INVALID_SOCKET { + unsafe { Ok(OwnedSocket::from_raw_socket(socket as RawSocket)) } + } else { + let error = unsafe { sys::c::WSAGetLastError() }; + + if error != sys::c::WSAEPROTOTYPE && error != sys::c::WSAEINVAL { + return Err(io::Error::from_raw_os_error(error)); + } + + let socket = unsafe { + sys::c::WSASocketW( + info.iAddressFamily, + info.iSocketType, + info.iProtocol, + &info, + 0, + sys::c::WSA_FLAG_OVERLAPPED, + ) + }; + + if socket == sys::c::INVALID_SOCKET { + return Err(last_error()); + } + + unsafe { + let socket = OwnedSocket::from_raw_socket(socket as RawSocket); + socket.set_no_inherit()?; + Ok(socket) + } } } } @@ -155,7 +159,9 @@ impl BorrowedSocket<'_> { /// Returns the last error from the Windows socket interface. fn last_error() -> io::Error { - io::Error::from_raw_os_error(unsafe { sys::c::WSAGetLastError() }) + no_code! { + io::Error::from_raw_os_error(unsafe { sys::c::WSAGetLastError() }) + } } #[stable(feature = "io_safety", since = "1.63.0")] @@ -195,8 +201,10 @@ impl FromRawSocket for OwnedSocket { impl Drop for OwnedSocket { #[inline] fn drop(&mut self) { - unsafe { - let _ = sys::c::closesocket(self.socket.as_inner() as sys::c::SOCKET); + no_code! { + unsafe { + let _ = sys::c::closesocket(self.socket.as_inner() as sys::c::SOCKET); + } } } } diff --git a/library/std/src/os/windows/net/addr.rs b/library/std/src/os/windows/net/addr.rs index 5f6b93e56e723..614579762573c 100644 --- a/library/std/src/os/windows/net/addr.rs +++ b/library/std/src/os/windows/net/addr.rs @@ -131,20 +131,24 @@ impl SocketAddr { where P: AsRef, { - sockaddr_un(path.as_ref()).map(|(addr, len)| SocketAddr { addr, len: len as _ }) + no_code! { + sockaddr_un(path.as_ref()).map(|(addr, len)| SocketAddr { addr, len: len as _ }) + } } fn address(&self) -> AddressKind<'_> { - let len = self.len as usize - SUN_PATH_OFFSET; - let path = unsafe { mem::transmute::<&[i8], &[u8]>(&self.addr.sun_path) }; + no_code! { + let len = self.len as usize - SUN_PATH_OFFSET; + let path = unsafe { mem::transmute::<&[i8], &[u8]>(&self.addr.sun_path) }; - if len == 0 { - AddressKind::Unnamed - } else if self.addr.sun_path[0] == 0 { - AddressKind::Abstract(ByteStr::from_bytes(&path[1..len])) - } else { - AddressKind::Pathname(unsafe { - OsStr::from_encoded_bytes_unchecked(&path[..len - 1]).as_ref() - }) + if len == 0 { + AddressKind::Unnamed + } else if self.addr.sun_path[0] == 0 { + AddressKind::Abstract(ByteStr::from_bytes(&path[1..len])) + } else { + AddressKind::Pathname(unsafe { + OsStr::from_encoded_bytes_unchecked(&path[..len - 1]).as_ref() + }) + } } } diff --git a/library/std/src/os/windows/net/listener.rs b/library/std/src/os/windows/net/listener.rs index 19f5254e08bf9..5749747b3adee 100644 --- a/library/std/src/os/windows/net/listener.rs +++ b/library/std/src/os/windows/net/listener.rs @@ -164,7 +164,9 @@ impl UnixListener { /// } /// ``` pub fn local_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) + no_code! { + SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) + } } /// Creates a new independently owned handle to the underlying socket. @@ -326,21 +328,27 @@ impl<'a> Iterator for Incoming<'a> { impl AsRawSocket for UnixListener { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.0.as_raw_socket() + no_code! { + self.0.as_raw_socket() + } } } impl FromRawSocket for UnixListener { #[inline] unsafe fn from_raw_socket(sock: RawSocket) -> Self { - UnixListener(unsafe { Socket::from_raw_socket(sock) }) + no_code! { + UnixListener(unsafe { Socket::from_raw_socket(sock) }) + } } } impl IntoRawSocket for UnixListener { #[inline] fn into_raw_socket(self) -> RawSocket { - self.0.into_raw_socket() + no_code! { + self.0.into_raw_socket() + } } } diff --git a/library/std/src/os/windows/net/stream.rs b/library/std/src/os/windows/net/stream.rs index c0f32e75411e9..1df01b8b527d5 100644 --- a/library/std/src/os/windows/net/stream.rs +++ b/library/std/src/os/windows/net/stream.rs @@ -127,7 +127,9 @@ impl UnixStream { /// } /// ``` pub fn local_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) + no_code! { + SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) + } } /// Returns the socket address of the remote half of this connection. @@ -146,7 +148,9 @@ impl UnixStream { /// } /// ``` pub fn peer_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { getpeername(self.0.as_raw(), addr, len) }) + no_code! { + SocketAddr::new(|addr, len| unsafe { getpeername(self.0.as_raw(), addr, len) }) + } } /// Returns the read timeout of this socket. @@ -167,7 +171,9 @@ impl UnixStream { /// } /// ``` pub fn read_timeout(&self) -> io::Result> { - self.0.timeout(SO_RCVTIMEO) + no_code! { + self.0.timeout(SO_RCVTIMEO) + } } /// Moves the socket into or out of nonblocking mode. @@ -231,7 +237,9 @@ impl UnixStream { /// } /// ``` pub fn set_read_timeout(&self, dur: Option) -> io::Result<()> { - self.0.set_timeout(dur, SO_RCVTIMEO) + no_code! { + self.0.set_timeout(dur, SO_RCVTIMEO) + } } /// Sets the write timeout for the socket. @@ -277,7 +285,9 @@ impl UnixStream { /// } /// ``` pub fn set_write_timeout(&self, dur: Option) -> io::Result<()> { - self.0.set_timeout(dur, SO_SNDTIMEO) + no_code! { + self.0.set_timeout(dur, SO_SNDTIMEO) + } } /// Shuts down the read, write, or both halves of this connection. @@ -368,7 +378,9 @@ impl UnixStream { /// } /// ``` pub fn write_timeout(&self) -> io::Result> { - self.0.timeout(SO_SNDTIMEO) + no_code! { + self.0.timeout(SO_SNDTIMEO) + } } } @@ -413,26 +425,34 @@ impl<'a> io::Write for &'a UnixStream { impl AsSocket for UnixStream { #[inline] fn as_socket(&self) -> BorrowedSocket<'_> { - self.0.as_socket() + no_code! { + self.0.as_socket() + } } } impl AsRawSocket for UnixStream { #[inline] fn as_raw_socket(&self) -> RawSocket { - self.0.as_raw_socket() + no_code! { + self.0.as_raw_socket() + } } } impl FromRawSocket for UnixStream { #[inline] unsafe fn from_raw_socket(sock: RawSocket) -> Self { - unsafe { UnixStream(Socket::from_raw_socket(sock)) } + no_code! { + unsafe { UnixStream(Socket::from_raw_socket(sock)) } + } } } impl IntoRawSocket for UnixStream { fn into_raw_socket(self) -> RawSocket { - self.0.into_raw_socket() + no_code! { + self.0.into_raw_socket() + } } } diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index f4b60f2ed8eca..568bd45f01da3 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -15,9 +15,11 @@ use crate::{io, marker, process, ptr, sys}; #[stable(feature = "process_extensions", since = "1.2.0")] impl FromRawHandle for process::Stdio { unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio { - let handle = unsafe { sys::handle::Handle::from_raw_handle(handle as *mut _) }; - let io = sys::process::Stdio::Handle(handle); - process::Stdio::from_inner(io) + no_code! { + let handle = unsafe { sys::handle::Handle::from_raw_handle(handle as *mut _) }; + let io = sys::process::Stdio::Handle(handle); + process::Stdio::from_inner(io) + } } } @@ -26,9 +28,11 @@ impl From for process::Stdio { /// Takes ownership of a handle and returns a [`Stdio`](process::Stdio) /// that can attach a stream to it. fn from(handle: OwnedHandle) -> process::Stdio { - let handle = sys::handle::Handle::from_inner(handle); - let io = sys::process::Stdio::Handle(handle); - process::Stdio::from_inner(io) + no_code! { + let handle = sys::handle::Handle::from_inner(handle); + let io = sys::process::Stdio::Handle(handle); + process::Stdio::from_inner(io) + } } } @@ -36,7 +40,9 @@ impl From for process::Stdio { impl AsRawHandle for process::Child { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.as_inner().handle().as_raw_handle() as *mut _ + no_code! { + self.as_inner().handle().as_raw_handle() as *mut _ + } } } @@ -44,14 +50,18 @@ impl AsRawHandle for process::Child { impl AsHandle for process::Child { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { - self.as_inner().handle().as_handle() + no_code! { + self.as_inner().handle().as_handle() + } } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::Child { fn into_raw_handle(self) -> RawHandle { - self.into_inner().into_handle().into_raw_handle() as *mut _ + no_code! { + self.into_inner().into_handle().into_raw_handle() as *mut _ + } } } @@ -59,7 +69,9 @@ impl IntoRawHandle for process::Child { impl From for OwnedHandle { /// Takes ownership of a [`Child`](process::Child)'s process handle. fn from(child: process::Child) -> OwnedHandle { - child.into_inner().into_handle().into_inner() + no_code! { + child.into_inner().into_handle().into_inner() + } } } @@ -67,7 +79,9 @@ impl From for OwnedHandle { impl AsRawHandle for process::ChildStdin { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.as_inner().handle().as_raw_handle() as *mut _ + no_code! { + self.as_inner().handle().as_raw_handle() as *mut _ + } } } @@ -75,7 +89,9 @@ impl AsRawHandle for process::ChildStdin { impl AsRawHandle for process::ChildStdout { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.as_inner().handle().as_raw_handle() as *mut _ + no_code! { + self.as_inner().handle().as_raw_handle() as *mut _ + } } } @@ -83,28 +99,36 @@ impl AsRawHandle for process::ChildStdout { impl AsRawHandle for process::ChildStderr { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.as_inner().handle().as_raw_handle() as *mut _ + no_code! { + self.as_inner().handle().as_raw_handle() as *mut _ + } } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::ChildStdin { fn into_raw_handle(self) -> RawHandle { - self.into_inner().into_handle().into_raw_handle() as *mut _ + no_code! { + self.into_inner().into_handle().into_raw_handle() as *mut _ + } } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::ChildStdout { fn into_raw_handle(self) -> RawHandle { - self.into_inner().into_handle().into_raw_handle() as *mut _ + no_code! { + self.into_inner().into_handle().into_raw_handle() as *mut _ + } } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::ChildStderr { fn into_raw_handle(self) -> RawHandle { - self.into_inner().into_handle().into_raw_handle() as *mut _ + no_code! { + self.into_inner().into_handle().into_raw_handle() as *mut _ + } } } @@ -115,9 +139,11 @@ impl IntoRawHandle for process::ChildStderr { #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStdin { fn from(handle: OwnedHandle) -> process::ChildStdin { - let handle = sys::handle::Handle::from_inner(handle); - let pipe = sys::process::ChildPipe::from_inner(handle); - process::ChildStdin::from_inner(pipe) + no_code! { + let handle = sys::handle::Handle::from_inner(handle); + let pipe = sys::process::ChildPipe::from_inner(handle); + process::ChildStdin::from_inner(pipe) + } } } @@ -128,9 +154,11 @@ impl From for process::ChildStdin { #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStdout { fn from(handle: OwnedHandle) -> process::ChildStdout { - let handle = sys::handle::Handle::from_inner(handle); - let pipe = sys::process::ChildPipe::from_inner(handle); - process::ChildStdout::from_inner(pipe) + no_code! { + let handle = sys::handle::Handle::from_inner(handle); + let pipe = sys::process::ChildPipe::from_inner(handle); + process::ChildStdout::from_inner(pipe) + } } } @@ -141,9 +169,11 @@ impl From for process::ChildStdout { #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStderr { fn from(handle: OwnedHandle) -> process::ChildStderr { - let handle = sys::handle::Handle::from_inner(handle); - let pipe = sys::process::ChildPipe::from_inner(handle); - process::ChildStderr::from_inner(pipe) + no_code! { + let handle = sys::handle::Handle::from_inner(handle); + let pipe = sys::process::ChildPipe::from_inner(handle); + process::ChildStderr::from_inner(pipe) + } } } @@ -159,7 +189,9 @@ pub impl(self) trait ExitStatusExt { #[stable(feature = "exit_status_from", since = "1.12.0")] impl ExitStatusExt for process::ExitStatus { fn from_raw(raw: u32) -> Self { - process::ExitStatus::from_inner(From::from(raw)) + no_code! { + process::ExitStatus::from_inner(From::from(raw)) + } } } @@ -391,28 +423,38 @@ pub impl(self) trait CommandExt { #[stable(feature = "windows_process_extensions", since = "1.16.0")] impl CommandExt for process::Command { fn creation_flags(&mut self, flags: u32) -> &mut process::Command { - self.as_inner_mut().creation_flags(flags); - self + no_code! { + self.as_inner_mut().creation_flags(flags); + self + } } fn desktop>(&mut self, desktop: S) -> &mut process::Command { - self.as_inner_mut().desktop(desktop.as_ref()); - self + no_code! { + self.as_inner_mut().desktop(desktop.as_ref()); + self + } } fn show_window(&mut self, cmd_show: u16) -> &mut process::Command { - self.as_inner_mut().show_window(Some(cmd_show)); - self + no_code! { + self.as_inner_mut().show_window(Some(cmd_show)); + self + } } fn force_quotes(&mut self, enabled: bool) -> &mut process::Command { - self.as_inner_mut().force_quotes(enabled); - self + no_code! { + self.as_inner_mut().force_quotes(enabled); + self + } } fn raw_arg>(&mut self, raw_text: S) -> &mut process::Command { - self.as_inner_mut().raw_arg(raw_text.as_ref()); - self + no_code! { + self.as_inner_mut().raw_arg(raw_text.as_ref()); + self + } } fn async_pipes(&mut self, always_async: bool) -> &mut process::Command { @@ -428,29 +470,39 @@ impl CommandExt for process::Command { &mut self, attribute_list: &ProcThreadAttributeList<'_>, ) -> io::Result { - self.as_inner_mut() - .spawn_with_attributes(sys::process::Stdio::Inherit, true, Some(attribute_list)) - .map(process::Child::from_inner) + no_code! { + self.as_inner_mut() + .spawn_with_attributes(sys::process::Stdio::Inherit, true, Some(attribute_list)) + .map(process::Child::from_inner) + } } fn startupinfo_fullscreen(&mut self, enabled: bool) -> &mut process::Command { - self.as_inner_mut().startupinfo_fullscreen(enabled); - self + no_code! { + self.as_inner_mut().startupinfo_fullscreen(enabled); + self + } } fn startupinfo_untrusted_source(&mut self, enabled: bool) -> &mut process::Command { - self.as_inner_mut().startupinfo_untrusted_source(enabled); - self + no_code! { + self.as_inner_mut().startupinfo_untrusted_source(enabled); + self + } } fn startupinfo_force_feedback(&mut self, enabled: Option) -> &mut process::Command { - self.as_inner_mut().startupinfo_force_feedback(enabled); - self + no_code! { + self.as_inner_mut().startupinfo_force_feedback(enabled); + self + } } fn inherit_handles(&mut self, inherit_handles: bool) -> &mut process::Command { - self.as_inner_mut().inherit_handles(inherit_handles); - self + no_code! { + self.as_inner_mut().inherit_handles(inherit_handles); + self + } } } @@ -464,7 +516,9 @@ pub impl(self) trait ChildExt { #[stable(feature = "windows_process_extensions_main_thread_handle", since = "1.100.0")] impl ChildExt for process::Child { fn main_thread_handle(&self) -> BorrowedHandle<'_> { - self.handle.main_thread_handle() + no_code! { + self.handle.main_thread_handle() + } } } @@ -484,7 +538,9 @@ pub impl(self) trait ExitCodeExt { #[stable(feature = "windows_process_exit_code_from", since = "CURRENT_RUSTC_VERSION")] impl ExitCodeExt for process::ExitCode { fn from_raw(raw: u32) -> Self { - process::ExitCode::from_inner(From::from(raw)) + no_code! { + process::ExitCode::from_inner(From::from(raw)) + } } } @@ -521,9 +577,11 @@ impl<'a> Drop for ProcThreadAttributeList<'a> { /// /// [1]: fn drop(&mut self) { - let lp_attribute_list = - self.attribute_list.as_mut_ptr().cast::(); - unsafe { sys::c::DeleteProcThreadAttributeList(lp_attribute_list) } + no_code! { + let lp_attribute_list = + self.attribute_list.as_mut_ptr().cast::(); + unsafe { sys::c::DeleteProcThreadAttributeList(lp_attribute_list) } + } } } @@ -667,58 +725,60 @@ impl<'a> ProcThreadAttributeListBuilder<'a> { /// Returns an error if the maximum number of attributes is exceeded /// or if there is an I/O error during initialization. pub fn finish(&self) -> io::Result> { - // To initialize our ProcThreadAttributeList, we need to determine - // how many bytes to allocate for it. The Windows API simplifies this - // process by allowing us to call `InitializeProcThreadAttributeList` - // with a null pointer to retrieve the required size. - let mut required_size = 0; - let Ok(attribute_count) = self.attributes.len().try_into() else { - return Err(io::const_error!( - io::ErrorKind::InvalidInput, - "maximum number of ProcThreadAttributes exceeded", - )); - }; - unsafe { - sys::c::InitializeProcThreadAttributeList( - ptr::null_mut(), - attribute_count, - 0, - &mut required_size, - ) - }; - - let mut attribute_list = 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. - sys::cvt(unsafe { - sys::c::InitializeProcThreadAttributeList( - attribute_list.as_mut_ptr().cast::(), - attribute_count, - 0, - &mut required_size, - ) - })?; - - // # Add our attributes to the buffer. - // It's theoretically possible for the attribute count to exceed a u32 - // value. Therefore, we ensure that we don't add more attributes than - // the buffer was initialized for. - for (&attribute, value) in self.attributes.iter().take(attribute_count as usize) { + no_code! { + // To initialize our ProcThreadAttributeList, we need to determine + // how many bytes to allocate for it. The Windows API simplifies this + // process by allowing us to call `InitializeProcThreadAttributeList` + // with a null pointer to retrieve the required size. + let mut required_size = 0; + let Ok(attribute_count) = self.attributes.len().try_into() else { + return Err(io::const_error!( + io::ErrorKind::InvalidInput, + "maximum number of ProcThreadAttributes exceeded", + )); + }; + unsafe { + sys::c::InitializeProcThreadAttributeList( + ptr::null_mut(), + attribute_count, + 0, + &mut required_size, + ) + }; + + let mut attribute_list = 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. sys::cvt(unsafe { - sys::c::UpdateProcThreadAttribute( + sys::c::InitializeProcThreadAttributeList( attribute_list.as_mut_ptr().cast::(), + attribute_count, 0, - attribute, - value.ptr, - value.size, - ptr::null_mut(), - ptr::null_mut(), + &mut required_size, ) })?; - } - Ok(ProcThreadAttributeList { attribute_list, _lifetime_marker: marker::PhantomData }) + // # Add our attributes to the buffer. + // It's theoretically possible for the attribute count to exceed a u32 + // value. Therefore, we ensure that we don't add more attributes than + // the buffer was initialized for. + for (&attribute, value) in self.attributes.iter().take(attribute_count as usize) { + sys::cvt(unsafe { + sys::c::UpdateProcThreadAttribute( + attribute_list.as_mut_ptr().cast::(), + 0, + attribute, + value.ptr, + value.size, + ptr::null_mut(), + ptr::null_mut(), + ) + })?; + } + + Ok(ProcThreadAttributeList { attribute_list, _lifetime_marker: marker::PhantomData }) + } } } diff --git a/library/std/src/os/windows/thread.rs b/library/std/src/os/windows/thread.rs index 1cdee44de4b72..137afc6af1a4c 100644 --- a/library/std/src/os/windows/thread.rs +++ b/library/std/src/os/windows/thread.rs @@ -12,7 +12,9 @@ use crate::thread; impl AsRawHandle for thread::JoinHandle { #[inline] fn as_raw_handle(&self) -> RawHandle { - self.as_inner().handle().as_raw_handle() as *mut _ + no_code! { + self.as_inner().handle().as_raw_handle() as *mut _ + } } } @@ -20,6 +22,8 @@ impl AsRawHandle for thread::JoinHandle { impl IntoRawHandle for thread::JoinHandle { #[inline] fn into_raw_handle(self) -> RawHandle { - self.into_inner().into_handle().into_raw_handle() as *mut _ + no_code! { + self.into_inner().into_handle().into_raw_handle() as *mut _ + } } } diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index ab02c05ea49a9..8d83bcf7e54bc 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1320,11 +1320,13 @@ mod linux_child_ext { } fn into_pidfd(mut self) -> Result { - self.handle - .pidfd - .take() - .map(>::from_inner) - .ok_or_else(|| self) + no_code! { + self.handle + .pidfd + .take() + .map(>::from_inner) + .ok_or_else(|| self) + } } } } diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 34e9b354bddb2..ebc1a0fd3da89 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -710,7 +710,14 @@ impl CommandLineStep for Std { .expect("non-utf8 paths are unsupported"); let mut extra_args = match self.format { DocumentationFormat::Html => { - vec!["--markdown-css", "rust.css", "--markdown-no-toc", "--index-page", &index_page] + vec![ + "--markdown-css", + "rust.css", + "--markdown-no-toc", + "--index-page", + &index_page, + "--generate-link-to-definition", + ] } DocumentationFormat::Json => vec![], }; From f6db3da7b3fe8252fae10d8cb87b254fa7841b1b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 14 Oct 2026 22:28:26 +0200 Subject: [PATCH 2/5] Create new builtin rustc macro `rustdoc_skip_body` and replace the `std::no_code` macro --- compiler/rustc_builtin_macros/src/lib.rs | 2 + .../src/rustdoc_skip_body.rs | 93 ++++++ compiler/rustc_span/src/symbol.rs | 1 + library/std/src/lib.rs | 13 - library/std/src/macros.rs | 13 + library/std/src/os/darwin/fs.rs | 118 +++---- library/std/src/os/linux/process.rs | 46 ++- library/std/src/os/wasi/fs.rs | 31 +- library/std/src/os/windows/ffi.rs | 11 +- library/std/src/os/windows/fs.rs | 132 ++++---- library/std/src/os/windows/io/handle.rs | 143 ++++----- library/std/src/os/windows/io/raw.rs | 111 +++---- library/std/src/os/windows/io/socket.rs | 111 ++++--- library/std/src/os/windows/net/addr.rs | 30 +- library/std/src/os/windows/net/listener.rs | 22 +- library/std/src/os/windows/net/stream.rs | 52 ++-- library/std/src/os/windows/process.rs | 287 ++++++++---------- library/std/src/os/windows/thread.rs | 11 +- library/std/src/sys/process/unix/unix.rs | 14 +- 19 files changed, 601 insertions(+), 640 deletions(-) create mode 100644 compiler/rustc_builtin_macros/src/rustdoc_skip_body.rs diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 4c3b42eaa0b22..aaaf67e34af4e 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -46,6 +46,7 @@ mod iter; mod log_syntax; mod offload; mod pattern_type; +mod rustdoc_skip_body; mod source_util; mod test; mod test_binder_constraints; @@ -125,6 +126,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { eii_shared_macro: eii::eii_shared_macro, global_allocator: global_allocator::expand, offload_kernel: offload::expand_kernel, + rustdoc_skip_body: rustdoc_skip_body::expand, test: test::expand_test, test_case: test::expand_test_case, unsafe_eii: eii::unsafe_eii, diff --git a/compiler/rustc_builtin_macros/src/rustdoc_skip_body.rs b/compiler/rustc_builtin_macros/src/rustdoc_skip_body.rs new file mode 100644 index 0000000000000..7649fc7d72fe0 --- /dev/null +++ b/compiler/rustc_builtin_macros/src/rustdoc_skip_body.rs @@ -0,0 +1,93 @@ +//! The expansion from a function when the code would not compile with rustdoc: so if `cfg(doc)`, +//! expands to a `loop {}`. + +use rustc_ast::token::{self, Delimiter, IdentKind}; +use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; +use rustc_ast::{ + AssocItemKind, AttrArgs, AttrItem, Attribute, DelimArgs, ExprKind, Fn, ItemKind, MetaItem, + Safety, +}; +use rustc_expand::base::*; +use rustc_span::{Ident, Span, sym}; +use thin_vec::ThinVec; + +pub(crate) fn expand( + cx: &mut ExtCtxt<'_>, + attr_path_sp: Span, + meta_item: &MetaItem, + mut item: Annotatable, +) -> Vec { + if !meta_item.is_word() { + cx.dcx().struct_span_err(attr_path_sp, "`rustdoc_skip_body` doesn't take arguments").emit(); + } + let mut is_expected_item = false; + match item { + Annotatable::Item(ref mut item) => { + if let ItemKind::Fn(ref mut fn_) = item.kind { + expand_macro(cx, attr_path_sp, fn_); + is_expected_item = true; + } + } + Annotatable::AssocItem(ref mut item, _) => { + if let AssocItemKind::Fn(ref mut fn_) = item.kind { + expand_macro(cx, attr_path_sp, fn_); + is_expected_item = true; + } + } + _ => {} + } + if !is_expected_item { + cx.dcx() + .struct_span_err(attr_path_sp, "`rustdoc_skip_body` can only be used on functions") + .emit(); + } + vec![item] +} + +fn cfg_not_doc(cx: &mut ExtCtxt<'_>, sp: Span) -> Attribute { + // `not(doc)` + let not_doc = TokenStream::new(vec![ + TokenTree::token_alone(token::Ident(sym::not, IdentKind::Normal), sp), + TokenTree::Delimited( + DelimSpan::from_single(sp), + DelimSpacing::new(Spacing::JointHidden, Spacing::Alone), + Delimiter::Parenthesis, + TokenStream::token_alone(token::Ident(sym::doc, IdentKind::Normal), sp), + ), + ]); + + cx.attr_nested( + AttrItem { + unsafety: Safety::Default, + path: cx.path_ident(sp, Ident::new(sym::cfg, sp)), + args: AttrArgs::Delimited(DelimArgs { + dspan: DelimSpan::from_single(sp), + delim: Delimiter::Parenthesis, + tokens: not_doc, + }), + span: sp, + }, + sp, + ) +} + +fn expand_macro(cx: &mut ExtCtxt<'_>, sp: Span, fn_: &mut Fn) { + let Some(old_body) = fn_.body.take() else { + // No body... Well, no possibility to not compile I guess so all good. + return; + }; + let mut old_body = cx.expr_block(old_body); + // We add on the function's body `#[cfg(not(doc))]`. + old_body.attrs.push(cfg_not_doc(cx, sp)); + + // We create the `#[cfg(doc)] loop {}` "block". + let mut loop_expr = cx.expr(sp, ExprKind::Loop(cx.block(sp, ThinVec::new()), None, sp)); + loop_expr.attrs.push(cx.attr_nested_word(sym::cfg, sym::doc, sp)); + + let mut stmts = ThinVec::new(); + stmts.push(cx.stmt_expr(loop_expr)); + stmts.push(cx.stmt_expr(old_body)); + + // We create a new function body containing both blocks. + fn_.body = Some(cx.block(sp, stmts)); +} diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 95197e6c98a9f..c400aff1432d2 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1912,6 +1912,7 @@ symbols! { rustdoc, rustdoc_internals, rustdoc_missing_doc_code_examples, + rustdoc_skip_body, rustfmt, rvalue_static_promotion, rvector, diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 69bdc3256a9b7..8ed3a46bf3189 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -449,19 +449,6 @@ since = "1.90.0" )] -// Macro used when rendering with `rustdoc` to replace code with `loop {}`. -#[allow(unused_macros)] -macro_rules! no_code { - ($($code:tt)*) => { - #[cfg(not(doc))] - { - $($code)* - } - #[cfg(doc)] - loop {} - } -} - // The Rust prelude // The compiler expects the prelude definition to be defined before its use statement. pub mod prelude; diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index ea574fc4146e7..7dcdd2c6246b1 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -461,3 +461,16 @@ macro_rules! hash_map { map }} } + +/// Attribute macro to replace a function's body with `loop {}` under rustdoc. +/// +/// This allows target-specific functions to be documented on other targets, +/// even when their bodies reference items unavailable on the target used to +/// build the documentation. Use this with `#[cfg(any(doc, ...))]` to include +/// such functions in documentation builds. +/// +/// The function's signature must still be valid on the documentation target. +#[rustc_builtin_macro] +pub(crate) macro rustdoc_skip_body($item:item) { + /* compiler built-in */ +} diff --git a/library/std/src/os/darwin/fs.rs b/library/std/src/os/darwin/fs.rs index 5349892dbd1c1..ece59e96c7819 100644 --- a/library/std/src/os/darwin/fs.rs +++ b/library/std/src/os/darwin/fs.rs @@ -4,6 +4,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::{self, Metadata}; +use crate::macros::rustdoc_skip_body; use crate::sys::{AsInner, AsInnerMut, IntoInner}; use crate::time::SystemTime; @@ -88,115 +89,93 @@ pub trait MetadataExt { impl MetadataExt for Metadata { #[allow(deprecated)] #[cfg(any(doc, target_os = "macos", target_os = "ios"))] + #[rustdoc_skip_body] fn as_raw_stat(&self) -> &super::raw::stat { - no_code! { - unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const super::raw::stat) } - } + unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const super::raw::stat) } } + #[rustdoc_skip_body] fn st_dev(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_dev as u64 - } + self.as_inner().as_inner().st_dev as u64 } + #[rustdoc_skip_body] fn st_ino(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_ino as u64 - } + self.as_inner().as_inner().st_ino as u64 } + #[rustdoc_skip_body] fn st_mode(&self) -> u32 { - no_code! { - self.as_inner().as_inner().st_mode as u32 - } + self.as_inner().as_inner().st_mode as u32 } + #[rustdoc_skip_body] fn st_nlink(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_nlink as u64 - } + self.as_inner().as_inner().st_nlink as u64 } + #[rustdoc_skip_body] fn st_uid(&self) -> u32 { - no_code! { - self.as_inner().as_inner().st_uid as u32 - } + self.as_inner().as_inner().st_uid as u32 } + #[rustdoc_skip_body] fn st_gid(&self) -> u32 { - no_code! { - self.as_inner().as_inner().st_gid as u32 - } + self.as_inner().as_inner().st_gid as u32 } + #[rustdoc_skip_body] fn st_rdev(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_rdev as u64 - } + self.as_inner().as_inner().st_rdev as u64 } + #[rustdoc_skip_body] fn st_size(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_size as u64 - } + self.as_inner().as_inner().st_size as u64 } + #[rustdoc_skip_body] fn st_atime(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_atime as i64 - } + self.as_inner().as_inner().st_atime as i64 } + #[rustdoc_skip_body] fn st_atime_nsec(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_atime_nsec as i64 - } + self.as_inner().as_inner().st_atime_nsec as i64 } + #[rustdoc_skip_body] fn st_mtime(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_mtime as i64 - } + self.as_inner().as_inner().st_mtime as i64 } + #[rustdoc_skip_body] fn st_mtime_nsec(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_mtime_nsec as i64 - } + self.as_inner().as_inner().st_mtime_nsec as i64 } + #[rustdoc_skip_body] fn st_ctime(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_ctime as i64 - } + self.as_inner().as_inner().st_ctime as i64 } + #[rustdoc_skip_body] fn st_ctime_nsec(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_ctime_nsec as i64 - } + self.as_inner().as_inner().st_ctime_nsec as i64 } + #[rustdoc_skip_body] fn st_birthtime(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_birthtime as i64 - } + self.as_inner().as_inner().st_birthtime as i64 } + #[rustdoc_skip_body] fn st_birthtime_nsec(&self) -> i64 { - no_code! { - self.as_inner().as_inner().st_birthtime_nsec as i64 - } + self.as_inner().as_inner().st_birthtime_nsec as i64 } + #[rustdoc_skip_body] fn st_blksize(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_blksize as u64 - } + self.as_inner().as_inner().st_blksize as u64 } + #[rustdoc_skip_body] fn st_blocks(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_blocks as u64 - } + self.as_inner().as_inner().st_blocks as u64 } + #[rustdoc_skip_body] fn st_gen(&self) -> u32 { - no_code! { - self.as_inner().as_inner().st_gen as u32 - } + self.as_inner().as_inner().st_gen as u32 } + #[rustdoc_skip_body] fn st_flags(&self) -> u32 { - no_code! { - self.as_inner().as_inner().st_flags as u32 - } + self.as_inner().as_inner().st_flags as u32 } + #[rustdoc_skip_body] fn st_lspare(&self) -> u32 { - no_code! { - self.as_inner().as_inner().st_lspare as u32 - } + self.as_inner().as_inner().st_lspare as u32 } #[cfg(target_os = "macos")] fn st_qspare(&self) -> [u64; 2] { @@ -215,10 +194,9 @@ pub impl(self) trait FileTimesExt { #[stable(feature = "file_set_times", since = "1.75.0")] impl FileTimesExt for fs::FileTimes { + #[rustdoc_skip_body] fn set_created(mut self, t: SystemTime) -> Self { - no_code! { - self.as_inner_mut().set_created(t.into_inner()); - self - } + self.as_inner_mut().set_created(t.into_inner()); + self } } diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 26f2057b6d942..26a4ab4b4c603 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -5,6 +5,7 @@ #![unstable(feature = "linux_pidfd", issue = "82971")] use crate::io::Result; +use crate::macros::rustdoc_skip_body; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::process::{self, ExitStatus}; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner}; @@ -61,10 +62,9 @@ impl PidFd { /// races. But doing so will return an Error. /// /// [`Child::kill`]: process::Child::kill + #[rustdoc_skip_body] pub fn kill(&self) -> Result<()> { - no_code! { - self.inner.kill() - } + self.inner.kill() } /// Waits for the child to exit completely, returning the status that it exited with. @@ -76,10 +76,9 @@ impl PidFd { /// will return an Error. /// /// [`Child::wait`]: process::Child::wait + #[rustdoc_skip_body] pub fn wait(&self) -> Result { - no_code! { - self.inner.wait().map(FromInner::from_inner) - } + self.inner.wait().map(FromInner::from_inner) } /// Attempts to collect the exit status of the child if it has already exited. @@ -88,10 +87,9 @@ impl PidFd { /// to reap a child will return an ExitStatus, further attempts will return an Error. /// /// [`Child::try_wait`]: process::Child::try_wait + #[rustdoc_skip_body] pub fn try_wait(&self) -> Result> { - no_code! { - Ok(self.inner.try_wait()?.map(FromInner::from_inner)) - } + Ok(self.inner.try_wait()?.map(FromInner::from_inner)) } } @@ -116,50 +114,44 @@ impl IntoInner for PidFd { impl AsRawFd for PidFd { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { - no_code! { - self.as_inner().as_inner().as_raw_fd() - } + self.as_inner().as_inner().as_raw_fd() } } impl FromRawFd for PidFd { + #[rustdoc_skip_body] unsafe fn from_raw_fd(fd: RawFd) -> Self { - no_code! { - Self::from_inner(InnerPidFd::from_raw_fd(fd)) - } + Self::from_inner(InnerPidFd::from_raw_fd(fd)) } } impl IntoRawFd for PidFd { + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { - no_code! { - self.into_inner().into_inner().into_raw_fd() - } + self.into_inner().into_inner().into_raw_fd() } } impl AsFd for PidFd { + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { - no_code! { - self.as_inner().as_inner().as_fd() - } + self.as_inner().as_inner().as_fd() } } impl From for PidFd { + #[rustdoc_skip_body] fn from(fd: OwnedFd) -> Self { - no_code! { - Self::from_inner(InnerPidFd::from_inner(FileDesc::from_inner(fd))) - } + Self::from_inner(InnerPidFd::from_inner(FileDesc::from_inner(fd))) } } impl From for OwnedFd { + #[rustdoc_skip_body] fn from(pid_fd: PidFd) -> Self { - no_code! { - pid_fd.into_inner().into_inner().into_inner() - } + pid_fd.into_inner().into_inner().into_inner() } } diff --git a/library/std/src/os/wasi/fs.rs b/library/std/src/os/wasi/fs.rs index 96a18ff934ff0..811ab7ea8480b 100644 --- a/library/std/src/os/wasi/fs.rs +++ b/library/std/src/os/wasi/fs.rs @@ -12,6 +12,7 @@ use io::{Read, Write}; use crate::ffi::OsStr; use crate::fs::{self, File, OpenOptions}; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; +use crate::macros::rustdoc_skip_body; #[cfg(target_env = "p1")] use crate::os::fd::AsRawFd; use crate::path::Path; @@ -333,20 +334,17 @@ pub trait MetadataExt { } impl MetadataExt for fs::Metadata { + #[rustdoc_skip_body] fn dev(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_dev - } + self.as_inner().as_inner().st_dev } + #[rustdoc_skip_body] fn ino(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_ino - } + self.as_inner().as_inner().st_ino } + #[rustdoc_skip_body] fn nlink(&self) -> u64 { - no_code! { - self.as_inner().as_inner().st_nlink - } + self.as_inner().as_inner().st_nlink } } @@ -364,20 +362,17 @@ pub trait FileTypeExt { } impl FileTypeExt for fs::FileType { + #[rustdoc_skip_body] fn is_block_device(&self) -> bool { - no_code! { - self.as_inner().is(libc::S_IFBLK) - } + self.as_inner().is(libc::S_IFBLK) } + #[rustdoc_skip_body] fn is_char_device(&self) -> bool { - no_code! { - self.as_inner().is(libc::S_IFCHR) - } + self.as_inner().is(libc::S_IFCHR) } + #[rustdoc_skip_body] fn is_socket(&self) -> bool { - no_code! { - self.as_inner().is(libc::S_IFSOCK) - } + self.as_inner().is(libc::S_IFSOCK) } } diff --git a/library/std/src/os/windows/ffi.rs b/library/std/src/os/windows/ffi.rs index d21dace2346ce..a4c6f1ad7df42 100644 --- a/library/std/src/os/windows/ffi.rs +++ b/library/std/src/os/windows/ffi.rs @@ -58,6 +58,7 @@ use alloc::wtf8::Wtf8Buf; use crate::ffi::{OsStr, OsString}; use crate::fmt; use crate::iter::FusedIterator; +use crate::macros::rustdoc_skip_body; use crate::sys::os_str::Buf; use crate::sys::{AsInner, FromInner}; @@ -88,10 +89,9 @@ pub impl(self) trait OsStringExt { #[stable(feature = "rust1", since = "1.0.0")] impl OsStringExt for OsString { + #[rustdoc_skip_body] fn from_wide(wide: &[u16]) -> OsString { - no_code! { - FromInner::from_inner(Buf { inner: Wtf8Buf::from_wide(wide) }) - } + FromInner::from_inner(Buf { inner: Wtf8Buf::from_wide(wide) }) } } @@ -127,10 +127,9 @@ pub impl(self) trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] impl OsStrExt for OsStr { #[inline] + #[rustdoc_skip_body] fn encode_wide(&self) -> EncodeWide<'_> { - no_code! { - EncodeWide { inner: self.as_inner().inner.encode_wide() } - } + EncodeWide { inner: self.as_inner().inner.encode_wide() } } } diff --git a/library/std/src/os/windows/fs.rs b/library/std/src/os/windows/fs.rs index ec60272e8c89d..d931dd2476039 100644 --- a/library/std/src/os/windows/fs.rs +++ b/library/std/src/os/windows/fs.rs @@ -6,6 +6,7 @@ use crate::fs::{self, Metadata, OpenOptions, Permissions}; use crate::io::BorrowedCursor; +use crate::macros::rustdoc_skip_body; use crate::path::Path; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::time::SystemTime; @@ -493,39 +494,34 @@ pub trait OpenOptionsExt { #[stable(feature = "open_options_ext", since = "1.10.0")] impl OpenOptionsExt for OpenOptions { + #[rustdoc_skip_body] fn access_mode(&mut self, access: u32) -> &mut OpenOptions { - no_code! { - self.as_inner_mut().access_mode(access); - self - } + self.as_inner_mut().access_mode(access); + self } + #[rustdoc_skip_body] fn share_mode(&mut self, share: u32) -> &mut OpenOptions { - no_code! { - self.as_inner_mut().share_mode(share); - self - } + self.as_inner_mut().share_mode(share); + self } + #[rustdoc_skip_body] fn custom_flags(&mut self, flags: u32) -> &mut OpenOptions { - no_code! { - self.as_inner_mut().custom_flags(flags); - self - } + self.as_inner_mut().custom_flags(flags); + self } + #[rustdoc_skip_body] fn attributes(&mut self, attributes: u32) -> &mut OpenOptions { - no_code! { - self.as_inner_mut().attributes(attributes); - self - } + self.as_inner_mut().attributes(attributes); + self } + #[rustdoc_skip_body] fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions { - no_code! { - self.as_inner_mut().security_qos_flags(flags); - self - } + self.as_inner_mut().security_qos_flags(flags); + self } } @@ -546,18 +542,16 @@ pub impl(self) trait OpenOptionsExt2 { #[unstable(feature = "windows_freeze_file_times", issue = "149715")] impl OpenOptionsExt2 for OpenOptions { + #[rustdoc_skip_body] fn freeze_last_access_time(&mut self, freeze: bool) -> &mut Self { - no_code! { - self.as_inner_mut().freeze_last_access_time(freeze); - self - } + self.as_inner_mut().freeze_last_access_time(freeze); + self } + #[rustdoc_skip_body] fn freeze_last_write_time(&mut self, freeze: bool) -> &mut Self { - no_code! { - self.as_inner_mut().freeze_last_write_time(freeze); - self - } + self.as_inner_mut().freeze_last_write_time(freeze); + self } } @@ -608,10 +602,9 @@ pub impl(self) trait PermissionsExt { #[unstable(feature = "windows_permissions_ext", issue = "152956")] impl PermissionsExt for fs::Permissions { + #[rustdoc_skip_body] fn file_attributes(&self) -> u32 { - no_code! { - self.as_inner().file_attributes() - } + self.as_inner().file_attributes() } fn set_file_attributes(&mut self, mask: u32) { @@ -821,50 +814,41 @@ pub trait MetadataExt { #[stable(feature = "metadata_ext", since = "1.1.0")] impl MetadataExt for Metadata { + #[rustdoc_skip_body] fn file_attributes(&self) -> u32 { - no_code! { - self.as_inner().attrs() - } + self.as_inner().attrs() } + #[rustdoc_skip_body] fn creation_time(&self) -> u64 { - no_code! { - self.as_inner().created_u64() - } + self.as_inner().created_u64() } + #[rustdoc_skip_body] fn last_access_time(&self) -> u64 { - no_code! { - self.as_inner().accessed_u64() - } + self.as_inner().accessed_u64() } + #[rustdoc_skip_body] fn last_write_time(&self) -> u64 { - no_code! { - self.as_inner().modified_u64() - } + self.as_inner().modified_u64() } + #[rustdoc_skip_body] fn file_size(&self) -> u64 { - no_code! { - self.as_inner().size() - } + self.as_inner().size() } + #[rustdoc_skip_body] fn volume_serial_number(&self) -> Option { - no_code! { - self.as_inner().volume_serial_number() - } + self.as_inner().volume_serial_number() } + #[rustdoc_skip_body] fn number_of_links(&self) -> Option { - no_code! { - self.as_inner().number_of_links() - } + self.as_inner().number_of_links() } + #[rustdoc_skip_body] fn file_index(&self) -> Option { - no_code! { - self.as_inner().file_index() - } + self.as_inner().file_index() } + #[rustdoc_skip_body] fn change_time(&self) -> Option { - no_code! { - self.as_inner().changed_u64() - } + self.as_inner().changed_u64() } } @@ -883,15 +867,13 @@ pub impl(self) trait FileTypeExt { #[stable(feature = "windows_file_type_ext", since = "1.64.0")] impl FileTypeExt for fs::FileType { + #[rustdoc_skip_body] fn is_symlink_dir(&self) -> bool { - no_code! { - self.as_inner().is_symlink_dir() - } + self.as_inner().is_symlink_dir() } + #[rustdoc_skip_body] fn is_symlink_file(&self) -> bool { - no_code! { - self.as_inner().is_symlink_file() - } + self.as_inner().is_symlink_file() } } @@ -905,11 +887,10 @@ pub impl(self) trait FileTimesExt { #[stable(feature = "file_set_times", since = "1.75.0")] impl FileTimesExt for fs::FileTimes { + #[rustdoc_skip_body] fn set_created(mut self, t: SystemTime) -> Self { - no_code! { - self.as_inner_mut().set_created(t.into_inner()); - self - } + self.as_inner_mut().set_created(t.into_inner()); + self } } @@ -951,10 +932,9 @@ impl FileTimesExt for fs::FileTimes { #[doc(alias = "CreateSymbolicLink", alias = "CreateSymbolicLinkW")] #[stable(feature = "symlink", since = "1.1.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "fs_symlink_file")] +#[rustdoc_skip_body] pub fn symlink_file, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - no_code! { - sys::fs::symlink_inner(original.as_ref(), link.as_ref(), false) - } + sys::fs::symlink_inner(original.as_ref(), link.as_ref(), false) } /// Creates a new symlink to a directory on the filesystem. @@ -995,10 +975,9 @@ pub fn symlink_file, Q: AsRef>(original: P, link: Q) -> io: #[doc(alias = "CreateSymbolicLink", alias = "CreateSymbolicLinkW")] #[stable(feature = "symlink", since = "1.1.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "fs_symlink_dir")] +#[rustdoc_skip_body] pub fn symlink_dir, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - no_code! { - sys::fs::symlink_inner(original.as_ref(), link.as_ref(), true) - } + sys::fs::symlink_inner(original.as_ref(), link.as_ref(), true) } /// Creates a junction point. @@ -1009,8 +988,7 @@ pub fn symlink_dir, Q: AsRef>(original: P, link: Q) -> io:: /// /// If either path is not a local file path then this will fail. #[unstable(feature = "junction_point", issue = "121709")] +#[rustdoc_skip_body] pub fn junction_point, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - no_code! { - sys::fs::junction_point(original.as_ref(), link.as_ref()) - } + sys::fs::junction_point(original.as_ref(), link.as_ref()) } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 96db1c06318b9..90d9770cc6203 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -4,6 +4,7 @@ use super::raw::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle}; use crate::alloc::Allocator; +use crate::macros::rustdoc_skip_body; use crate::marker::PhantomData; use crate::mem::ManuallyDrop; use crate::sys::{AsInner, FromInner, IntoInner, cvt}; @@ -193,12 +194,11 @@ impl TryFrom for OwnedHandle { #[stable(feature = "io_safety", since = "1.63.0")] impl Drop for HandleOrNull { #[inline] + #[rustdoc_skip_body] fn drop(&mut self) { - no_code! { - if self.is_valid() { - unsafe { - let _ = sys::c::CloseHandle(self.0); - } + if self.is_valid() { + unsafe { + let _ = sys::c::CloseHandle(self.0); } } } @@ -217,44 +217,42 @@ impl BorrowedHandle<'_> { /// Creates a new `OwnedHandle` instance that shares the same underlying /// object as the existing `BorrowedHandle` instance. #[stable(feature = "io_safety", since = "1.63.0")] + #[rustdoc_skip_body] pub fn try_clone_to_owned(&self) -> io::Result { - no_code! { - self.duplicate(0, false, sys::c::DUPLICATE_SAME_ACCESS) - } + self.duplicate(0, false, sys::c::DUPLICATE_SAME_ACCESS) } + #[rustdoc_skip_body] pub(crate) fn duplicate( &self, access: u32, inherit: bool, options: u32, ) -> io::Result { - no_code! { - let handle = self.as_raw_handle(); - - // `Stdin`, `Stdout`, and `Stderr` can all hold null handles, such as - // in a process with a detached console. `DuplicateHandle` would fail - // if we passed it a null handle, but we can treat null as a valid - // handle which doesn't do any I/O, and allow it to be duplicated. - if handle.is_null() { - return unsafe { Ok(OwnedHandle::from_raw_handle(handle)) }; - } - - let mut ret = ptr::null_mut(); - cvt(unsafe { - let cur_proc = sys::c::GetCurrentProcess(); - sys::c::DuplicateHandle( - cur_proc, - handle, - cur_proc, - &mut ret, - access, - inherit as sys::c::BOOL, - options, - ) - })?; - unsafe { Ok(OwnedHandle::from_raw_handle(ret)) } + let handle = self.as_raw_handle(); + + // `Stdin`, `Stdout`, and `Stderr` can all hold null handles, such as + // in a process with a detached console. `DuplicateHandle` would fail + // if we passed it a null handle, but we can treat null as a valid + // handle which doesn't do any I/O, and allow it to be duplicated. + if handle.is_null() { + return unsafe { Ok(OwnedHandle::from_raw_handle(handle)) }; } + + let mut ret = ptr::null_mut(); + cvt(unsafe { + let cur_proc = sys::c::GetCurrentProcess(); + sys::c::DuplicateHandle( + cur_proc, + handle, + cur_proc, + &mut ret, + access, + inherit as sys::c::BOOL, + options, + ) + })?; + unsafe { Ok(OwnedHandle::from_raw_handle(ret)) } } } @@ -277,12 +275,11 @@ impl TryFrom for OwnedHandle { #[stable(feature = "io_safety", since = "1.63.0")] impl Drop for HandleOrInvalid { #[inline] + #[rustdoc_skip_body] fn drop(&mut self) { - no_code! { - if self.is_valid() { - unsafe { - let _ = sys::c::CloseHandle(self.0); - } + if self.is_valid() { + unsafe { + let _ = sys::c::CloseHandle(self.0); } } } @@ -499,40 +496,36 @@ impl AsHandle for &mut T { /// ``` impl AsHandle for crate::sync::Arc { #[inline] + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - (**self).as_handle() - } + (**self).as_handle() } } #[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl AsHandle for crate::rc::Rc { #[inline] + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - (**self).as_handle() - } + (**self).as_handle() } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl AsHandle for crate::rc::UniqueRc { #[inline] + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - (**self).as_handle() - } + (**self).as_handle() } } #[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl AsHandle for Box { #[inline] + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - (**self).as_handle() - } + (**self).as_handle() } } @@ -558,10 +551,9 @@ impl AsHandle for OwnedHandle { #[stable(feature = "io_safety", since = "1.63.0")] impl AsHandle for fs::File { #[inline] + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - self.as_inner().as_handle() - } + self.as_inner().as_handle() } } @@ -569,10 +561,9 @@ impl AsHandle for fs::File { impl From for OwnedHandle { /// Takes ownership of a [`File`](fs::File)'s underlying file handle. #[inline] + #[rustdoc_skip_body] fn from(file: fs::File) -> OwnedHandle { - no_code! { - file.into_inner().into_inner().into_inner() - } + file.into_inner().into_inner().into_inner() } } @@ -580,10 +571,9 @@ impl From for OwnedHandle { impl From for fs::File { /// Returns a [`File`](fs::File) that takes ownership of the given handle. #[inline] + #[rustdoc_skip_body] fn from(owned: OwnedHandle) -> Self { - no_code! { - Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned))) - } + Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned))) } } @@ -697,37 +687,33 @@ impl AsHandle for crate::thread::JoinHandle { #[stable(feature = "io_safety", since = "1.63.0")] impl From> for OwnedHandle { #[inline] + #[rustdoc_skip_body] fn from(join_handle: crate::thread::JoinHandle) -> OwnedHandle { - no_code! { - join_handle.into_inner().into_handle().into_inner() - } + join_handle.into_inner().into_handle().into_inner() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsHandle for io::PipeReader { + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - self.0.as_handle() - } + self.0.as_handle() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for OwnedHandle { + #[rustdoc_skip_body] fn from(pipe: io::PipeReader) -> Self { - no_code! { - pipe.into_inner().into_inner() - } + pipe.into_inner().into_inner() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsHandle for io::PipeWriter { + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - self.0.as_handle() - } + self.0.as_handle() } } @@ -776,27 +762,24 @@ unsafe_impl_handle_asrefs!(crate::fs::File, io::PipeWriter, io::PipeReader,); #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for OwnedHandle { + #[rustdoc_skip_body] fn from(pipe: io::PipeWriter) -> Self { - no_code! { - pipe.into_inner().into_inner() - } + pipe.into_inner().into_inner() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for io::PipeReader { + #[rustdoc_skip_body] fn from(owned_handle: OwnedHandle) -> Self { - no_code! { - Self::from_inner(FromInner::from_inner(owned_handle)) - } + Self::from_inner(FromInner::from_inner(owned_handle)) } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl From for io::PipeWriter { + #[rustdoc_skip_body] fn from(owned_handle: OwnedHandle) -> Self { - no_code! { - Self::from_inner(FromInner::from_inner(owned_handle)) - } + Self::from_inner(FromInner::from_inner(owned_handle)) } } diff --git a/library/std/src/os/windows/io/raw.rs b/library/std/src/os/windows/io/raw.rs index bd1601fc5c5fd..0bd74c76490b1 100644 --- a/library/std/src/os/windows/io/raw.rs +++ b/library/std/src/os/windows/io/raw.rs @@ -2,6 +2,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use crate::macros::rustdoc_skip_body; #[cfg(doc)] use crate::os::windows::io::{AsHandle, AsSocket}; use crate::os::windows::io::{OwnedHandle, OwnedSocket}; @@ -93,10 +94,9 @@ pub trait IntoRawHandle { #[stable(feature = "rust1", since = "1.0.0")] impl AsRawHandle for fs::File { #[inline] + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.as_inner().as_raw_handle() as RawHandle - } + self.as_inner().as_raw_handle() as RawHandle } } @@ -157,14 +157,13 @@ pub(super) fn stdio_handle(raw: RawHandle) -> RawHandle { #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawHandle for fs::File { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_handle(handle: RawHandle) -> fs::File { - no_code! { - unsafe { - let handle = handle as sys::c::HANDLE; - fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner( - OwnedHandle::from_raw_handle(handle), - ))) - } + unsafe { + let handle = handle as sys::c::HANDLE; + fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner( + OwnedHandle::from_raw_handle(handle), + ))) } } } @@ -172,10 +171,9 @@ impl FromRawHandle for fs::File { #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for fs::File { #[inline] + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.into_inner().into_raw_handle() as *mut _ - } + self.into_inner().into_raw_handle() as *mut _ } } @@ -243,64 +241,58 @@ pub trait IntoRawSocket { #[stable(feature = "rust1", since = "1.0.0")] impl AsRawSocket for net::TcpStream { #[inline] + #[rustdoc_skip_body] fn as_raw_socket(&self) -> RawSocket { - no_code! { - self.as_inner().socket().as_raw_socket() - } + self.as_inner().socket().as_raw_socket() } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawSocket for net::TcpListener { #[inline] + #[rustdoc_skip_body] fn as_raw_socket(&self) -> RawSocket { - no_code! { - self.as_inner().socket().as_raw_socket() - } + self.as_inner().socket().as_raw_socket() } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawSocket for net::UdpSocket { #[inline] + #[rustdoc_skip_body] fn as_raw_socket(&self) -> RawSocket { - no_code! { - self.as_inner().socket().as_raw_socket() - } + self.as_inner().socket().as_raw_socket() } } #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawSocket for net::TcpStream { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream { - no_code! { - unsafe { - let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); - net::TcpStream::from_inner(sys::net::TcpStream::from_inner(sock)) - } + unsafe { + let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); + net::TcpStream::from_inner(sys::net::TcpStream::from_inner(sock)) } } } #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawSocket for net::TcpListener { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener { - no_code! { - unsafe { - let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); - net::TcpListener::from_inner(sys::net::TcpListener::from_inner(sock)) - } + unsafe { + let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); + net::TcpListener::from_inner(sys::net::TcpListener::from_inner(sock)) } } } #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawSocket for net::UdpSocket { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket { - no_code! { - unsafe { - let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); - net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(sock)) - } + unsafe { + let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock)); + net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(sock)) } } } @@ -308,83 +300,74 @@ impl FromRawSocket for net::UdpSocket { #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawSocket for net::TcpStream { #[inline] + #[rustdoc_skip_body] fn into_raw_socket(self) -> RawSocket { - no_code! { - self.into_inner().into_socket().into_inner().into_raw_socket() - } + self.into_inner().into_socket().into_inner().into_raw_socket() } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawSocket for net::TcpListener { #[inline] + #[rustdoc_skip_body] fn into_raw_socket(self) -> RawSocket { - no_code! { - self.into_inner().into_socket().into_inner().into_raw_socket() - } + self.into_inner().into_socket().into_inner().into_raw_socket() } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawSocket for net::UdpSocket { #[inline] + #[rustdoc_skip_body] fn into_raw_socket(self) -> RawSocket { - no_code! { - self.into_inner().into_socket().into_inner().into_raw_socket() - } + self.into_inner().into_socket().into_inner().into_raw_socket() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsRawHandle for io::PipeReader { + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.0.as_raw_handle() - } + self.0.as_raw_handle() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl FromRawHandle for io::PipeReader { + #[rustdoc_skip_body] unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self { - no_code! { - unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } - } + unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl IntoRawHandle for io::PipeReader { + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.0.into_raw_handle() - } + self.0.into_raw_handle() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl AsRawHandle for io::PipeWriter { + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.0.as_raw_handle() - } + self.0.as_raw_handle() } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl FromRawHandle for io::PipeWriter { + #[rustdoc_skip_body] unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self { - no_code! { - unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } - } + unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) } } } #[stable(feature = "anonymous_pipe", since = "1.87.0")] impl IntoRawHandle for io::PipeWriter { + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.0.into_raw_handle() - } + self.0.into_raw_handle() } } diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index dd4476bac4bd0..24038e3dd5624 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -4,6 +4,7 @@ use super::raw::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}; use crate::alloc::Allocator; +use crate::macros::rustdoc_skip_body; use crate::marker::PhantomData; use crate::mem::{self, ManuallyDrop}; #[cfg(not(target_vendor = "uwp"))] @@ -78,17 +79,16 @@ impl OwnedSocket { // FIXME(strict_provenance_magic): we defined RawSocket to be a u64 ;-; #[allow(implicit_provenance_casts)] #[cfg(not(target_vendor = "uwp"))] + #[rustdoc_skip_body] pub(crate) fn set_no_inherit(&self) -> io::Result<()> { - no_code! { - cvt(unsafe { - sys::c::SetHandleInformation( - self.as_raw_socket() as sys::c::HANDLE, - sys::c::HANDLE_FLAG_INHERIT, - 0, - ) - }) - .map(drop) - } + cvt(unsafe { + sys::c::SetHandleInformation( + self.as_raw_socket() as sys::c::HANDLE, + sys::c::HANDLE_FLAG_INHERIT, + 0, + ) + }) + .map(drop) } #[cfg(target_vendor = "uwp")] @@ -101,17 +101,37 @@ impl BorrowedSocket<'_> { /// Creates a new `OwnedSocket` instance that shares the same underlying /// object as the existing `BorrowedSocket` instance. #[stable(feature = "io_safety", since = "1.63.0")] + #[rustdoc_skip_body] pub fn try_clone_to_owned(&self) -> io::Result { - no_code! { - let mut info = unsafe { mem::zeroed::() }; - let result = unsafe { - sys::c::WSADuplicateSocketW( - self.as_raw_socket() as sys::c::SOCKET, - sys::c::GetCurrentProcessId(), - &mut info, - ) - }; - sys::net::cvt(result)?; + let mut info = unsafe { mem::zeroed::() }; + let result = unsafe { + sys::c::WSADuplicateSocketW( + self.as_raw_socket() as sys::c::SOCKET, + sys::c::GetCurrentProcessId(), + &mut info, + ) + }; + sys::net::cvt(result)?; + let socket = unsafe { + sys::c::WSASocketW( + info.iAddressFamily, + info.iSocketType, + info.iProtocol, + &info, + 0, + sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT, + ) + }; + + if socket != sys::c::INVALID_SOCKET { + unsafe { Ok(OwnedSocket::from_raw_socket(socket as RawSocket)) } + } else { + let error = unsafe { sys::c::WSAGetLastError() }; + + if error != sys::c::WSAEPROTOTYPE && error != sys::c::WSAEINVAL { + return Err(io::Error::from_raw_os_error(error)); + } + let socket = unsafe { sys::c::WSASocketW( info.iAddressFamily, @@ -119,49 +139,27 @@ impl BorrowedSocket<'_> { info.iProtocol, &info, 0, - sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT, + sys::c::WSA_FLAG_OVERLAPPED, ) }; - if socket != sys::c::INVALID_SOCKET { - unsafe { Ok(OwnedSocket::from_raw_socket(socket as RawSocket)) } - } else { - let error = unsafe { sys::c::WSAGetLastError() }; - - if error != sys::c::WSAEPROTOTYPE && error != sys::c::WSAEINVAL { - return Err(io::Error::from_raw_os_error(error)); - } - - let socket = unsafe { - sys::c::WSASocketW( - info.iAddressFamily, - info.iSocketType, - info.iProtocol, - &info, - 0, - sys::c::WSA_FLAG_OVERLAPPED, - ) - }; - - if socket == sys::c::INVALID_SOCKET { - return Err(last_error()); - } - - unsafe { - let socket = OwnedSocket::from_raw_socket(socket as RawSocket); - socket.set_no_inherit()?; - Ok(socket) - } + if socket == sys::c::INVALID_SOCKET { + return Err(last_error()); + } + + unsafe { + let socket = OwnedSocket::from_raw_socket(socket as RawSocket); + socket.set_no_inherit()?; + Ok(socket) } } } } /// Returns the last error from the Windows socket interface. +#[rustdoc_skip_body] fn last_error() -> io::Error { - no_code! { - io::Error::from_raw_os_error(unsafe { sys::c::WSAGetLastError() }) - } + io::Error::from_raw_os_error(unsafe { sys::c::WSAGetLastError() }) } #[stable(feature = "io_safety", since = "1.63.0")] @@ -200,11 +198,10 @@ impl FromRawSocket for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl Drop for OwnedSocket { #[inline] + #[rustdoc_skip_body] fn drop(&mut self) { - no_code! { - unsafe { - let _ = sys::c::closesocket(self.socket.as_inner() as sys::c::SOCKET); - } + unsafe { + let _ = sys::c::closesocket(self.socket.as_inner() as sys::c::SOCKET); } } } diff --git a/library/std/src/os/windows/net/addr.rs b/library/std/src/os/windows/net/addr.rs index 614579762573c..7ab856ae6ba44 100644 --- a/library/std/src/os/windows/net/addr.rs +++ b/library/std/src/os/windows/net/addr.rs @@ -1,6 +1,7 @@ #![unstable(feature = "windows_unix_domain_sockets", issue = "150487")] use crate::byte_str::ByteStr; use crate::ffi::OsStr; +use crate::macros::rustdoc_skip_body; use crate::path::Path; #[cfg(not(doc))] use crate::sys::c::{AF_UNIX, SOCKADDR, SOCKADDR_UN}; @@ -127,28 +128,27 @@ impl SocketAddr { /// /// assert!(SocketAddr::from_pathname("/path/with/\0/bytes").is_err()); /// ``` + #[rustdoc_skip_body] pub fn from_pathname

(path: P) -> io::Result where P: AsRef, { - no_code! { - sockaddr_un(path.as_ref()).map(|(addr, len)| SocketAddr { addr, len: len as _ }) - } + sockaddr_un(path.as_ref()).map(|(addr, len)| SocketAddr { addr, len: len as _ }) } + + #[rustdoc_skip_body] fn address(&self) -> AddressKind<'_> { - no_code! { - let len = self.len as usize - SUN_PATH_OFFSET; - let path = unsafe { mem::transmute::<&[i8], &[u8]>(&self.addr.sun_path) }; + let len = self.len as usize - SUN_PATH_OFFSET; + let path = unsafe { mem::transmute::<&[i8], &[u8]>(&self.addr.sun_path) }; - if len == 0 { - AddressKind::Unnamed - } else if self.addr.sun_path[0] == 0 { - AddressKind::Abstract(ByteStr::from_bytes(&path[1..len])) - } else { - AddressKind::Pathname(unsafe { - OsStr::from_encoded_bytes_unchecked(&path[..len - 1]).as_ref() - }) - } + if len == 0 { + AddressKind::Unnamed + } else if self.addr.sun_path[0] == 0 { + AddressKind::Abstract(ByteStr::from_bytes(&path[1..len])) + } else { + AddressKind::Pathname(unsafe { + OsStr::from_encoded_bytes_unchecked(&path[..len - 1]).as_ref() + }) } } diff --git a/library/std/src/os/windows/net/listener.rs b/library/std/src/os/windows/net/listener.rs index 5749747b3adee..d3b9b50c17293 100644 --- a/library/std/src/os/windows/net/listener.rs +++ b/library/std/src/os/windows/net/listener.rs @@ -1,4 +1,6 @@ #![unstable(feature = "windows_unix_domain_sockets", issue = "150487")] + +use crate::macros::rustdoc_skip_body; use crate::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}; use crate::os::windows::net::{SocketAddr, UnixStream}; use crate::path::Path; @@ -163,10 +165,9 @@ impl UnixListener { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn local_addr(&self) -> io::Result { - no_code! { - SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) - } + SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) } /// Creates a new independently owned handle to the underlying socket. @@ -327,28 +328,25 @@ impl<'a> Iterator for Incoming<'a> { impl AsRawSocket for UnixListener { #[inline] + #[rustdoc_skip_body] fn as_raw_socket(&self) -> RawSocket { - no_code! { - self.0.as_raw_socket() - } + self.0.as_raw_socket() } } impl FromRawSocket for UnixListener { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_socket(sock: RawSocket) -> Self { - no_code! { - UnixListener(unsafe { Socket::from_raw_socket(sock) }) - } + UnixListener(unsafe { Socket::from_raw_socket(sock) }) } } impl IntoRawSocket for UnixListener { #[inline] + #[rustdoc_skip_body] fn into_raw_socket(self) -> RawSocket { - no_code! { - self.0.into_raw_socket() - } + self.0.into_raw_socket() } } diff --git a/library/std/src/os/windows/net/stream.rs b/library/std/src/os/windows/net/stream.rs index 1df01b8b527d5..9a3360bfb565c 100644 --- a/library/std/src/os/windows/net/stream.rs +++ b/library/std/src/os/windows/net/stream.rs @@ -1,4 +1,6 @@ #![unstable(feature = "windows_unix_domain_sockets", issue = "150487")] + +use crate::macros::rustdoc_skip_body; use crate::net::Shutdown; use crate::os::windows::io::{ AsRawSocket, AsSocket, BorrowedSocket, FromRawSocket, IntoRawSocket, RawSocket, @@ -126,10 +128,9 @@ impl UnixStream { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn local_addr(&self) -> io::Result { - no_code! { - SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) - } + SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) }) } /// Returns the socket address of the remote half of this connection. @@ -147,10 +148,9 @@ impl UnixStream { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn peer_addr(&self) -> io::Result { - no_code! { - SocketAddr::new(|addr, len| unsafe { getpeername(self.0.as_raw(), addr, len) }) - } + SocketAddr::new(|addr, len| unsafe { getpeername(self.0.as_raw(), addr, len) }) } /// Returns the read timeout of this socket. @@ -170,10 +170,9 @@ impl UnixStream { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn read_timeout(&self) -> io::Result> { - no_code! { - self.0.timeout(SO_RCVTIMEO) - } + self.0.timeout(SO_RCVTIMEO) } /// Moves the socket into or out of nonblocking mode. @@ -236,10 +235,9 @@ impl UnixStream { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn set_read_timeout(&self, dur: Option) -> io::Result<()> { - no_code! { - self.0.set_timeout(dur, SO_RCVTIMEO) - } + self.0.set_timeout(dur, SO_RCVTIMEO) } /// Sets the write timeout for the socket. @@ -284,10 +282,9 @@ impl UnixStream { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn set_write_timeout(&self, dur: Option) -> io::Result<()> { - no_code! { - self.0.set_timeout(dur, SO_SNDTIMEO) - } + self.0.set_timeout(dur, SO_SNDTIMEO) } /// Shuts down the read, write, or both halves of this connection. @@ -377,10 +374,9 @@ impl UnixStream { /// Ok(()) /// } /// ``` + #[rustdoc_skip_body] pub fn write_timeout(&self) -> io::Result> { - no_code! { - self.0.timeout(SO_SNDTIMEO) - } + self.0.timeout(SO_SNDTIMEO) } } @@ -424,35 +420,31 @@ impl<'a> io::Write for &'a UnixStream { impl AsSocket for UnixStream { #[inline] + #[rustdoc_skip_body] fn as_socket(&self) -> BorrowedSocket<'_> { - no_code! { - self.0.as_socket() - } + self.0.as_socket() } } impl AsRawSocket for UnixStream { #[inline] + #[rustdoc_skip_body] fn as_raw_socket(&self) -> RawSocket { - no_code! { - self.0.as_raw_socket() - } + self.0.as_raw_socket() } } impl FromRawSocket for UnixStream { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_socket(sock: RawSocket) -> Self { - no_code! { - unsafe { UnixStream(Socket::from_raw_socket(sock)) } - } + unsafe { UnixStream(Socket::from_raw_socket(sock)) } } } impl IntoRawSocket for UnixStream { + #[rustdoc_skip_body] fn into_raw_socket(self) -> RawSocket { - no_code! { - self.0.into_raw_socket() - } + self.0.into_raw_socket() } } diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index 568bd45f01da3..5065026b21a46 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -5,6 +5,7 @@ #![stable(feature = "process_extensions", since = "1.2.0")] use crate::ffi::{OsStr, c_void}; +use crate::macros::rustdoc_skip_body; use crate::mem::MaybeUninit; use crate::os::windows::io::{ AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle, @@ -14,12 +15,11 @@ use crate::{io, marker, process, ptr, sys}; #[stable(feature = "process_extensions", since = "1.2.0")] impl FromRawHandle for process::Stdio { + #[rustdoc_skip_body] unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio { - no_code! { - let handle = unsafe { sys::handle::Handle::from_raw_handle(handle as *mut _) }; - let io = sys::process::Stdio::Handle(handle); - process::Stdio::from_inner(io) - } + let handle = unsafe { sys::handle::Handle::from_raw_handle(handle as *mut _) }; + let io = sys::process::Stdio::Handle(handle); + process::Stdio::from_inner(io) } } @@ -27,108 +27,97 @@ impl FromRawHandle for process::Stdio { impl From for process::Stdio { /// Takes ownership of a handle and returns a [`Stdio`](process::Stdio) /// that can attach a stream to it. + #[rustdoc_skip_body] fn from(handle: OwnedHandle) -> process::Stdio { - no_code! { - let handle = sys::handle::Handle::from_inner(handle); - let io = sys::process::Stdio::Handle(handle); - process::Stdio::from_inner(io) - } + let handle = sys::handle::Handle::from_inner(handle); + let io = sys::process::Stdio::Handle(handle); + process::Stdio::from_inner(io) } } #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawHandle for process::Child { #[inline] + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.as_inner().handle().as_raw_handle() as *mut _ - } + self.as_inner().handle().as_raw_handle() as *mut _ } } #[stable(feature = "io_safety", since = "1.63.0")] impl AsHandle for process::Child { #[inline] + #[rustdoc_skip_body] fn as_handle(&self) -> BorrowedHandle<'_> { - no_code! { - self.as_inner().handle().as_handle() - } + self.as_inner().handle().as_handle() } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::Child { + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.into_inner().into_handle().into_raw_handle() as *mut _ - } + self.into_inner().into_handle().into_raw_handle() as *mut _ } } #[stable(feature = "io_safety", since = "1.63.0")] impl From for OwnedHandle { /// Takes ownership of a [`Child`](process::Child)'s process handle. + #[rustdoc_skip_body] fn from(child: process::Child) -> OwnedHandle { - no_code! { - child.into_inner().into_handle().into_inner() - } + child.into_inner().into_handle().into_inner() } } #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawHandle for process::ChildStdin { #[inline] + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.as_inner().handle().as_raw_handle() as *mut _ - } + self.as_inner().handle().as_raw_handle() as *mut _ } } #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawHandle for process::ChildStdout { #[inline] + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.as_inner().handle().as_raw_handle() as *mut _ - } + self.as_inner().handle().as_raw_handle() as *mut _ } } #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawHandle for process::ChildStderr { #[inline] + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.as_inner().handle().as_raw_handle() as *mut _ - } + self.as_inner().handle().as_raw_handle() as *mut _ } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::ChildStdin { + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.into_inner().into_handle().into_raw_handle() as *mut _ - } + self.into_inner().into_handle().into_raw_handle() as *mut _ } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::ChildStdout { + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.into_inner().into_handle().into_raw_handle() as *mut _ - } + self.into_inner().into_handle().into_raw_handle() as *mut _ } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawHandle for process::ChildStderr { + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.into_inner().into_handle().into_raw_handle() as *mut _ - } + self.into_inner().into_handle().into_raw_handle() as *mut _ } } @@ -138,12 +127,11 @@ impl IntoRawHandle for process::ChildStderr { /// writing from and to it is implemented using asynchronous APIs. #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStdin { + #[rustdoc_skip_body] fn from(handle: OwnedHandle) -> process::ChildStdin { - no_code! { - let handle = sys::handle::Handle::from_inner(handle); - let pipe = sys::process::ChildPipe::from_inner(handle); - process::ChildStdin::from_inner(pipe) - } + let handle = sys::handle::Handle::from_inner(handle); + let pipe = sys::process::ChildPipe::from_inner(handle); + process::ChildStdin::from_inner(pipe) } } @@ -153,12 +141,11 @@ impl From for process::ChildStdin { /// writing from and to it is implemented using asynchronous APIs. #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStdout { + #[rustdoc_skip_body] fn from(handle: OwnedHandle) -> process::ChildStdout { - no_code! { - let handle = sys::handle::Handle::from_inner(handle); - let pipe = sys::process::ChildPipe::from_inner(handle); - process::ChildStdout::from_inner(pipe) - } + let handle = sys::handle::Handle::from_inner(handle); + let pipe = sys::process::ChildPipe::from_inner(handle); + process::ChildStdout::from_inner(pipe) } } @@ -168,12 +155,11 @@ impl From for process::ChildStdout { /// writing from and to it is implemented using asynchronous APIs. #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStderr { + #[rustdoc_skip_body] fn from(handle: OwnedHandle) -> process::ChildStderr { - no_code! { - let handle = sys::handle::Handle::from_inner(handle); - let pipe = sys::process::ChildPipe::from_inner(handle); - process::ChildStderr::from_inner(pipe) - } + let handle = sys::handle::Handle::from_inner(handle); + let pipe = sys::process::ChildPipe::from_inner(handle); + process::ChildStderr::from_inner(pipe) } } @@ -188,10 +174,9 @@ pub impl(self) trait ExitStatusExt { #[stable(feature = "exit_status_from", since = "1.12.0")] impl ExitStatusExt for process::ExitStatus { + #[rustdoc_skip_body] fn from_raw(raw: u32) -> Self { - no_code! { - process::ExitStatus::from_inner(From::from(raw)) - } + process::ExitStatus::from_inner(From::from(raw)) } } @@ -422,39 +407,34 @@ pub impl(self) trait CommandExt { #[stable(feature = "windows_process_extensions", since = "1.16.0")] impl CommandExt for process::Command { + #[rustdoc_skip_body] fn creation_flags(&mut self, flags: u32) -> &mut process::Command { - no_code! { - self.as_inner_mut().creation_flags(flags); - self - } + self.as_inner_mut().creation_flags(flags); + self } + #[rustdoc_skip_body] fn desktop>(&mut self, desktop: S) -> &mut process::Command { - no_code! { - self.as_inner_mut().desktop(desktop.as_ref()); - self - } + self.as_inner_mut().desktop(desktop.as_ref()); + self } + #[rustdoc_skip_body] fn show_window(&mut self, cmd_show: u16) -> &mut process::Command { - no_code! { - self.as_inner_mut().show_window(Some(cmd_show)); - self - } + self.as_inner_mut().show_window(Some(cmd_show)); + self } + #[rustdoc_skip_body] fn force_quotes(&mut self, enabled: bool) -> &mut process::Command { - no_code! { - self.as_inner_mut().force_quotes(enabled); - self - } + self.as_inner_mut().force_quotes(enabled); + self } + #[rustdoc_skip_body] fn raw_arg>(&mut self, raw_text: S) -> &mut process::Command { - no_code! { - self.as_inner_mut().raw_arg(raw_text.as_ref()); - self - } + self.as_inner_mut().raw_arg(raw_text.as_ref()); + self } fn async_pipes(&mut self, always_async: bool) -> &mut process::Command { @@ -466,43 +446,38 @@ impl CommandExt for process::Command { self } + #[rustdoc_skip_body] fn spawn_with_attributes( &mut self, attribute_list: &ProcThreadAttributeList<'_>, ) -> io::Result { - no_code! { - self.as_inner_mut() - .spawn_with_attributes(sys::process::Stdio::Inherit, true, Some(attribute_list)) - .map(process::Child::from_inner) - } + self.as_inner_mut() + .spawn_with_attributes(sys::process::Stdio::Inherit, true, Some(attribute_list)) + .map(process::Child::from_inner) } + #[rustdoc_skip_body] fn startupinfo_fullscreen(&mut self, enabled: bool) -> &mut process::Command { - no_code! { - self.as_inner_mut().startupinfo_fullscreen(enabled); - self - } + self.as_inner_mut().startupinfo_fullscreen(enabled); + self } + #[rustdoc_skip_body] fn startupinfo_untrusted_source(&mut self, enabled: bool) -> &mut process::Command { - no_code! { - self.as_inner_mut().startupinfo_untrusted_source(enabled); - self - } + self.as_inner_mut().startupinfo_untrusted_source(enabled); + self } + #[rustdoc_skip_body] fn startupinfo_force_feedback(&mut self, enabled: Option) -> &mut process::Command { - no_code! { - self.as_inner_mut().startupinfo_force_feedback(enabled); - self - } + self.as_inner_mut().startupinfo_force_feedback(enabled); + self } + #[rustdoc_skip_body] fn inherit_handles(&mut self, inherit_handles: bool) -> &mut process::Command { - no_code! { - self.as_inner_mut().inherit_handles(inherit_handles); - self - } + self.as_inner_mut().inherit_handles(inherit_handles); + self } } @@ -515,10 +490,9 @@ pub impl(self) trait ChildExt { #[stable(feature = "windows_process_extensions_main_thread_handle", since = "1.100.0")] impl ChildExt for process::Child { + #[rustdoc_skip_body] fn main_thread_handle(&self) -> BorrowedHandle<'_> { - no_code! { - self.handle.main_thread_handle() - } + self.handle.main_thread_handle() } } @@ -537,10 +511,9 @@ pub impl(self) trait ExitCodeExt { #[stable(feature = "windows_process_exit_code_from", since = "CURRENT_RUSTC_VERSION")] impl ExitCodeExt for process::ExitCode { + #[rustdoc_skip_body] fn from_raw(raw: u32) -> Self { - no_code! { - process::ExitCode::from_inner(From::from(raw)) - } + process::ExitCode::from_inner(From::from(raw)) } } @@ -576,12 +549,11 @@ impl<'a> Drop for ProcThreadAttributeList<'a> { /// underlying attribute list. /// /// [1]: + #[rustdoc_skip_body] fn drop(&mut self) { - no_code! { - let lp_attribute_list = - self.attribute_list.as_mut_ptr().cast::(); - unsafe { sys::c::DeleteProcThreadAttributeList(lp_attribute_list) } - } + let lp_attribute_list = + self.attribute_list.as_mut_ptr().cast::(); + unsafe { sys::c::DeleteProcThreadAttributeList(lp_attribute_list) } } } @@ -724,61 +696,60 @@ impl<'a> ProcThreadAttributeListBuilder<'a> { /// /// Returns an error if the maximum number of attributes is exceeded /// or if there is an I/O error during initialization. + #[rustdoc_skip_body] pub fn finish(&self) -> io::Result> { - no_code! { - // To initialize our ProcThreadAttributeList, we need to determine - // how many bytes to allocate for it. The Windows API simplifies this - // process by allowing us to call `InitializeProcThreadAttributeList` - // with a null pointer to retrieve the required size. - let mut required_size = 0; - let Ok(attribute_count) = self.attributes.len().try_into() else { - return Err(io::const_error!( - io::ErrorKind::InvalidInput, - "maximum number of ProcThreadAttributes exceeded", - )); - }; - unsafe { - sys::c::InitializeProcThreadAttributeList( - ptr::null_mut(), - attribute_count, - 0, - &mut required_size, - ) - }; - - let mut attribute_list = 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. + // To initialize our ProcThreadAttributeList, we need to determine + // how many bytes to allocate for it. The Windows API simplifies this + // process by allowing us to call `InitializeProcThreadAttributeList` + // with a null pointer to retrieve the required size. + let mut required_size = 0; + let Ok(attribute_count) = self.attributes.len().try_into() else { + return Err(io::const_error!( + io::ErrorKind::InvalidInput, + "maximum number of ProcThreadAttributes exceeded", + )); + }; + unsafe { + sys::c::InitializeProcThreadAttributeList( + ptr::null_mut(), + attribute_count, + 0, + &mut required_size, + ) + }; + + let mut attribute_list = 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. + sys::cvt(unsafe { + sys::c::InitializeProcThreadAttributeList( + attribute_list.as_mut_ptr().cast::(), + attribute_count, + 0, + &mut required_size, + ) + })?; + + // # Add our attributes to the buffer. + // It's theoretically possible for the attribute count to exceed a u32 + // value. Therefore, we ensure that we don't add more attributes than + // the buffer was initialized for. + for (&attribute, value) in self.attributes.iter().take(attribute_count as usize) { sys::cvt(unsafe { - sys::c::InitializeProcThreadAttributeList( + sys::c::UpdateProcThreadAttribute( attribute_list.as_mut_ptr().cast::(), - attribute_count, 0, - &mut required_size, + attribute, + value.ptr, + value.size, + ptr::null_mut(), + ptr::null_mut(), ) })?; - - // # Add our attributes to the buffer. - // It's theoretically possible for the attribute count to exceed a u32 - // value. Therefore, we ensure that we don't add more attributes than - // the buffer was initialized for. - for (&attribute, value) in self.attributes.iter().take(attribute_count as usize) { - sys::cvt(unsafe { - sys::c::UpdateProcThreadAttribute( - attribute_list.as_mut_ptr().cast::(), - 0, - attribute, - value.ptr, - value.size, - ptr::null_mut(), - ptr::null_mut(), - ) - })?; - } - - Ok(ProcThreadAttributeList { attribute_list, _lifetime_marker: marker::PhantomData }) } + + Ok(ProcThreadAttributeList { attribute_list, _lifetime_marker: marker::PhantomData }) } } diff --git a/library/std/src/os/windows/thread.rs b/library/std/src/os/windows/thread.rs index 137afc6af1a4c..b53bd72f5d3e1 100644 --- a/library/std/src/os/windows/thread.rs +++ b/library/std/src/os/windows/thread.rs @@ -4,6 +4,7 @@ #![stable(feature = "thread_extensions", since = "1.9.0")] +use crate::macros::rustdoc_skip_body; use crate::os::windows::io::{AsRawHandle, IntoRawHandle, RawHandle}; use crate::sys::{AsInner, IntoInner}; use crate::thread; @@ -11,19 +12,17 @@ use crate::thread; #[stable(feature = "thread_extensions", since = "1.9.0")] impl AsRawHandle for thread::JoinHandle { #[inline] + #[rustdoc_skip_body] fn as_raw_handle(&self) -> RawHandle { - no_code! { - self.as_inner().handle().as_raw_handle() as *mut _ - } + self.as_inner().handle().as_raw_handle() as *mut _ } } #[stable(feature = "thread_extensions", since = "1.9.0")] impl IntoRawHandle for thread::JoinHandle { #[inline] + #[rustdoc_skip_body] fn into_raw_handle(self) -> RawHandle { - no_code! { - self.into_inner().into_handle().into_raw_handle() as *mut _ - } + self.into_inner().into_handle().into_raw_handle() as *mut _ } } diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 8d83bcf7e54bc..d1262ba3e2e6e 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1304,6 +1304,7 @@ impl ExitStatusError { #[cfg(target_os = "linux")] mod linux_child_ext { use crate::io::ErrorKind; + use crate::macros::rustdoc_skip_body; use crate::os::linux::process as os; use crate::sys::{FromInner, process as imp}; use crate::{io, mem}; @@ -1319,14 +1320,13 @@ mod linux_child_ext { .ok_or_else(|| io::const_error!(ErrorKind::Uncategorized, "no pidfd was created.")) } + #[rustdoc_skip_body] fn into_pidfd(mut self) -> Result { - no_code! { - self.handle - .pidfd - .take() - .map(>::from_inner) - .ok_or_else(|| self) - } + self.handle + .pidfd + .take() + .map(>::from_inner) + .ok_or_else(|| self) } } } From 4d2c7adec81adabd0b36fe5abbee84b982cb0909 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 24 Oct 2026 23:23:00 +0200 Subject: [PATCH 3/5] Disable `unused_macros` check on `rustdoc_skip_body` --- library/std/src/macros.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index 7dcdd2c6246b1..15ff7afa45818 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -471,6 +471,7 @@ macro_rules! hash_map { /// /// The function's signature must still be valid on the documentation target. #[rustc_builtin_macro] +#[allow(unused_macros)] pub(crate) macro rustdoc_skip_body($item:item) { /* compiler built-in */ } From b8a7befb21f7ce9ec186ca2b8d935b281c9ff32b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Oct 2026 10:45:57 +0100 Subject: [PATCH 4/5] Ignore more std functions body --- library/std/src/os/fd/owned.rs | 19 ++++++++++++ library/std/src/os/fd/raw.rs | 10 ++++++ library/std/src/os/linux/fs.rs | 18 +++++++++++ library/std/src/os/linux/process.rs | 1 + library/std/src/os/net/linux_ext/socket.rs | 5 +++ library/std/src/os/net/linux_ext/tcp.rs | 3 ++ library/std/src/os/unix/ffi/os_str.rs | 3 ++ library/std/src/os/unix/fs.rs | 18 +++++++++++ library/std/src/os/unix/fs/dirs.rs | 7 +++++ library/std/src/os/unix/io/mod.rs | 2 ++ library/std/src/os/unix/net/addr.rs | 5 +++ library/std/src/os/unix/net/ancillary.rs | 6 ++++ library/std/src/os/unix/net/datagram.rs | 14 +++++++++ library/std/src/os/unix/net/listener.rs | 8 +++++ library/std/src/os/unix/net/stream.rs | 13 ++++++++ library/std/src/os/unix/process.rs | 36 ++++++++++++++++++++++ library/std/src/os/unix/thread.rs | 3 ++ library/std/src/os/wasi/fs.rs | 4 +++ 18 files changed, 175 insertions(+) diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index dd6336748db2c..c336b11e91f7c 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -10,6 +10,7 @@ use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use crate::alloc::Allocator; #[cfg(not(target_os = "trusty"))] use crate::fs; +use crate::macros::rustdoc_skip_body; use crate::marker::PhantomData; use crate::mem::ManuallyDrop; #[cfg(not(any( @@ -136,6 +137,7 @@ impl BorrowedFd<'_> { target_os = "motor" )))] #[stable(feature = "io_safety", since = "1.63.0")] + #[rustdoc_skip_body] pub fn try_clone_to_owned(&self) -> io::Result { // We want to atomically duplicate this file descriptor and set the // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This @@ -225,6 +227,7 @@ impl FromRawFd for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] impl Drop for OwnedFd { #[inline] + #[rustdoc_skip_body] fn drop(&mut self) { unsafe { // Note that errors are ignored when closing a file descriptor. According to POSIX 2024, @@ -344,6 +347,7 @@ impl AsFd for OwnedFd { #[cfg(not(target_os = "trusty"))] impl AsFd for fs::File { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().as_fd() } @@ -354,6 +358,7 @@ impl AsFd for fs::File { impl From for OwnedFd { /// Takes ownership of a [`File`](fs::File)'s underlying file descriptor. #[inline] + #[rustdoc_skip_body] fn from(file: fs::File) -> OwnedFd { file.into_inner().into_inner().into_inner() } @@ -365,6 +370,7 @@ impl From for fs::File { /// Returns a [`File`](fs::File) that takes ownership of the given /// file descriptor. #[inline] + #[rustdoc_skip_body] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd))) } @@ -374,6 +380,7 @@ impl From for fs::File { #[cfg(not(target_os = "trusty"))] impl AsFd for crate::net::TcpStream { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().socket().as_fd() } @@ -384,6 +391,7 @@ impl AsFd for crate::net::TcpStream { impl From for OwnedFd { /// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor. #[inline] + #[rustdoc_skip_body] fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd { tcp_stream.into_inner().into_socket().into_inner().into_inner() } @@ -393,6 +401,7 @@ impl From for OwnedFd { #[cfg(not(target_os = "trusty"))] impl From for crate::net::TcpStream { #[inline] + #[rustdoc_skip_body] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( owned_fd, @@ -404,6 +413,7 @@ impl From for crate::net::TcpStream { #[cfg(not(target_os = "trusty"))] impl AsFd for crate::net::TcpListener { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().socket().as_fd() } @@ -414,6 +424,7 @@ impl AsFd for crate::net::TcpListener { impl From for OwnedFd { /// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor. #[inline] + #[rustdoc_skip_body] fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd { tcp_listener.into_inner().into_socket().into_inner().into_inner() } @@ -423,6 +434,7 @@ impl From for OwnedFd { #[cfg(not(target_os = "trusty"))] impl From for crate::net::TcpListener { #[inline] + #[rustdoc_skip_body] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( owned_fd, @@ -434,6 +446,7 @@ impl From for crate::net::TcpListener { #[cfg(not(target_os = "trusty"))] impl AsFd for crate::net::UdpSocket { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().socket().as_fd() } @@ -444,6 +457,7 @@ impl AsFd for crate::net::UdpSocket { impl From for OwnedFd { /// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor. #[inline] + #[rustdoc_skip_body] fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd { udp_socket.into_inner().into_socket().into_inner().into_inner() } @@ -453,6 +467,7 @@ impl From for OwnedFd { #[cfg(not(target_os = "trusty"))] impl From for crate::net::UdpSocket { #[inline] + #[rustdoc_skip_body] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( owned_fd, @@ -613,6 +628,7 @@ impl<'a> AsFd for io::StderrLock<'a> { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl AsFd for io::PipeReader { + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } @@ -621,6 +637,7 @@ impl AsFd for io::PipeReader { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl From for OwnedFd { + #[rustdoc_skip_body] fn from(pipe: io::PipeReader) -> Self { pipe.0.into_inner() } @@ -629,6 +646,7 @@ impl From for OwnedFd { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl AsFd for io::PipeWriter { + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } @@ -637,6 +655,7 @@ impl AsFd for io::PipeWriter { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl From for OwnedFd { + #[rustdoc_skip_body] fn from(pipe: io::PipeWriter) -> Self { pipe.0.into_inner() } diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index 4d7b6a3e5fb53..41904018d095a 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -13,6 +13,7 @@ use crate::alloc::Allocator; #[cfg(not(target_os = "trusty"))] use crate::fs; use crate::io; +use crate::macros::rustdoc_skip_body; #[cfg(target_os = "hermit")] use crate::os::hermit::io::OwnedFd; #[cfg(all(not(target_os = "hermit"), not(target_os = "motor")))] @@ -172,6 +173,7 @@ impl FromRawFd for RawFd { #[cfg(not(target_os = "trusty"))] impl AsRawFd for fs::File { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.as_inner().as_raw_fd() } @@ -180,6 +182,7 @@ impl AsRawFd for fs::File { #[cfg(not(target_os = "trusty"))] impl FromRawFd for fs::File { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_fd(fd: RawFd) -> fs::File { unsafe { fs::File::from(OwnedFd::from_raw_fd(fd)) } } @@ -188,6 +191,7 @@ impl FromRawFd for fs::File { #[cfg(not(target_os = "trusty"))] impl IntoRawFd for fs::File { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.into_inner().into_inner().into_raw_fd() } @@ -293,6 +297,7 @@ impl AsRawFd for Box { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl AsRawFd for io::PipeReader { + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } @@ -301,6 +306,7 @@ impl AsRawFd for io::PipeReader { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl FromRawFd for io::PipeReader { + #[rustdoc_skip_body] unsafe fn from_raw_fd(raw_fd: RawFd) -> Self { Self::from_inner(unsafe { FromRawFd::from_raw_fd(raw_fd) }) } @@ -309,6 +315,7 @@ impl FromRawFd for io::PipeReader { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl IntoRawFd for io::PipeReader { + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.0.into_raw_fd() } @@ -317,6 +324,7 @@ impl IntoRawFd for io::PipeReader { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl AsRawFd for io::PipeWriter { + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } @@ -325,6 +333,7 @@ impl AsRawFd for io::PipeWriter { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl FromRawFd for io::PipeWriter { + #[rustdoc_skip_body] unsafe fn from_raw_fd(raw_fd: RawFd) -> Self { Self::from_inner(unsafe { FromRawFd::from_raw_fd(raw_fd) }) } @@ -333,6 +342,7 @@ impl FromRawFd for io::PipeWriter { #[stable(feature = "anonymous_pipe", since = "1.87.0")] #[cfg(not(target_os = "trusty"))] impl IntoRawFd for io::PipeWriter { + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.0.into_raw_fd() } diff --git a/library/std/src/os/linux/fs.rs b/library/std/src/os/linux/fs.rs index 0e8fa0a15da09..1f4021811e350 100644 --- a/library/std/src/os/linux/fs.rs +++ b/library/std/src/os/linux/fs.rs @@ -5,6 +5,7 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::Metadata; +use crate::macros::rustdoc_skip_body; #[allow(deprecated)] use crate::os::linux::raw; use crate::sys::AsInner; @@ -344,6 +345,7 @@ pub trait MetadataExt { #[stable(feature = "metadata_ext", since = "1.1.0")] impl MetadataExt for Metadata { #[allow(deprecated)] + #[rustdoc_skip_body] fn as_raw_stat(&self) -> &raw::stat { #[cfg(target_env = "musl")] unsafe { @@ -354,30 +356,39 @@ impl MetadataExt for Metadata { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) } } + #[rustdoc_skip_body] fn st_dev(&self) -> u64 { self.as_inner().as_inner().st_dev as u64 } + #[rustdoc_skip_body] fn st_ino(&self) -> u64 { self.as_inner().as_inner().st_ino as u64 } + #[rustdoc_skip_body] fn st_mode(&self) -> u32 { self.as_inner().as_inner().st_mode as u32 } + #[rustdoc_skip_body] fn st_nlink(&self) -> u64 { self.as_inner().as_inner().st_nlink as u64 } + #[rustdoc_skip_body] fn st_uid(&self) -> u32 { self.as_inner().as_inner().st_uid as u32 } + #[rustdoc_skip_body] fn st_gid(&self) -> u32 { self.as_inner().as_inner().st_gid as u32 } + #[rustdoc_skip_body] fn st_rdev(&self) -> u64 { self.as_inner().as_inner().st_rdev as u64 } + #[rustdoc_skip_body] fn st_size(&self) -> u64 { self.as_inner().as_inner().st_size as u64 } + #[rustdoc_skip_body] fn st_atime(&self) -> i64 { let file_attr = self.as_inner(); #[cfg(all(target_env = "gnu", target_pointer_width = "32"))] @@ -386,9 +397,11 @@ impl MetadataExt for Metadata { } file_attr.as_inner().st_atime as i64 } + #[rustdoc_skip_body] fn st_atime_nsec(&self) -> i64 { self.as_inner().as_inner().st_atime_nsec as i64 } + #[rustdoc_skip_body] fn st_mtime(&self) -> i64 { let file_attr = self.as_inner(); #[cfg(all(target_env = "gnu", target_pointer_width = "32"))] @@ -397,9 +410,11 @@ impl MetadataExt for Metadata { } file_attr.as_inner().st_mtime as i64 } + #[rustdoc_skip_body] fn st_mtime_nsec(&self) -> i64 { self.as_inner().as_inner().st_mtime_nsec as i64 } + #[rustdoc_skip_body] fn st_ctime(&self) -> i64 { let file_attr = self.as_inner(); #[cfg(all(target_env = "gnu", target_pointer_width = "32"))] @@ -408,12 +423,15 @@ impl MetadataExt for Metadata { } file_attr.as_inner().st_ctime as i64 } + #[rustdoc_skip_body] fn st_ctime_nsec(&self) -> i64 { self.as_inner().as_inner().st_ctime_nsec as i64 } + #[rustdoc_skip_body] fn st_blksize(&self) -> u64 { self.as_inner().as_inner().st_blksize as u64 } + #[rustdoc_skip_body] fn st_blocks(&self) -> u64 { self.as_inner().as_inner().st_blocks as u64 } diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 26a4ab4b4c603..19cc16822f98d 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -221,6 +221,7 @@ pub impl(self) trait CommandExt { } impl CommandExt for process::Command { + #[rustdoc_skip_body] fn create_pidfd(&mut self, val: bool) -> &mut process::Command { self.as_inner_mut().create_pidfd(val); self diff --git a/library/std/src/os/net/linux_ext/socket.rs b/library/std/src/os/net/linux_ext/socket.rs index 777587fe4ce7c..67936e28f5f3f 100644 --- a/library/std/src/os/net/linux_ext/socket.rs +++ b/library/std/src/os/net/linux_ext/socket.rs @@ -1,6 +1,7 @@ //! Linux and Android-specific socket functionality. use crate::io; +use crate::macros::rustdoc_skip_body; use crate::os::unix::net; use crate::sys::AsInner; @@ -51,10 +52,12 @@ pub impl(self) trait UnixSocketExt { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] impl UnixSocketExt for net::UnixDatagram { + #[rustdoc_skip_body] fn passcred(&self) -> io::Result { self.as_inner().passcred() } + #[rustdoc_skip_body] fn set_passcred(&self, passcred: bool) -> io::Result<()> { self.as_inner().set_passcred(passcred) } @@ -62,10 +65,12 @@ impl UnixSocketExt for net::UnixDatagram { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] impl UnixSocketExt for net::UnixStream { + #[rustdoc_skip_body] fn passcred(&self) -> io::Result { self.as_inner().passcred() } + #[rustdoc_skip_body] fn set_passcred(&self, passcred: bool) -> io::Result<()> { self.as_inner().set_passcred(passcred) } diff --git a/library/std/src/os/net/linux_ext/tcp.rs b/library/std/src/os/net/linux_ext/tcp.rs index 2fc6b2769568e..726655b54d174 100644 --- a/library/std/src/os/net/linux_ext/tcp.rs +++ b/library/std/src/os/net/linux_ext/tcp.rs @@ -2,6 +2,7 @@ //! //! [`std::net`]: crate::net +use crate::macros::rustdoc_skip_body; use crate::sys::AsInner; #[cfg(target_os = "linux")] use crate::time::Duration; @@ -131,10 +132,12 @@ pub impl(self) trait TcpStreamExt { #[stable(feature = "tcp_quickack", since = "1.89.0")] impl TcpStreamExt for net::TcpStream { + #[rustdoc_skip_body] fn set_quickack(&self, quickack: bool) -> io::Result<()> { self.as_inner().as_inner().set_quickack(quickack) } + #[rustdoc_skip_body] fn quickack(&self) -> io::Result { self.as_inner().as_inner().quickack() } diff --git a/library/std/src/os/unix/ffi/os_str.rs b/library/std/src/os/unix/ffi/os_str.rs index 5beabd5618084..3a9312eb84692 100644 --- a/library/std/src/os/unix/ffi/os_str.rs +++ b/library/std/src/os/unix/ffi/os_str.rs @@ -1,4 +1,5 @@ use crate::ffi::{OsStr, OsString}; +use crate::macros::rustdoc_skip_body; use crate::mem; use crate::sys::os_str::Buf; use crate::sys::{AsInner, FromInner, IntoInner}; @@ -29,6 +30,7 @@ impl OsStringExt for OsString { FromInner::from_inner(Buf { inner: vec }) } #[inline] + #[rustdoc_skip_body] fn into_vec(self) -> Vec { self.into_inner().inner } @@ -57,6 +59,7 @@ impl OsStrExt for OsStr { unsafe { mem::transmute(slice) } } #[inline] + #[rustdoc_skip_body] fn as_bytes(&self) -> &[u8] { &self.as_inner().inner } diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index 6edb464b949d5..7a9524054ef7b 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -12,6 +12,7 @@ use super::platform::fs::MetadataExt as _; use crate::ffi::OsStr; use crate::fs::{self, OpenOptions, Permissions}; use crate::io::BorrowedCursor; +use crate::macros::rustdoc_skip_body; use crate::os::unix::io::{AsFd, AsRawFd}; use crate::path::Path; use crate::sys::{AsInner, AsInnerMut, FromInner}; @@ -372,12 +373,14 @@ impl FileExt for fs::File { fn read_buf_at(&self, buf: BorrowedCursor<'_, u8>, offset: u64) -> io::Result<()> { self.as_inner().read_buf_at(buf, offset) } + #[rustdoc_skip_body] fn read_vectored_at(&self, bufs: &mut [io::IoSliceMut<'_>], offset: u64) -> io::Result { self.as_inner().read_vectored_at(bufs, offset) } fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { self.as_inner().write_at(buf, offset) } + #[rustdoc_skip_body] fn write_vectored_at(&self, bufs: &[io::IoSlice<'_>], offset: u64) -> io::Result { self.as_inner().write_vectored_at(bufs, offset) } @@ -476,6 +479,7 @@ pub trait PermissionsExt { #[stable(feature = "fs_ext", since = "1.1.0")] impl PermissionsExt for Permissions { + #[rustdoc_skip_body] fn mode(&self) -> u32 { self.as_inner().mode() } @@ -545,11 +549,13 @@ pub trait OpenOptionsExt { #[stable(feature = "fs_ext", since = "1.1.0")] impl OpenOptionsExt for OpenOptions { + #[rustdoc_skip_body] fn mode(&mut self, mode: u32) -> &mut OpenOptions { self.as_inner_mut().mode(mode); self } + #[rustdoc_skip_body] fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions { self.as_inner_mut().custom_flags(flags); self @@ -1006,15 +1012,19 @@ pub trait FileTypeExt { #[stable(feature = "file_type_ext", since = "1.5.0")] impl FileTypeExt for fs::FileType { + #[rustdoc_skip_body] fn is_block_device(&self) -> bool { self.as_inner().is(libc::S_IFBLK) } + #[rustdoc_skip_body] fn is_char_device(&self) -> bool { self.as_inner().is(libc::S_IFCHR) } + #[rustdoc_skip_body] fn is_fifo(&self) -> bool { self.as_inner().is(libc::S_IFIFO) } + #[rustdoc_skip_body] fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) } @@ -1048,6 +1058,7 @@ pub trait DirEntryExt { #[stable(feature = "dir_entry_ext", since = "1.1.0")] impl DirEntryExt for fs::DirEntry { + #[rustdoc_skip_body] fn ino(&self) -> u64 { self.as_inner().ino() } @@ -1082,6 +1093,7 @@ pub impl(self) trait DirEntryExt2 { #[unstable(feature = "dir_entry_ext2", issue = "85573")] impl DirEntryExt2 for fs::DirEntry { + #[rustdoc_skip_body] fn file_name_ref(&self) -> &OsStr { self.as_inner().file_name_os_str() } @@ -1130,6 +1142,7 @@ pub trait DirBuilderExt { #[stable(feature = "dir_builder", since = "1.6.0")] impl DirBuilderExt for fs::DirBuilder { + #[rustdoc_skip_body] fn mode(&mut self, mode: u32) -> &mut fs::DirBuilder { self.as_inner_mut().set_mode(mode); self @@ -1164,6 +1177,7 @@ impl DirBuilderExt for fs::DirBuilder { /// } /// ``` #[stable(feature = "unix_chown", since = "1.73.0")] +#[rustdoc_skip_body] pub fn chown>(dir: P, uid: Option, gid: Option) -> io::Result<()> { sys::fs::chown(dir.as_ref(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX)) } @@ -1185,6 +1199,7 @@ pub fn chown>(dir: P, uid: Option, gid: Option) -> io:: /// } /// ``` #[stable(feature = "unix_chown", since = "1.73.0")] +#[rustdoc_skip_body] pub fn fchown(fd: F, uid: Option, gid: Option) -> io::Result<()> { sys::fs::fchown(fd.as_fd().as_raw_fd(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX)) } @@ -1206,6 +1221,7 @@ pub fn fchown(fd: F, uid: Option, gid: Option) -> io::Result< /// } /// ``` #[stable(feature = "unix_chown", since = "1.73.0")] +#[rustdoc_skip_body] pub fn lchown>(dir: P, uid: Option, gid: Option) -> io::Result<()> { sys::fs::lchown(dir.as_ref(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX)) } @@ -1232,6 +1248,7 @@ pub fn lchown>(dir: P, uid: Option, gid: Option) -> io: /// ``` #[stable(feature = "unix_chroot", since = "1.56.0")] #[cfg(not(target_os = "fuchsia"))] +#[rustdoc_skip_body] pub fn chroot>(dir: P) -> io::Result<()> { sys::fs::chroot(dir.as_ref()) } @@ -1269,6 +1286,7 @@ pub fn chroot>(dir: P) -> io::Result<()> { /// # } /// ``` #[unstable(feature = "unix_mkfifo", issue = "139324")] +#[rustdoc_skip_body] pub fn mkfifo>(path: P, permissions: Permissions) -> io::Result<()> { sys::fs::mkfifo(path.as_ref(), permissions.mode()) } diff --git a/library/std/src/os/unix/fs/dirs.rs b/library/std/src/os/unix/fs/dirs.rs index 5d8e13c7a730a..8081cb633acff 100644 --- a/library/std/src/os/unix/fs/dirs.rs +++ b/library/std/src/os/unix/fs/dirs.rs @@ -2,6 +2,7 @@ use crate::env::{self, SplitPathsRef}; use crate::ffi::{OsStr, OsString}; use crate::fs::{self, HomeDirs, MediaDirs}; use crate::io::{self, ErrorKind, const_error}; +use crate::macros::rustdoc_skip_body; use crate::path::{Path, PathBuf}; #[derive(Debug, Default, Clone)] @@ -247,14 +248,17 @@ impl HomeDirsExt for HomeDirs { Ok(dirs) } + #[rustdoc_skip_body] fn runtime_home(&self) -> Option<&Path> { self.extra.runtime.as_deref() } + #[rustdoc_skip_body] fn config_dirs(&self) -> Option> { self.extra.config_path.as_deref().map(XdgDirs::new) } + #[rustdoc_skip_body] fn data_dirs(&self) -> Option> { self.extra.data_path.as_deref().map(XdgDirs::new) } @@ -302,6 +306,7 @@ impl MediaDirsExt for MediaDirs { Ok(xdg::parse_user_dirs(&spec, &user_home)) } + #[rustdoc_skip_body] fn templates(&self) -> Option<&Path> { self.extra.templates.as_deref() } @@ -338,6 +343,7 @@ mod xdg { use crate::env::{self, join_paths, var_os}; use crate::ffi::OsString; use crate::io::{self, ErrorKind, const_error}; + use crate::macros::rustdoc_skip_body; use crate::ops::Deref; use crate::os::unix::ffi::{OsStrExt, OsStringExt}; use crate::path::{Path, PathBuf}; @@ -377,6 +383,7 @@ mod xdg { dirs(env).unwrap_or_else(|| fallback.into()) } + #[rustdoc_skip_body] pub fn parse_user_dirs<'a>(spec: &'a [u8], user_home: &Path) -> MediaDirs { let mut dirs = MediaDirs::empty(); diff --git a/library/std/src/os/unix/io/mod.rs b/library/std/src/os/unix/io/mod.rs index 099bdd35439a1..7804c4382f90c 100644 --- a/library/std/src/os/unix/io/mod.rs +++ b/library/std/src/os/unix/io/mod.rs @@ -93,6 +93,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::io::{self, Stderr, StderrLock, Stdin, StdinLock, Stdout, StdoutLock, Write}; +use crate::macros::rustdoc_skip_body; #[stable(feature = "rust1", since = "1.0.0")] pub use crate::os::fd::*; #[allow(unused_imports)] // not used on all targets @@ -209,6 +210,7 @@ fn null_fd() -> io::Result { /// Replaces the underlying file descriptor with the one from `other`. /// Does not set CLOEXEC. +#[rustdoc_skip_body] fn replace_stdio_fd(this: BorrowedFd<'_>, other: OwnedFd) -> io::Result<()> { cfg_select! { all(target_os = "wasi", target_env = "p1") => { diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index b03b359cdea91..e5fcb93b88308 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -1,5 +1,6 @@ use crate::byte_str::ByteStr; use crate::ffi::OsStr; +use crate::macros::rustdoc_skip_body; #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))] use crate::os::net::linux_ext; use crate::os::unix::ffi::OsStrExt; @@ -22,6 +23,7 @@ mod libc { const SUN_PATH_OFFSET: usize = mem::offset_of!(libc::sockaddr_un, sun_path); +#[rustdoc_skip_body] pub(super) fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::socklen_t)> { // SAFETY: All zeros is a valid representation for `sockaddr_un`. let mut addr: libc::sockaddr_un = unsafe { mem::zeroed() }; @@ -109,6 +111,7 @@ impl SocketAddr { } } + #[rustdoc_skip_body] pub(super) fn from_parts( addr: libc::sockaddr_un, mut len: libc::socklen_t, @@ -251,6 +254,7 @@ impl SocketAddr { if let AddressKind::Pathname(path) = self.address() { Some(path) } else { None } } + #[rustdoc_skip_body] fn address(&self) -> AddressKind<'_> { let len = self.len as usize - SUN_PATH_OFFSET; let path = unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&self.addr.sun_path) }; @@ -281,6 +285,7 @@ impl linux_ext::addr::SocketAddrExt for SocketAddr { if let AddressKind::Abstract(name) = self.address() { Some(name.as_bytes()) } else { None } } + #[rustdoc_skip_body] fn from_abstract_name(name: N) -> io::Result where N: AsRef<[u8]>, diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index bdf0384e34f80..acd564eb9c157 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -2,6 +2,7 @@ use super::{SocketAddr, sockaddr_un}; use crate::io::{self, IoSlice, IoSliceMut}; +use crate::macros::rustdoc_skip_body; use crate::marker::PhantomData; use crate::mem::zeroed; use crate::os::unix::io::RawFd; @@ -30,6 +31,7 @@ mod libc { pub type uid_t = u32; } +#[rustdoc_skip_body] pub(super) fn recv_vectored_with_ancillary_from( socket: &Socket, bufs: &mut [IoSliceMut<'_>], @@ -60,6 +62,7 @@ pub(super) fn recv_vectored_with_ancillary_from( } } +#[rustdoc_skip_body] pub(super) fn send_vectored_with_ancillary_to( socket: &Socket, path: Option<&Path>, @@ -87,6 +90,7 @@ pub(super) fn send_vectored_with_ancillary_to( } } +#[rustdoc_skip_body] fn add_to_ancillary_data( buffer: &mut [u8], length: &mut usize, @@ -503,6 +507,7 @@ impl<'a> AncillaryData<'a> { AncillaryData::ScmCredentials(scm_credentials) } + #[rustdoc_skip_body] fn try_from_cmsghdr(cmsg: &'a libc::cmsghdr) -> Result { unsafe { let cmsg_len_zero = libc::CMSG_LEN(0) as usize; @@ -543,6 +548,7 @@ pub struct Messages<'a> { impl<'a> Iterator for Messages<'a> { type Item = Result, AncillaryError>; + #[rustdoc_skip_body] fn next(&mut self) -> Option { unsafe { let mut msg: libc::msghdr = zeroed(); diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 309f80f7923b2..901263a7aa123 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -19,6 +19,7 @@ use super::{SocketAddr, sockaddr_un}; use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to}; #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))] use crate::io::{IoSlice, IoSliceMut}; +use crate::macros::rustdoc_skip_body; use crate::net::Shutdown; use crate::os::unix::io::{ AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd, unsafe_impl_fd_asrefs, @@ -298,6 +299,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn local_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getsockname(self.as_raw_fd(), addr, len) }) } @@ -323,6 +325,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn peer_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getpeername(self.as_raw_fd(), addr, len) }) } @@ -602,6 +605,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn send(&self, buf: &[u8]) -> io::Result { self.0.write(buf) } @@ -743,6 +747,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { self.0.set_timeout(timeout, libc::SO_RCVTIMEO) } @@ -789,6 +794,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { self.0.set_timeout(timeout, libc::SO_SNDTIMEO) } @@ -811,6 +817,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn read_timeout(&self) -> io::Result> { self.0.timeout(libc::SO_RCVTIMEO) } @@ -833,6 +840,7 @@ impl UnixDatagram { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn write_timeout(&self) -> io::Result> { self.0.timeout(libc::SO_SNDTIMEO) } @@ -877,6 +885,7 @@ impl UnixDatagram { /// ``` #[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))] #[unstable(feature = "unix_set_mark", issue = "96467")] + #[rustdoc_skip_body] pub fn set_mark(&self, mark: u32) -> io::Result<()> { self.0.set_mark(mark) } @@ -980,6 +989,7 @@ impl UnixDatagram { /// } /// ``` #[unstable(feature = "unix_socket_peek", issue = "76923")] + #[rustdoc_skip_body] pub fn peek_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { self.recv_from_flags(buf, libc::MSG_PEEK) } @@ -988,6 +998,7 @@ impl UnixDatagram { #[stable(feature = "unix_socket", since = "1.10.0")] impl AsRawFd for UnixDatagram { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.0.as_inner().as_raw_fd() } @@ -996,6 +1007,7 @@ impl AsRawFd for UnixDatagram { #[stable(feature = "unix_socket", since = "1.10.0")] impl FromRawFd for UnixDatagram { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram { UnixDatagram(Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd)))) } @@ -1004,6 +1016,7 @@ impl FromRawFd for UnixDatagram { #[stable(feature = "unix_socket", since = "1.10.0")] impl IntoRawFd for UnixDatagram { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.0.into_inner().into_inner().into_raw_fd() } @@ -1012,6 +1025,7 @@ impl IntoRawFd for UnixDatagram { #[stable(feature = "io_safety", since = "1.63.0")] impl AsFd for UnixDatagram { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_inner().as_fd() } diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 713ad2944a8cb..cc0bcdf9e614c 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -1,4 +1,5 @@ use super::{SocketAddr, UnixStream, sockaddr_un}; +use crate::macros::rustdoc_skip_body; use crate::os::unix::io::{ AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd, unsafe_impl_fd_asrefs, }; @@ -225,6 +226,7 @@ impl UnixListener { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn local_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getsockname(self.as_raw_fd(), addr, len) }) } @@ -320,6 +322,7 @@ impl UnixListener { #[stable(feature = "unix_socket", since = "1.10.0")] impl AsRawFd for UnixListener { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.0.as_inner().as_raw_fd() } @@ -328,6 +331,7 @@ impl AsRawFd for UnixListener { #[stable(feature = "unix_socket", since = "1.10.0")] impl FromRawFd for UnixListener { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_fd(fd: RawFd) -> UnixListener { UnixListener(Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd)))) } @@ -336,6 +340,7 @@ impl FromRawFd for UnixListener { #[stable(feature = "unix_socket", since = "1.10.0")] impl IntoRawFd for UnixListener { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.0.into_inner().into_inner().into_raw_fd() } @@ -344,6 +349,7 @@ impl IntoRawFd for UnixListener { #[stable(feature = "io_safety", since = "1.63.0")] impl AsFd for UnixListener { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_inner().as_fd() } @@ -352,6 +358,7 @@ impl AsFd for UnixListener { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixListener { #[inline] + #[rustdoc_skip_body] fn from(fd: OwnedFd) -> UnixListener { UnixListener(Socket::from_inner(FromInner::from_inner(fd))) } @@ -366,6 +373,7 @@ unsafe_impl_fd_asrefs!(UnixListener); impl From for OwnedFd { /// Takes ownership of a [`UnixListener`]'s socket file descriptor. #[inline] + #[rustdoc_skip_body] fn from(listener: UnixListener) -> OwnedFd { listener.0.into_inner().into_inner() } diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 00c3e75592ee2..3ad76f77aa475 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -39,6 +39,7 @@ use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_wi use super::{UCred, peer_cred}; use crate::fmt; use crate::io::{self, IoSlice, IoSliceMut}; +use crate::macros::rustdoc_skip_body; use crate::net::Shutdown; use crate::os::unix::io::{ AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd, unsafe_impl_fd_asrefs, @@ -225,6 +226,7 @@ impl UnixStream { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn local_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getsockname(self.as_raw_fd(), addr, len) }) } @@ -244,6 +246,7 @@ impl UnixStream { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn peer_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getpeername(self.as_raw_fd(), addr, len) }) } @@ -320,6 +323,7 @@ impl UnixStream { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { self.0.set_timeout(timeout, libc::SO_RCVTIMEO) } @@ -365,6 +369,7 @@ impl UnixStream { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { self.0.set_timeout(timeout, libc::SO_SNDTIMEO) } @@ -386,6 +391,7 @@ impl UnixStream { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn read_timeout(&self) -> io::Result> { self.0.timeout(libc::SO_RCVTIMEO) } @@ -408,6 +414,7 @@ impl UnixStream { /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] + #[rustdoc_skip_body] pub fn write_timeout(&self) -> io::Result> { self.0.timeout(libc::SO_SNDTIMEO) } @@ -452,6 +459,7 @@ impl UnixStream { /// ``` #[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))] #[unstable(feature = "unix_set_mark", issue = "96467")] + #[rustdoc_skip_body] pub fn set_mark(&self, mark: u32) -> io::Result<()> { self.0.set_mark(mark) } @@ -696,6 +704,7 @@ impl io::Write for UnixStream { #[stable(feature = "unix_socket", since = "1.10.0")] impl<'a> io::Write for &'a UnixStream { + #[rustdoc_skip_body] fn write(&mut self, buf: &[u8]) -> io::Result { self.0.send_with_flags(buf, MSG_NOSIGNAL) } @@ -718,6 +727,7 @@ impl<'a> io::Write for &'a UnixStream { #[stable(feature = "unix_socket", since = "1.10.0")] impl AsRawFd for UnixStream { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } @@ -726,6 +736,7 @@ impl AsRawFd for UnixStream { #[stable(feature = "unix_socket", since = "1.10.0")] impl FromRawFd for UnixStream { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_fd(fd: RawFd) -> UnixStream { UnixStream(Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd)))) } @@ -734,6 +745,7 @@ impl FromRawFd for UnixStream { #[stable(feature = "unix_socket", since = "1.10.0")] impl IntoRawFd for UnixStream { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.0.into_raw_fd() } @@ -742,6 +754,7 @@ impl IntoRawFd for UnixStream { #[stable(feature = "io_safety", since = "1.63.0")] impl AsFd for UnixStream { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index edd7d8dfb092d..1aa6076f3a7ed 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -5,6 +5,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::ffi::OsStr; +use crate::macros::rustdoc_skip_body; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::path::Path; #[cfg(doc)] @@ -252,21 +253,25 @@ pub impl(self) trait CommandExt { #[stable(feature = "rust1", since = "1.0.0")] impl CommandExt for process::Command { + #[rustdoc_skip_body] fn uid(&mut self, id: UserId) -> &mut process::Command { self.as_inner_mut().uid(id); self } + #[rustdoc_skip_body] fn gid(&mut self, id: GroupId) -> &mut process::Command { self.as_inner_mut().gid(id); self } + #[rustdoc_skip_body] fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command { self.as_inner_mut().groups(groups); self } + #[rustdoc_skip_body] unsafe fn pre_exec(&mut self, f: F) -> &mut process::Command where F: FnMut() -> io::Result<()> + Send + Sync + 'static, @@ -275,12 +280,14 @@ impl CommandExt for process::Command { self } + #[rustdoc_skip_body] fn exec(&mut self) -> io::Error { // NOTE: This may *not* be safe to call after `libc::fork`, because it // may allocate. That may be worth fixing at some point in the future. self.as_inner_mut().exec(sys::process::Stdio::Inherit) } + #[rustdoc_skip_body] fn arg0(&mut self, arg: S) -> &mut process::Command where S: AsRef, @@ -289,16 +296,19 @@ impl CommandExt for process::Command { self } + #[rustdoc_skip_body] fn process_group(&mut self, pgroup: i32) -> &mut process::Command { self.as_inner_mut().pgroup(pgroup); self } + #[rustdoc_skip_body] fn chroot>(&mut self, dir: P) -> &mut process::Command { self.as_inner_mut().chroot(dir.as_ref()); self } + #[rustdoc_skip_body] fn setsid(&mut self, setsid: bool) -> &mut process::Command { self.as_inner_mut().setsid(setsid); self @@ -443,26 +453,32 @@ pub impl(self) trait ExitStatusExt { #[stable(feature = "rust1", since = "1.0.0")] impl ExitStatusExt for process::ExitStatus { + #[rustdoc_skip_body] fn from_raw(raw: i32) -> Self { process::ExitStatus::from_inner(From::from(raw)) } + #[rustdoc_skip_body] fn signal(&self) -> Option { self.as_inner().signal() } + #[rustdoc_skip_body] fn core_dumped(&self) -> bool { self.as_inner().core_dumped() } + #[rustdoc_skip_body] fn stopped_signal(&self) -> Option { self.as_inner().stopped_signal() } + #[rustdoc_skip_body] fn continued(&self) -> bool { self.as_inner().continued() } + #[rustdoc_skip_body] fn into_raw(self) -> i32 { self.as_inner().into_raw().into() } @@ -594,15 +610,18 @@ pub impl(self) trait ChildExt { #[unstable(feature = "unix_send_signal", issue = "141975")] impl ChildExt for process::Child { + #[rustdoc_skip_body] fn send_signal(&self, signal: i32) -> io::Result<()> { self.handle.send_signal(signal) } + #[rustdoc_skip_body] fn send_process_group_signal(&self, signal: i32) -> io::Result<()> { self.handle.send_process_group_signal(signal) } #[cfg(not(target_os = "espidf"))] + #[rustdoc_skip_body] fn kill_process_group(&mut self) -> io::Result<()> { self.handle.send_process_group_signal(libc::SIGKILL) } @@ -619,6 +638,7 @@ impl ChildExt for process::Child { #[stable(feature = "process_extensions", since = "1.2.0")] impl FromRawFd for process::Stdio { #[inline] + #[rustdoc_skip_body] unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio { let fd = sys::fd::FileDesc::from_raw_fd(fd); let io = sys::process::Stdio::Fd(fd); @@ -631,6 +651,7 @@ impl From for process::Stdio { /// Takes ownership of a file descriptor and returns a [`Stdio`](process::Stdio) /// that can attach a stream to it. #[inline] + #[rustdoc_skip_body] fn from(fd: OwnedFd) -> process::Stdio { let fd = sys::fd::FileDesc::from_inner(fd); let io = sys::process::Stdio::Fd(fd); @@ -641,6 +662,7 @@ impl From for process::Stdio { #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawFd for process::ChildStdin { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.as_inner().as_raw_fd() } @@ -649,6 +671,7 @@ impl AsRawFd for process::ChildStdin { #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawFd for process::ChildStdout { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.as_inner().as_raw_fd() } @@ -657,6 +680,7 @@ impl AsRawFd for process::ChildStdout { #[stable(feature = "process_extensions", since = "1.2.0")] impl AsRawFd for process::ChildStderr { #[inline] + #[rustdoc_skip_body] fn as_raw_fd(&self) -> RawFd { self.as_inner().as_raw_fd() } @@ -665,6 +689,7 @@ impl AsRawFd for process::ChildStderr { #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawFd for process::ChildStdin { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.into_inner().into_inner().into_raw_fd() } @@ -673,6 +698,7 @@ impl IntoRawFd for process::ChildStdin { #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawFd for process::ChildStdout { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.into_inner().into_inner().into_raw_fd() } @@ -681,6 +707,7 @@ impl IntoRawFd for process::ChildStdout { #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawFd for process::ChildStderr { #[inline] + #[rustdoc_skip_body] fn into_raw_fd(self) -> RawFd { self.into_inner().into_inner().into_raw_fd() } @@ -689,6 +716,7 @@ impl IntoRawFd for process::ChildStderr { #[stable(feature = "io_safety", since = "1.63.0")] impl AsFd for crate::process::ChildStdin { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().as_fd() } @@ -698,6 +726,7 @@ impl AsFd for crate::process::ChildStdin { impl From for OwnedFd { /// Takes ownership of a [`ChildStdin`](crate::process::ChildStdin)'s file descriptor. #[inline] + #[rustdoc_skip_body] fn from(child_stdin: crate::process::ChildStdin) -> OwnedFd { child_stdin.into_inner().into_inner() } @@ -710,6 +739,7 @@ impl From for OwnedFd { #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStdin { #[inline] + #[rustdoc_skip_body] fn from(fd: OwnedFd) -> process::ChildStdin { let pipe = ChildPipe::from_inner(fd); process::ChildStdin::from_inner(pipe) @@ -719,6 +749,7 @@ impl From for process::ChildStdin { #[stable(feature = "io_safety", since = "1.63.0")] impl AsFd for crate::process::ChildStdout { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().as_fd() } @@ -728,6 +759,7 @@ impl AsFd for crate::process::ChildStdout { impl From for OwnedFd { /// Takes ownership of a [`ChildStdout`](crate::process::ChildStdout)'s file descriptor. #[inline] + #[rustdoc_skip_body] fn from(child_stdout: crate::process::ChildStdout) -> OwnedFd { child_stdout.into_inner().into_inner() } @@ -740,6 +772,7 @@ impl From for OwnedFd { #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStdout { #[inline] + #[rustdoc_skip_body] fn from(fd: OwnedFd) -> process::ChildStdout { let pipe = ChildPipe::from_inner(fd); process::ChildStdout::from_inner(pipe) @@ -749,6 +782,7 @@ impl From for process::ChildStdout { #[stable(feature = "io_safety", since = "1.63.0")] impl AsFd for crate::process::ChildStderr { #[inline] + #[rustdoc_skip_body] fn as_fd(&self) -> BorrowedFd<'_> { self.as_inner().as_fd() } @@ -758,6 +792,7 @@ impl AsFd for crate::process::ChildStderr { impl From for OwnedFd { /// Takes ownership of a [`ChildStderr`](crate::process::ChildStderr)'s file descriptor. #[inline] + #[rustdoc_skip_body] fn from(child_stderr: crate::process::ChildStderr) -> OwnedFd { child_stderr.into_inner().into_inner() } @@ -770,6 +805,7 @@ impl From for OwnedFd { #[stable(feature = "child_stream_from_fd", since = "1.74.0")] impl From for process::ChildStderr { #[inline] + #[rustdoc_skip_body] fn from(fd: OwnedFd) -> process::ChildStderr { let pipe = ChildPipe::from_inner(fd); process::ChildStderr::from_inner(pipe) diff --git a/library/std/src/os/unix/thread.rs b/library/std/src/os/unix/thread.rs index c19ccaf742da9..f022b01056615 100644 --- a/library/std/src/os/unix/thread.rs +++ b/library/std/src/os/unix/thread.rs @@ -4,6 +4,7 @@ #![stable(feature = "thread_extensions", since = "1.9.0")] +use crate::macros::rustdoc_skip_body; #[allow(deprecated)] use crate::os::unix::raw::pthread_t; use crate::sys::{AsInner, IntoInner}; @@ -35,11 +36,13 @@ impl JoinHandleExt for JoinHandle { // is an integer but libc::pthread_t is a pointer. Exposed provenance is the // safe choice here, but `as` also works when it's int2int or ptr2ptr. #[allow(implicit_provenance_casts)] + #[rustdoc_skip_body] fn as_pthread_t(&self) -> RawPthread { self.as_inner().id() as RawPthread } #[allow(implicit_provenance_casts)] // see above for why + #[rustdoc_skip_body] fn into_pthread_t(self) -> RawPthread { self.into_inner().into_id() as RawPthread } diff --git a/library/std/src/os/wasi/fs.rs b/library/std/src/os/wasi/fs.rs index 811ab7ea8480b..0d64cefec2ea3 100644 --- a/library/std/src/os/wasi/fs.rs +++ b/library/std/src/os/wasi/fs.rs @@ -233,6 +233,7 @@ impl FileExt for File { self.as_inner().read_buf_at(buf, offset) } + #[rustdoc_skip_body] fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { self.as_inner().read_vectored_at(bufs, offset) } @@ -241,6 +242,7 @@ impl FileExt for File { self.as_inner().write_at(buf, offset) } + #[rustdoc_skip_body] fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { self.as_inner().write_vectored_at(bufs, offset) } @@ -317,6 +319,7 @@ pub trait OpenOptionsExt { } impl OpenOptionsExt for OpenOptions { + #[rustdoc_skip_body] fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions { self.as_inner_mut().custom_flags(flags); self @@ -383,6 +386,7 @@ pub trait DirEntryExt { } impl DirEntryExt for fs::DirEntry { + #[rustdoc_skip_body] fn ino(&self) -> u64 { self.as_inner().ino() } From 6623b95fe0f61a97a5aa977162d5fc601cd7f8cf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 26 Oct 2026 23:26:05 +0100 Subject: [PATCH 5/5] Stop using `Path` on Windows to generate URLs because of wrong `\` path separator --- src/librustdoc/html/render/context.rs | 18 ++++++++---------- src/librustdoc/html/sources.rs | 13 ++++--------- tests/rustdoc-html/jump-to-def/nested-dirs.rs | 14 ++++++++++++++ .../jump-to-def/nested-dirs/a/b/mod.rs | 4 ++++ .../jump-to-def/nested-dirs/a/mod.rs | 3 +++ .../nested-dirs/compiletest-ignore-dir | 0 6 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 tests/rustdoc-html/jump-to-def/nested-dirs.rs create mode 100644 tests/rustdoc-html/jump-to-def/nested-dirs/a/b/mod.rs create mode 100644 tests/rustdoc-html/jump-to-def/nested-dirs/a/mod.rs create mode 100644 tests/rustdoc-html/jump-to-def/nested-dirs/compiletest-ignore-dir diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 96b735b08a894..88841e4d32f67 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -418,25 +418,23 @@ impl<'tcx> Context<'tcx> { ExternalLocation::Unknown => return None, }; - let href = RefCell::new(PathBuf::new()); + let components = RefCell::new(Vec::new()); sources::clean_path( &src_root, file, |component| { - href.borrow_mut().push(component); + components.borrow_mut().push(component.to_string_lossy().into_owned()); }, || { - href.borrow_mut().pop(); + components.borrow_mut().pop(); }, ); - path = href.into_inner().to_string_lossy().into_owned(); - - if let Some(c) = path.as_bytes().last() - && *c != b'/' - { - path.push('/'); - } + path = components.into_inner().iter().fold(String::new(), |mut acc, component| { + acc.push_str(component); + acc.push('/'); + acc + }); let mut fname = file.file_name().expect("source has no filename").to_os_string(); fname.push(".html"); diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 2328f0e8b9a11..b8a11adb5ac5b 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -74,24 +74,19 @@ impl LocalSourcesCollector<'_, '_> { return; } - let href = RefCell::new(PathBuf::new()); + let components = RefCell::new(Vec::new()); clean_path( self.src_root, &p, |component| { - href.borrow_mut().push(component); + components.borrow_mut().push(component.to_string_lossy().into_owned()); }, || { - href.borrow_mut().pop(); + components.borrow_mut().pop(); }, ); - let mut href = href.into_inner().to_string_lossy().into_owned(); - if let Some(c) = href.as_bytes().last() - && *c != b'/' - { - href.push('/'); - } + let mut href: String = components.into_inner().iter().map(|c| format!("{c}/")).collect(); let mut src_fname = p.file_name().expect("source has no filename").to_os_string(); src_fname.push(".html"); href.push_str(&src_fname.to_string_lossy()); diff --git a/tests/rustdoc-html/jump-to-def/nested-dirs.rs b/tests/rustdoc-html/jump-to-def/nested-dirs.rs new file mode 100644 index 0000000000000..c6a53c58ab156 --- /dev/null +++ b/tests/rustdoc-html/jump-to-def/nested-dirs.rs @@ -0,0 +1,14 @@ +// Checks that "jump-to-def" links on source pages don't generate links with `\` as separator +// on Windows. For other systems, just checks that the links are valid. + +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/nested-dirs/a/b/mod.rs.html' +//@ has - '//pre[@class="rust"]//a[@href="../../../nested-dirs.rs.html#14"]' 'Top' +//@ has - '//pre[@class="rust"]//a[@href="../mod.rs.html#3"]' 'Middle' +#[path = "nested-dirs/a/mod.rs"] +pub mod a; + +pub struct Top; diff --git a/tests/rustdoc-html/jump-to-def/nested-dirs/a/b/mod.rs b/tests/rustdoc-html/jump-to-def/nested-dirs/a/b/mod.rs new file mode 100644 index 0000000000000..96e11793634fc --- /dev/null +++ b/tests/rustdoc-html/jump-to-def/nested-dirs/a/b/mod.rs @@ -0,0 +1,4 @@ +use crate::Top; +use crate::a::Middle; + +pub struct Deep(Top, Middle); diff --git a/tests/rustdoc-html/jump-to-def/nested-dirs/a/mod.rs b/tests/rustdoc-html/jump-to-def/nested-dirs/a/mod.rs new file mode 100644 index 0000000000000..e045685bf5b89 --- /dev/null +++ b/tests/rustdoc-html/jump-to-def/nested-dirs/a/mod.rs @@ -0,0 +1,3 @@ +pub mod b; + +pub struct Middle; diff --git a/tests/rustdoc-html/jump-to-def/nested-dirs/compiletest-ignore-dir b/tests/rustdoc-html/jump-to-def/nested-dirs/compiletest-ignore-dir new file mode 100644 index 0000000000000..e69de29bb2d1d