From 38591d2d77c9fadf4d199ec6a6e937ec80d1796d Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 16 Jul 2026 07:05:06 +0000 Subject: [PATCH] Add #[inline] to core::io methods with simple logic or forwarding --- library/core/src/io/error.rs | 8 ++++++++ library/core/src/io/error/os_functions_atomic.rs | 1 + library/core/src/io/error/repr_bitpacked.rs | 1 + library/core/src/io/io_slice.rs | 2 ++ library/core/src/net/ip_addr.rs | 1 + 5 files changed, 13 insertions(+) diff --git a/library/core/src/io/error.rs b/library/core/src/io/error.rs index 61abdb16d07da..0df8b2d05cf48 100644 --- a/library/core/src/io/error.rs +++ b/library/core/src/io/error.rs @@ -534,6 +534,7 @@ impl fmt::Display for Error { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for Error { #[allow(deprecated)] + #[inline] fn cause(&self) -> Option<&dyn error::Error> { match self.repr.data() { ErrorData::Os(..) => None, @@ -543,6 +544,7 @@ impl error::Error for Error { } } + #[inline] fn source(&self) -> Option<&(dyn error::Error + 'static)> { match self.repr.data() { ErrorData::Os(..) => None, @@ -605,6 +607,7 @@ impl fmt::Debug for Custom { #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] impl Drop for Custom { + #[inline] fn drop(&mut self) { // SAFETY: `Custom::from_raw` ensures this call is safe. unsafe { @@ -631,12 +634,14 @@ impl Custom { } #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] + #[inline] pub fn into_raw(self) -> crate::ptr::NonNull { let ptr = self.error; core::mem::forget(self); ptr } + #[inline] fn error_ref(&self) -> &(dyn error::Error + Send + Sync + 'static) { // SAFETY: // `from_raw` ensures `error` is a valid pointer up to a static lifetime @@ -644,6 +649,7 @@ impl Custom { unsafe { self.error.as_ref() } } + #[inline] fn error_mut(&mut self) -> &mut (dyn error::Error + Send + Sync + 'static) { // SAFETY: // `from_raw` ensures `error` is a valid pointer up to a static lifetime @@ -668,6 +674,7 @@ unsafe impl Sync for CustomOwner {} #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] impl Drop for CustomOwner { + #[inline] fn drop(&mut self) { // SAFETY: `CustomOwner::from_raw` ensures this call is safe. unsafe { @@ -687,6 +694,7 @@ impl CustomOwner { } #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] + #[inline] pub fn into_raw(self) -> crate::ptr::NonNull { let ptr = self.0; core::mem::forget(self); diff --git a/library/core/src/io/error/os_functions_atomic.rs b/library/core/src/io/error/os_functions_atomic.rs index dfaf59ae742de..d4d77ced59187 100644 --- a/library/core/src/io/error/os_functions_atomic.rs +++ b/library/core/src/io/error/os_functions_atomic.rs @@ -15,6 +15,7 @@ use crate::sync::atomic; static OS_FUNCTIONS: atomic::AtomicPtr = atomic::AtomicPtr::new(OsFunctions::DEFAULT as *const _ as *mut _); +#[inline] fn get_os_functions() -> &'static OsFunctions { // SAFETY: // * `OS_FUNCTIONS` is initially a pointer to `OsFunctions::DEFAULT`, which is valid for a static lifetime. diff --git a/library/core/src/io/error/repr_bitpacked.rs b/library/core/src/io/error/repr_bitpacked.rs index 22cb331924081..8758e5543762a 100644 --- a/library/core/src/io/error/repr_bitpacked.rs +++ b/library/core/src/io/error/repr_bitpacked.rs @@ -133,6 +133,7 @@ unsafe impl Send for Repr {} unsafe impl Sync for Repr {} impl Repr { + #[inline] pub(super) fn new_custom(b: CustomOwner) -> Self { let p = b.into_raw().as_ptr().cast::(); // Should only be possible if an allocator handed out a pointer with diff --git a/library/core/src/io/io_slice.rs b/library/core/src/io/io_slice.rs index 0bdd410d3e964..807bbfcd36225 100644 --- a/library/core/src/io/io_slice.rs +++ b/library/core/src/io/io_slice.rs @@ -155,6 +155,7 @@ impl<'a> IoSliceMut<'a> { /// assert_eq!(&data, b"Abcdef"); /// ``` #[unstable(feature = "io_slice_as_bytes", issue = "132818")] + #[inline] pub const fn into_slice(self) -> &'a mut [u8] { self.0.into_slice() } @@ -323,6 +324,7 @@ impl<'a> IoSlice<'a> { /// assert_eq!(io_slice.as_slice(), b"def"); /// ``` #[unstable(feature = "io_slice_as_bytes", issue = "132818")] + #[inline] pub const fn as_slice(self) -> &'a [u8] { self.0.as_slice() } diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 4e380a93972e7..3fe98eba22358 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -2480,6 +2480,7 @@ macro_rules! bitop_impls { $(#[$attr])* const impl $BitOpAssign<&'_ $ty> for $ty { + #[inline] fn $bitop_assign(&mut self, rhs: &'_ $ty) { self.$bitop_assign(*rhs); }