Skip to content

Commit 3ad59b1

Browse files
authored
Rollup merge of rust-lang#159369 - Darksonn:core-io-inline, r=Mark-Simulacrum
Add #[inline] to core::io methods with simple logic or forwarding These methods are super trivial, but they were observed as exported functions on the `core.o` object file in RfL. They are super trivial methods that just perform either a trivial operation or forward to another method call, so it makes much more sense for these to be inlined into their caller.
2 parents e604a79 + 38591d2 commit 3ad59b1

5 files changed

Lines changed: 13 additions & 0 deletions

File tree

library/core/src/io/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ impl fmt::Display for Error {
534534
#[stable(feature = "rust1", since = "1.0.0")]
535535
impl error::Error for Error {
536536
#[allow(deprecated)]
537+
#[inline]
537538
fn cause(&self) -> Option<&dyn error::Error> {
538539
match self.repr.data() {
539540
ErrorData::Os(..) => None,
@@ -543,6 +544,7 @@ impl error::Error for Error {
543544
}
544545
}
545546

547+
#[inline]
546548
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
547549
match self.repr.data() {
548550
ErrorData::Os(..) => None,
@@ -605,6 +607,7 @@ impl fmt::Debug for Custom {
605607

606608
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
607609
impl Drop for Custom {
610+
#[inline]
608611
fn drop(&mut self) {
609612
// SAFETY: `Custom::from_raw` ensures this call is safe.
610613
unsafe {
@@ -631,19 +634,22 @@ impl Custom {
631634
}
632635

633636
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
637+
#[inline]
634638
pub fn into_raw(self) -> crate::ptr::NonNull<dyn error::Error + Send + Sync> {
635639
let ptr = self.error;
636640
core::mem::forget(self);
637641
ptr
638642
}
639643

644+
#[inline]
640645
fn error_ref(&self) -> &(dyn error::Error + Send + Sync + 'static) {
641646
// SAFETY:
642647
// `from_raw` ensures `error` is a valid pointer up to a static lifetime
643648
// and is owned by `self`
644649
unsafe { self.error.as_ref() }
645650
}
646651

652+
#[inline]
647653
fn error_mut(&mut self) -> &mut (dyn error::Error + Send + Sync + 'static) {
648654
// SAFETY:
649655
// `from_raw` ensures `error` is a valid pointer up to a static lifetime
@@ -668,6 +674,7 @@ unsafe impl Sync for CustomOwner {}
668674

669675
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
670676
impl Drop for CustomOwner {
677+
#[inline]
671678
fn drop(&mut self) {
672679
// SAFETY: `CustomOwner::from_raw` ensures this call is safe.
673680
unsafe {
@@ -687,6 +694,7 @@ impl CustomOwner {
687694
}
688695

689696
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
697+
#[inline]
690698
pub fn into_raw(self) -> crate::ptr::NonNull<Custom> {
691699
let ptr = self.0;
692700
core::mem::forget(self);

library/core/src/io/error/os_functions_atomic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::sync::atomic;
1515
static OS_FUNCTIONS: atomic::AtomicPtr<OsFunctions> =
1616
atomic::AtomicPtr::new(OsFunctions::DEFAULT as *const _ as *mut _);
1717

18+
#[inline]
1819
fn get_os_functions() -> &'static OsFunctions {
1920
// SAFETY:
2021
// * `OS_FUNCTIONS` is initially a pointer to `OsFunctions::DEFAULT`, which is valid for a static lifetime.

library/core/src/io/error/repr_bitpacked.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ unsafe impl Send for Repr {}
133133
unsafe impl Sync for Repr {}
134134

135135
impl Repr {
136+
#[inline]
136137
pub(super) fn new_custom(b: CustomOwner) -> Self {
137138
let p = b.into_raw().as_ptr().cast::<u8>();
138139
// Should only be possible if an allocator handed out a pointer with

library/core/src/io/io_slice.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl<'a> IoSliceMut<'a> {
155155
/// assert_eq!(&data, b"Abcdef");
156156
/// ```
157157
#[unstable(feature = "io_slice_as_bytes", issue = "132818")]
158+
#[inline]
158159
pub const fn into_slice(self) -> &'a mut [u8] {
159160
self.0.into_slice()
160161
}
@@ -323,6 +324,7 @@ impl<'a> IoSlice<'a> {
323324
/// assert_eq!(io_slice.as_slice(), b"def");
324325
/// ```
325326
#[unstable(feature = "io_slice_as_bytes", issue = "132818")]
327+
#[inline]
326328
pub const fn as_slice(self) -> &'a [u8] {
327329
self.0.as_slice()
328330
}

library/core/src/net/ip_addr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,7 @@ macro_rules! bitop_impls {
24802480

24812481
$(#[$attr])*
24822482
const impl $BitOpAssign<&'_ $ty> for $ty {
2483+
#[inline]
24832484
fn $bitop_assign(&mut self, rhs: &'_ $ty) {
24842485
self.$bitop_assign(*rhs);
24852486
}

0 commit comments

Comments
 (0)