From d5304737448b82e0535fa83e6d661f8740d8cdd3 Mon Sep 17 00:00:00 2001 From: beetrees Date: Thu, 30 Mar 2023 15:15:42 +0100 Subject: [PATCH 1/9] Add 64-bit `time_t` support on 32-bit glibc Linux to `set_times` --- library/std/src/sys/unix/fs.rs | 19 +++++++++++++++++-- library/std/src/sys/unix/time.rs | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 7566fafda24..f01167bf2f3 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1192,8 +1192,6 @@ impl File { None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }), } }; - #[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))] - let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?]; cfg_if::cfg_if! { if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] { // Redox doesn't appear to support `UTIME_OMIT`. @@ -1205,6 +1203,7 @@ impl File { "setting file times not supported", )) } else if #[cfg(any(target_os = "android", target_os = "macos"))] { + let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?]; // futimens requires macOS 10.13, and Android API level 19 cvt(unsafe { weak!(fn futimens(c_int, *const libc::timespec) -> c_int); @@ -1231,6 +1230,22 @@ impl File { })?; Ok(()) } else { + #[cfg(all(target_os = "linux", target_env = "gnu", target_pointer_width = "32", not(target_arch = "riscv32")))] + { + use crate::sys::{time::__timespec64, weak::weak}; + + // Added in glibc 2.34 + weak!(fn __futimens64(libc::c_int, *const __timespec64) -> libc::c_int); + + if let Some(futimens64) = __futimens64.get() { + let to_timespec = |time: Option| time.map(|time| time.t.to_timespec64()) + .unwrap_or(__timespec64::new(0, libc::UTIME_OMIT as _)); + let times = [to_timespec(times.accessed), to_timespec(times.modified)]; + cvt(unsafe { futimens64(self.as_raw_fd(), times.as_ptr()) })?; + return Ok(()); + } + } + let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?]; cvt(unsafe { libc::futimens(self.as_raw_fd(), times.as_ptr()) })?; Ok(()) } diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 6f53583409d..a61d926ca8b 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -166,6 +166,16 @@ impl Timespec { } self.to_timespec() } + + #[cfg(all( + target_os = "linux", + target_env = "gnu", + target_pointer_width = "32", + not(target_arch = "riscv32") + ))] + pub fn to_timespec64(&self) -> __timespec64 { + __timespec64::new(self.tv_sec, self.tv_nsec.0 as _) + } } impl From for Timespec { @@ -190,6 +200,18 @@ pub(in crate::sys::unix) struct __timespec64 { _padding: i32, } +#[cfg(all( + target_os = "linux", + target_env = "gnu", + target_pointer_width = "32", + not(target_arch = "riscv32") +))] +impl __timespec64 { + pub(in crate::sys::unix) fn new(tv_sec: i64, tv_nsec: i32) -> Self { + Self { tv_sec, tv_nsec, _padding: 0 } + } +} + #[cfg(all( target_os = "linux", target_env = "gnu", From 4eb4e1022a3e8fd03fda44b40e270bd94cb9c476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Thu, 23 Mar 2023 17:29:55 -0300 Subject: [PATCH 2/9] edit docs of `PathBuf::set_file_name` to show this method might replace or remove the extension, not just the file stem also edit docs of `Path::with_file_name` because it calls `PathBuf::set_file_name` --- library/std/src/path.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index dbc18f7827e..f3608187cce 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1395,11 +1395,16 @@ impl PathBuf { /// /// let mut buf = PathBuf::from("/"); /// assert!(buf.file_name() == None); - /// buf.set_file_name("bar"); - /// assert!(buf == PathBuf::from("/bar")); + /// + /// buf.set_file_name("foo.txt"); + /// assert!(buf == PathBuf::from("/foo.txt")); /// assert!(buf.file_name().is_some()); - /// buf.set_file_name("baz.txt"); - /// assert!(buf == PathBuf::from("/baz.txt")); + /// + /// buf.set_file_name("bar.txt"); + /// assert!(buf == PathBuf::from("/bar.txt")); + /// + /// buf.set_file_name("baz"); + /// assert!(buf == PathBuf::from("/baz")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn set_file_name>(&mut self, file_name: S) { @@ -2562,7 +2567,8 @@ impl Path { /// ``` /// use std::path::{Path, PathBuf}; /// - /// let path = Path::new("/tmp/foo.txt"); + /// let path = Path::new("/tmp/foo.png"); + /// assert_eq!(path.with_file_name("bar"), PathBuf::from("/tmp/bar")); /// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt")); /// /// let path = Path::new("/tmp"); From bca9387e1c53415bf64519d07e3a019aa083d037 Mon Sep 17 00:00:00 2001 From: clundro <859287553@qq.com> Date: Sat, 29 Apr 2023 19:04:16 +0800 Subject: [PATCH 3/9] update wasi_clock_time_api ref. Signed-off-by: clundro <859287553@qq.com> --- library/std/src/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/time.rs b/library/std/src/time.rs index 5c2e9da70fb..00e2857a137 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -119,7 +119,7 @@ pub use core::time::TryFromFloatSecsError; /// [QueryPerformanceCounter]: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter /// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time /// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode -/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#clock_time_get +/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#clock_time_get /// [clock_gettime (Monotonic Clock)]: https://linux.die.net/man/3/clock_gettime /// [mach_absolute_time]: https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/services/services.html /// @@ -224,7 +224,7 @@ pub struct Instant(time::Instant); /// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode /// [gettimeofday]: https://man7.org/linux/man-pages/man2/gettimeofday.2.html /// [clock_gettime (Realtime Clock)]: https://linux.die.net/man/3/clock_gettime -/// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#clock_time_get +/// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#clock_time_get /// [GetSystemTimePreciseAsFileTime]: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime /// [GetSystemTimeAsFileTime]: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimeasfiletime /// From c678acd3a275c9acd34c2ecfa9b7b06e2ca7874f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sun, 30 Apr 2023 00:00:00 +0000 Subject: [PATCH 4/9] Leave promoteds untainted by errors when borrowck fails Previously, when borrowck failed it would taint all promoteds within the MIR body. An attempt to evaluated the promoteds would subsequently fail with spurious "note: erroneous constant used". For example: ```console ... note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:9 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:14 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:19 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:24 | 7 | a = &0 * &1 * &2 * &3; | ^^ ``` Borrowck failure doesn't indicate that there is anything wrong with promoteds. Leave them untainted. --- compiler/rustc_mir_transform/src/lib.rs | 5 +---- tests/ui/borrowck/tainted-promoteds.rs | 12 ++++++++++++ tests/ui/borrowck/tainted-promoteds.stderr | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/ui/borrowck/tainted-promoteds.rs create mode 100644 tests/ui/borrowck/tainted-promoteds.stderr diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 25d7db0ee60..8d9a22ea30d 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -616,13 +616,10 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec u32 { + let a = 0; + a = &0 * &1 * &2 * &3; + //~^ ERROR: cannot assign twice to immutable variable + a +} + +fn main() {} diff --git a/tests/ui/borrowck/tainted-promoteds.stderr b/tests/ui/borrowck/tainted-promoteds.stderr new file mode 100644 index 00000000000..b276ea9aceb --- /dev/null +++ b/tests/ui/borrowck/tainted-promoteds.stderr @@ -0,0 +1,14 @@ +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/tainted-promoteds.rs:7:5 + | +LL | let a = 0; + | - + | | + | first assignment to `a` + | help: consider making this binding mutable: `mut a` +LL | a = &0 * &1 * &2 * &3; + | ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0384`. From 77af67ab64ffd3daaa255d6afff1f02bb1f5faa2 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Fri, 28 Apr 2023 21:05:17 +1000 Subject: [PATCH 5/9] Add `#[no_coverage]` to the test harness's `fn main` --- compiler/rustc_builtin_macros/src/test_harness.rs | 6 ++++-- tests/pretty/tests-are-sorted.pp | 1 + .../expected_show_coverage.test_harness.txt | 11 +++++++++++ tests/run-make/coverage/test_harness.rs | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt create mode 100644 tests/run-make/coverage/test_harness.rs diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index be4ba66c082..9bc1e27b4ec 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -232,7 +232,7 @@ fn generate_test_harness( let expn_id = ext_cx.resolver.expansion_for_ast_pass( DUMMY_SP, AstPass::TestHarness, - &[sym::test, sym::rustc_attrs], + &[sym::test, sym::rustc_attrs, sym::no_coverage], None, ); let def_site = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id()); @@ -313,6 +313,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { // #[rustc_main] let main_attr = ecx.attr_word(sym::rustc_main, sp); + // #[no_coverage] + let no_coverage_attr = ecx.attr_word(sym::no_coverage, sp); // pub fn main() { ... } let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new())); @@ -342,7 +344,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let main = P(ast::Item { ident: main_id, - attrs: thin_vec![main_attr], + attrs: thin_vec![main_attr, no_coverage_attr], id: ast::DUMMY_NODE_ID, kind: main, vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None }, diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index 58f746f2e0e..7d7f682130d 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -79,6 +79,7 @@ pub const a_test: test::TestDescAndFn = }; fn a_test() {} #[rustc_main] +#[no_coverage] pub fn main() -> () { extern crate test; test::test_main_static(&[&a_test, &m_test, &z_test]) diff --git a/tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt b/tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt new file mode 100644 index 00000000000..93bd1cfcb48 --- /dev/null +++ b/tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt @@ -0,0 +1,11 @@ + 1| |// Verify that the entry point injected by the test harness doesn't cause + 2| |// weird artifacts in the coverage report (e.g. issue #10749). + 3| | + 4| |// compile-flags: --test + 5| | + 6| |#[allow(dead_code)] + 7| 0|fn unused() {} + 8| | + 9| 1|#[test] + 10| 1|fn my_test() {} + diff --git a/tests/run-make/coverage/test_harness.rs b/tests/run-make/coverage/test_harness.rs new file mode 100644 index 00000000000..12a755734c1 --- /dev/null +++ b/tests/run-make/coverage/test_harness.rs @@ -0,0 +1,10 @@ +// Verify that the entry point injected by the test harness doesn't cause +// weird artifacts in the coverage report (e.g. issue #10749). + +// compile-flags: --test + +#[allow(dead_code)] +fn unused() {} + +#[test] +fn my_test() {} From 174c0e86ca953a200d4a1afabe7a17e55f9783c2 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Mon, 1 May 2023 13:25:09 +0200 Subject: [PATCH 6/9] Inline AsInner implementations --- library/std/src/fs.rs | 8 ++++++++ library/std/src/net/tcp.rs | 2 ++ library/std/src/net/udp.rs | 1 + library/std/src/os/linux/process.rs | 1 + library/std/src/process.rs | 8 ++++++++ library/std/src/sys/hermit/fd.rs | 1 + library/std/src/sys/hermit/fs.rs | 2 ++ library/std/src/sys/hermit/net.rs | 1 + library/std/src/sys/sgx/fd.rs | 1 + library/std/src/sys/sgx/net.rs | 3 +++ library/std/src/sys/solid/net.rs | 2 ++ library/std/src/sys/unix/fd.rs | 1 + library/std/src/sys/unix/fs.rs | 3 +++ library/std/src/sys/unix/l4re.rs | 1 + library/std/src/sys/unix/net.rs | 1 + library/std/src/sys/unix/os_str.rs | 1 + library/std/src/sys/wasi/fd.rs | 2 ++ library/std/src/sys/wasi/fs.rs | 1 + library/std/src/sys/wasi/net.rs | 3 +++ library/std/src/sys/windows/fs.rs | 1 + library/std/src/sys/windows/handle.rs | 1 + library/std/src/sys/windows/net.rs | 1 + library/std/src/sys/windows/os_str.rs | 1 + library/std/src/sys_common/net.rs | 1 + library/std/src/sys_common/wtf8.rs | 1 + 25 files changed, 49 insertions(+) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 30e553f285b..6640c7fb162 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -709,6 +709,7 @@ impl File { // `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows. impl AsInner for File { + #[inline] fn as_inner(&self) -> &fs_imp::File { &self.inner } @@ -1087,12 +1088,14 @@ impl OpenOptions { } impl AsInner for OpenOptions { + #[inline] fn as_inner(&self) -> &fs_imp::OpenOptions { &self.0 } } impl AsInnerMut for OpenOptions { + #[inline] fn as_inner_mut(&mut self) -> &mut fs_imp::OpenOptions { &mut self.0 } @@ -1352,6 +1355,7 @@ impl fmt::Debug for Metadata { } impl AsInner for Metadata { + #[inline] fn as_inner(&self) -> &fs_imp::FileAttr { &self.0 } @@ -1604,6 +1608,7 @@ impl FileType { } impl AsInner for FileType { + #[inline] fn as_inner(&self) -> &fs_imp::FileType { &self.0 } @@ -1616,6 +1621,7 @@ impl FromInner for Permissions { } impl AsInner for Permissions { + #[inline] fn as_inner(&self) -> &fs_imp::FilePermissions { &self.0 } @@ -1770,6 +1776,7 @@ impl fmt::Debug for DirEntry { } impl AsInner for DirEntry { + #[inline] fn as_inner(&self) -> &fs_imp::DirEntry { &self.0 } @@ -2510,6 +2517,7 @@ impl DirBuilder { } impl AsInnerMut for DirBuilder { + #[inline] fn as_inner_mut(&mut self) -> &mut fs_imp::DirBuilder { &mut self.inner } diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 4b42ad65ee6..541e95d229b 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -691,6 +691,7 @@ impl Write for &TcpStream { } impl AsInner for TcpStream { + #[inline] fn as_inner(&self) -> &net_imp::TcpStream { &self.0 } @@ -1033,6 +1034,7 @@ impl Iterator for IntoIncoming { impl FusedIterator for IntoIncoming {} impl AsInner for TcpListener { + #[inline] fn as_inner(&self) -> &net_imp::TcpListener { &self.0 } diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 864e1b0f345..9628bcc5108 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -788,6 +788,7 @@ impl UdpSocket { // `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows. impl AsInner for UdpSocket { + #[inline] fn as_inner(&self) -> &net_imp::UdpSocket { &self.0 } diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 540363c0349..201db8c4615 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -52,6 +52,7 @@ pub struct PidFd { } impl AsInner for PidFd { + #[inline] fn as_inner(&self) -> &FileDesc { &self.inner } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 0ab72f7ea7a..bf22c2d46c9 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -211,6 +211,7 @@ pub struct Child { impl crate::sealed::Sealed for Child {} impl AsInner for Child { + #[inline] fn as_inner(&self) -> &imp::Process { &self.handle } @@ -304,6 +305,7 @@ impl Write for &ChildStdin { } impl AsInner for ChildStdin { + #[inline] fn as_inner(&self) -> &AnonPipe { &self.inner } @@ -373,6 +375,7 @@ impl Read for ChildStdout { } impl AsInner for ChildStdout { + #[inline] fn as_inner(&self) -> &AnonPipe { &self.inner } @@ -438,6 +441,7 @@ impl Read for ChildStderr { } impl AsInner for ChildStderr { + #[inline] fn as_inner(&self) -> &AnonPipe { &self.inner } @@ -1107,12 +1111,14 @@ impl fmt::Debug for Command { } impl AsInner for Command { + #[inline] fn as_inner(&self) -> &imp::Command { &self.inner } } impl AsInnerMut for Command { + #[inline] fn as_inner_mut(&mut self) -> &mut imp::Command { &mut self.inner } @@ -1605,6 +1611,7 @@ impl ExitStatus { } impl AsInner for ExitStatus { + #[inline] fn as_inner(&self) -> &imp::ExitStatus { &self.0 } @@ -1884,6 +1891,7 @@ impl From for ExitCode { } impl AsInner for ExitCode { + #[inline] fn as_inner(&self) -> &imp::ExitCode { &self.0 } diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index 3a2cdd301ea..ccde05aa1d7 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -75,6 +75,7 @@ impl FromRawFd for FileDesc { } impl AsInner for FileDesc { + #[inline] fn as_inner(&self) -> &OwnedFd { &self.fd } diff --git a/library/std/src/sys/hermit/fs.rs b/library/std/src/sys/hermit/fs.rs index cf0b271761f..5adffb8b7ff 100644 --- a/library/std/src/sys/hermit/fs.rs +++ b/library/std/src/sys/hermit/fs.rs @@ -367,12 +367,14 @@ impl DirBuilder { } impl AsInner for File { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } } impl AsInnerMut for File { + #[inline] fn as_inner_mut(&mut self) -> &mut FileDesc { &mut self.0 } diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index d6f64a29719..f38cb8b6aab 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -340,6 +340,7 @@ impl Socket { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } diff --git a/library/std/src/sys/sgx/fd.rs b/library/std/src/sys/sgx/fd.rs index 0c02a107691..b3686d0e283 100644 --- a/library/std/src/sys/sgx/fd.rs +++ b/library/std/src/sys/sgx/fd.rs @@ -62,6 +62,7 @@ impl FileDesc { } impl AsInner for FileDesc { + #[inline] fn as_inner(&self) -> &Fd { &self.fd } diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs index 923be5eb944..03620a08f2c 100644 --- a/library/std/src/sys/sgx/net.rs +++ b/library/std/src/sys/sgx/net.rs @@ -24,6 +24,7 @@ impl Socket { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &FileDesc { &self.inner } @@ -220,6 +221,7 @@ impl TcpStream { } impl AsInner for TcpStream { + #[inline] fn as_inner(&self) -> &Socket { &self.inner } @@ -304,6 +306,7 @@ impl TcpListener { } impl AsInner for TcpListener { + #[inline] fn as_inner(&self) -> &Socket { &self.inner } diff --git a/library/std/src/sys/solid/net.rs b/library/std/src/sys/solid/net.rs index 7d7bfae1432..0bd2bc3b961 100644 --- a/library/std/src/sys/solid/net.rs +++ b/library/std/src/sys/solid/net.rs @@ -112,6 +112,7 @@ impl FileDesc { } impl AsInner for FileDesc { + #[inline] fn as_inner(&self) -> &c_int { &self.fd } @@ -462,6 +463,7 @@ impl Socket { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &c_int { self.0.as_inner() } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index ce5c048f252..5cd756de271 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -481,6 +481,7 @@ impl<'a> Read for &'a FileDesc { } impl AsInner for FileDesc { + #[inline] fn as_inner(&self) -> &OwnedFd { &self.0 } diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index abef170dd5a..ebf677b3c4b 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -547,6 +547,7 @@ impl FileAttr { } impl AsInner for FileAttr { + #[inline] fn as_inner(&self) -> &stat64 { &self.stat } @@ -1254,12 +1255,14 @@ impl DirBuilder { } impl AsInner for File { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } } impl AsInnerMut for File { + #[inline] fn as_inner_mut(&mut self) -> &mut FileDesc { &mut self.0 } diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index 9967588939a..640cd96456c 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -129,6 +129,7 @@ pub mod net { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 573bfa6587e..355fffd12f7 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -490,6 +490,7 @@ impl Socket { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } diff --git a/library/std/src/sys/unix/os_str.rs b/library/std/src/sys/unix/os_str.rs index 017e2af29d4..488217f3941 100644 --- a/library/std/src/sys/unix/os_str.rs +++ b/library/std/src/sys/unix/os_str.rs @@ -89,6 +89,7 @@ impl IntoInner> for Buf { } impl AsInner<[u8]> for Buf { + #[inline] fn as_inner(&self) -> &[u8] { &self.inner } diff --git a/library/std/src/sys/wasi/fd.rs b/library/std/src/sys/wasi/fd.rs index 191db4b60f7..e9243e9ba46 100644 --- a/library/std/src/sys/wasi/fd.rs +++ b/library/std/src/sys/wasi/fd.rs @@ -275,12 +275,14 @@ impl WasiFd { } impl AsInner for WasiFd { + #[inline] fn as_inner(&self) -> &OwnedFd { &self.fd } } impl AsInnerMut for WasiFd { + #[inline] fn as_inner_mut(&mut self) -> &mut OwnedFd { &mut self.fd } diff --git a/library/std/src/sys/wasi/fs.rs b/library/std/src/sys/wasi/fs.rs index 3a205267e34..2c6b2885012 100644 --- a/library/std/src/sys/wasi/fs.rs +++ b/library/std/src/sys/wasi/fs.rs @@ -498,6 +498,7 @@ impl File { } impl AsInner for File { + #[inline] fn as_inner(&self) -> &WasiFd { &self.fd } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index 59d94a3686d..fc78cfcc17c 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -17,6 +17,7 @@ pub struct TcpStream { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &WasiFd { &self.0 } @@ -284,6 +285,7 @@ impl TcpListener { } impl AsInner for TcpListener { + #[inline] fn as_inner(&self) -> &Socket { &self.inner } @@ -446,6 +448,7 @@ impl UdpSocket { } impl AsInner for UdpSocket { + #[inline] fn as_inner(&self) -> &Socket { &self.inner } diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index 8ed62cdddcd..f99cdfbecfb 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -832,6 +832,7 @@ fn open_link_no_reparse(parent: &File, name: &[u16], access: u32) -> io::Result< } impl AsInner for File { + #[inline] fn as_inner(&self) -> &Handle { &self.handle } diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index b290f4070e8..c7677d1c13a 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -34,6 +34,7 @@ impl Handle { } impl AsInner for Handle { + #[inline] fn as_inner(&self) -> &OwnedHandle { &self.0 } diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index ee1f5482b47..8158713fa84 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -446,6 +446,7 @@ impl<'a> Read for &'a Socket { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &OwnedSocket { &self.0 } diff --git a/library/std/src/sys/windows/os_str.rs b/library/std/src/sys/windows/os_str.rs index 4bdd8c505ff..2f2b0e56e08 100644 --- a/library/std/src/sys/windows/os_str.rs +++ b/library/std/src/sys/windows/os_str.rs @@ -27,6 +27,7 @@ impl FromInner for Buf { } impl AsInner for Buf { + #[inline] fn as_inner(&self) -> &Wtf8 { &self.inner } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index cb24caa1e8a..a8deb885069 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -352,6 +352,7 @@ impl TcpStream { } impl AsInner for TcpStream { + #[inline] fn as_inner(&self) -> &Socket { &self.inner } diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs index bc588bdbb3c..ff96c35fb0b 100644 --- a/library/std/src/sys_common/wtf8.rs +++ b/library/std/src/sys_common/wtf8.rs @@ -501,6 +501,7 @@ pub struct Wtf8 { } impl AsInner<[u8]> for Wtf8 { + #[inline] fn as_inner(&self) -> &[u8] { &self.bytes } From 3abc30719e588745c8a9190a9842263cd2bfc463 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Mon, 1 May 2023 13:27:02 +0200 Subject: [PATCH 7/9] Inline socket function implementations --- library/std/src/sys/unix/l4re.rs | 3 +++ library/std/src/sys/wasi/net.rs | 3 +++ library/std/src/sys_common/net.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index 640cd96456c..d77a7ee87da 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -184,6 +184,7 @@ pub mod net { unimpl!(); } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -306,6 +307,7 @@ pub mod net { unimpl!(); } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -372,6 +374,7 @@ pub mod net { unimpl!(); } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index fc78cfcc17c..a5e0f9ee8ba 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -185,6 +185,7 @@ impl TcpStream { } } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -275,6 +276,7 @@ impl TcpListener { } } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -438,6 +440,7 @@ impl UdpSocket { unsupported() } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index a8deb885069..652c695fc57 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -239,6 +239,7 @@ impl TcpStream { Ok(TcpStream { inner: sock }) } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -428,6 +429,7 @@ impl TcpListener { Ok(TcpListener { inner: sock }) } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -518,6 +520,7 @@ impl UdpSocket { Ok(UdpSocket { inner: sock }) } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } From 500a8e13361787ad24c9ee88f8345d853ff628d3 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Mon, 1 May 2023 13:28:19 +0200 Subject: [PATCH 8/9] Inline AsRawFd implementations --- library/std/src/os/linux/process.rs | 1 + library/std/src/sys/hermit/fs.rs | 1 + library/std/src/sys/hermit/net.rs | 1 + library/std/src/sys/unix/fd.rs | 1 + library/std/src/sys/unix/fs.rs | 1 + library/std/src/sys/unix/l4re.rs | 1 + library/std/src/sys/unix/net.rs | 1 + library/std/src/sys/unix/pipe.rs | 1 + library/std/src/sys/wasi/fd.rs | 1 + library/std/src/sys/wasi/fs.rs | 1 + library/std/src/sys/wasi/net.rs | 1 + 11 files changed, 11 insertions(+) diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 201db8c4615..2b3ff76d7a4 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -71,6 +71,7 @@ impl IntoInner for PidFd { } impl AsRawFd for PidFd { + #[inline] fn as_raw_fd(&self) -> RawFd { self.as_inner().as_raw_fd() } diff --git a/library/std/src/sys/hermit/fs.rs b/library/std/src/sys/hermit/fs.rs index 5adffb8b7ff..4bb735668d2 100644 --- a/library/std/src/sys/hermit/fs.rs +++ b/library/std/src/sys/hermit/fs.rs @@ -399,6 +399,7 @@ impl AsFd for File { } impl AsRawFd for File { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index f38cb8b6aab..8c2d489d6a3 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -365,6 +365,7 @@ impl AsFd for Socket { } impl AsRawFd for Socket { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 5cd756de271..45f96478fc3 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -506,6 +506,7 @@ impl AsFd for FileDesc { } impl AsRawFd for FileDesc { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index ebf677b3c4b..96415fdbfdd 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1287,6 +1287,7 @@ impl AsFd for File { } impl AsRawFd for File { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index d77a7ee87da..ee016887e70 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -154,6 +154,7 @@ pub mod net { } impl AsRawFd for Socket { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 355fffd12f7..39edb136c24 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -515,6 +515,7 @@ impl AsFd for Socket { } impl AsRawFd for Socket { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/pipe.rs b/library/std/src/sys/unix/pipe.rs index dc17c9fac46..938a46bfdd8 100644 --- a/library/std/src/sys/unix/pipe.rs +++ b/library/std/src/sys/unix/pipe.rs @@ -135,6 +135,7 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, v2: &mut Vec) -> } impl AsRawFd for AnonPipe { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/wasi/fd.rs b/library/std/src/sys/wasi/fd.rs index e9243e9ba46..9a8b2a0be5b 100644 --- a/library/std/src/sys/wasi/fd.rs +++ b/library/std/src/sys/wasi/fd.rs @@ -307,6 +307,7 @@ impl AsFd for WasiFd { } impl AsRawFd for WasiFd { + #[inline] fn as_raw_fd(&self) -> RawFd { self.fd.as_raw_fd() } diff --git a/library/std/src/sys/wasi/fs.rs b/library/std/src/sys/wasi/fs.rs index 2c6b2885012..8d1dbf59155 100644 --- a/library/std/src/sys/wasi/fs.rs +++ b/library/std/src/sys/wasi/fs.rs @@ -523,6 +523,7 @@ impl AsFd for File { } impl AsRawFd for File { + #[inline] fn as_raw_fd(&self) -> RawFd { self.fd.as_raw_fd() } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index a5e0f9ee8ba..2239880ffbe 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -42,6 +42,7 @@ impl AsFd for Socket { } impl AsRawFd for Socket { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } From 09c50a0ae309dab351cb6c4d0f570a57ea72a7e9 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 1 May 2023 16:39:54 +0200 Subject: [PATCH 9/9] Explicitly document how Send and Sync relate to references Some of these relations were already mentioned in the text, but that Send is implemented for &mut impl Send was not mentioned, neither did the docs list when &T is Sync. --- library/core/src/marker.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 40789cb3049..82e4c648974 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -24,7 +24,7 @@ use crate::hash::Hasher; /// operations. Its cousin [`sync::Arc`][arc] does use atomic operations (incurring /// some overhead) and thus is `Send`. /// -/// See [the Nomicon](../../nomicon/send-and-sync.html) for more details. +/// See [the Nomicon](../../nomicon/send-and-sync.html) and the [`Sync`] trait for more details. /// /// [`Rc`]: ../../std/rc/struct.Rc.html /// [arc]: ../../std/sync/struct.Arc.html @@ -426,6 +426,11 @@ pub macro Copy($item:item) { /// becomes read-only, as if it were a `& &T`. Hence there is no risk /// of a data race. /// +/// A shorter overview of how [`Sync`] and [`Send`] relate to referencing: +/// * `&T` is [`Send`] if and only if `T` is [`Sync`] +/// * `&mut T` is [`Send`] if and only if `T` is [`Send`] +/// * `&T` and `&mut T` are [`Sync`] if and only if `T` is [`Sync`] +/// /// Types that are not `Sync` are those that have "interior /// mutability" in a non-thread-safe form, such as [`Cell`][cell] /// and [`RefCell`][refcell]. These types allow for mutation of