Skip to content

Commit 9c3c8ef

Browse files
committed
Add #[inline] to small functions in core
1 parent 3edee2b commit 9c3c8ef

36 files changed

+114
-0
lines changed

library/core/src/alloc/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ impl Error for LayoutError {}
482482
// (we need this for downstream impl of trait Error)
483483
#[stable(feature = "alloc_layout", since = "1.28.0")]
484484
impl fmt::Display for LayoutError {
485+
#[inline]
485486
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
486487
f.write_str("invalid parameters to Layout::from_size_align")
487488
}

library/core/src/alloc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl Error for AllocError {}
4343
// (we need this for downstream impl of trait Error)
4444
#[unstable(feature = "allocator_api", issue = "32838")]
4545
impl fmt::Display for AllocError {
46+
#[inline]
4647
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4748
f.write_str("memory allocation failed")
4849
}

library/core/src/any.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ impl TypeId {
630630
#[must_use]
631631
#[stable(feature = "rust1", since = "1.0.0")]
632632
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
633+
#[inline]
633634
pub const fn of<T: ?Sized + 'static>() -> TypeId {
634635
let t: u128 = intrinsics::type_id::<T>();
635636
TypeId { t }

library/core/src/ascii.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct EscapeDefault(escape::EscapeIterInner<4>);
9090
/// assert_eq!(b'd', escaped.next().unwrap());
9191
/// ```
9292
#[stable(feature = "rust1", since = "1.0.0")]
93+
#[inline]
9394
pub fn escape_default(c: u8) -> EscapeDefault {
9495
let mut data = [Char::Null; 4];
9596
let range = escape::escape_ascii_into(&mut data, c);

library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ impl [AsciiChar] {
559559

560560
#[unstable(feature = "ascii_char", issue = "110998")]
561561
impl fmt::Display for AsciiChar {
562+
#[inline]
562563
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
563564
<str as fmt::Display>::fmt(self.as_str(), f)
564565
}

library/core/src/cell.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ impl Debug for BorrowError {
722722

723723
#[stable(feature = "try_borrow", since = "1.13.0")]
724724
impl Display for BorrowError {
725+
#[inline]
725726
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
726727
Display::fmt("already mutably borrowed", f)
727728
}
@@ -749,6 +750,7 @@ impl Debug for BorrowMutError {
749750

750751
#[stable(feature = "try_borrow", since = "1.13.0")]
751752
impl Display for BorrowMutError {
753+
#[inline]
752754
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
753755
Display::fmt("already borrowed", f)
754756
}

library/core/src/char/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ pub struct CharTryFromError(());
264264

265265
#[stable(feature = "try_from", since = "1.34.0")]
266266
impl fmt::Display for CharTryFromError {
267+
#[inline]
267268
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
268269
"converted integer out of range for `char`".fmt(f)
269270
}

library/core/src/char/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub const fn from_digit(num: u32, radix: u32) -> Option<char> {
152152
pub struct EscapeUnicode(escape::EscapeIterInner<10>);
153153

154154
impl EscapeUnicode {
155+
#[inline]
155156
fn new(chr: char) -> Self {
156157
let mut data = [ascii::Char::Null; 10];
157158
let range = escape::escape_unicode_into(&mut data, chr);
@@ -219,11 +220,13 @@ impl fmt::Display for EscapeUnicode {
219220
pub struct EscapeDefault(escape::EscapeIterInner<10>);
220221

221222
impl EscapeDefault {
223+
#[inline]
222224
fn printable(chr: ascii::Char) -> Self {
223225
let data = [chr];
224226
Self(escape::EscapeIterInner::from_array(data))
225227
}
226228

229+
#[inline]
227230
fn backslash(chr: ascii::Char) -> Self {
228231
let data = [ascii::Char::ReverseSolidus, chr];
229232
Self(escape::EscapeIterInner::from_array(data))
@@ -308,6 +311,7 @@ impl EscapeDebug {
308311
Self(EscapeDebugInner::Char(chr))
309312
}
310313

314+
#[inline]
311315
fn backslash(chr: ascii::Char) -> Self {
312316
let data = [ascii::Char::ReverseSolidus, chr];
313317
let iter = escape::EscapeIterInner::from_array(data);
@@ -318,6 +322,7 @@ impl EscapeDebug {
318322
Self(EscapeDebugInner::Bytes(esc.0))
319323
}
320324

325+
#[inline]
321326
fn clear(&mut self) {
322327
let bytes = escape::EscapeIterInner::from_array([]);
323328
self.0 = EscapeDebugInner::Bytes(bytes);
@@ -386,6 +391,7 @@ pub struct ToLowercase(CaseMappingIter);
386391
#[stable(feature = "rust1", since = "1.0.0")]
387392
impl Iterator for ToLowercase {
388393
type Item = char;
394+
#[inline]
389395
fn next(&mut self) -> Option<char> {
390396
self.0.next()
391397
}
@@ -396,6 +402,7 @@ impl Iterator for ToLowercase {
396402

397403
#[stable(feature = "case_mapping_double_ended", since = "1.59.0")]
398404
impl DoubleEndedIterator for ToLowercase {
405+
#[inline]
399406
fn next_back(&mut self) -> Option<char> {
400407
self.0.next_back()
401408
}
@@ -420,6 +427,7 @@ pub struct ToUppercase(CaseMappingIter);
420427
#[stable(feature = "rust1", since = "1.0.0")]
421428
impl Iterator for ToUppercase {
422429
type Item = char;
430+
#[inline]
423431
fn next(&mut self) -> Option<char> {
424432
self.0.next()
425433
}
@@ -430,6 +438,7 @@ impl Iterator for ToUppercase {
430438

431439
#[stable(feature = "case_mapping_double_ended", since = "1.59.0")]
432440
impl DoubleEndedIterator for ToUppercase {
441+
#[inline]
433442
fn next_back(&mut self) -> Option<char> {
434443
self.0.next_back()
435444
}
@@ -534,13 +543,15 @@ impl fmt::Display for CaseMappingIter {
534543

535544
#[stable(feature = "char_struct_display", since = "1.16.0")]
536545
impl fmt::Display for ToLowercase {
546+
#[inline]
537547
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
538548
fmt::Display::fmt(&self.0, f)
539549
}
540550
}
541551

542552
#[stable(feature = "char_struct_display", since = "1.16.0")]
543553
impl fmt::Display for ToUppercase {
554+
#[inline]
544555
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
545556
fmt::Display::fmt(&self.0, f)
546557
}
@@ -553,6 +564,7 @@ pub struct TryFromCharError(pub(crate) ());
553564

554565
#[stable(feature = "u8_from_char", since = "1.59.0")]
555566
impl fmt::Display for TryFromCharError {
567+
#[inline]
556568
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
557569
"unicode code point out of range".fmt(fmt)
558570
}

library/core/src/escape.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ impl<const N: usize> EscapeIterInner<N> {
8282
Self::new(data, 0..M as u8)
8383
}
8484

85+
#[inline]
8586
pub fn as_ascii(&self) -> &[ascii::Char] {
8687
&self.data[usize::from(self.alive.start)..usize::from(self.alive.end)]
8788
}
8889

90+
#[inline]
8991
pub fn as_str(&self) -> &str {
9092
self.as_ascii().as_str()
9193
}

library/core/src/ffi/c_str.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ pub struct FromBytesUntilNulError(());
158158

159159
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
160160
impl fmt::Display for FromBytesUntilNulError {
161+
#[inline]
161162
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
162163
write!(f, "data provided does not contain a nul")
163164
}
@@ -623,6 +624,7 @@ impl CStr {
623624
/// ```
624625
#[stable(feature = "cstr_to_str", since = "1.4.0")]
625626
#[rustc_const_stable(feature = "const_cstr_methods", since = "1.72.0")]
627+
#[inline]
626628
pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {
627629
// N.B., when `CStr` is changed to perform the length check in `.to_bytes()`
628630
// instead of in `from_ptr()`, it may be worth considering if this should

0 commit comments

Comments
 (0)