diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index ebd4a8c05fe30..853073d11a1ce 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -143,6 +143,7 @@ impl fmt::Display for TryFromSliceError { #[stable(feature = "try_from", since = "1.34.0")] impl Error for TryFromSliceError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "could not convert slice to array" } @@ -150,6 +151,7 @@ impl Error for TryFromSliceError { #[stable(feature = "try_from_slice_error", since = "1.36.0")] impl From for TryFromSliceError { + #[inline] fn from(x: Infallible) -> TryFromSliceError { match x {} } diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index b6b36886604b6..7f67728aa22c5 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -190,6 +190,7 @@ enum CharErrorKind { #[stable(feature = "char_from_str", since = "1.20.0")] impl Error for ParseCharError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { match self.kind { CharErrorKind::EmptyString => "cannot parse char from empty string", diff --git a/library/core/src/char/decode.rs b/library/core/src/char/decode.rs index dbfe251f2bb71..6bd17b7d41128 100644 --- a/library/core/src/char/decode.rs +++ b/library/core/src/char/decode.rs @@ -109,6 +109,7 @@ impl DecodeUtf16Error { /// Returns the unpaired surrogate which caused this error. #[must_use] #[stable(feature = "decode_utf16", since = "1.9.0")] + #[inline] pub fn unpaired_surrogate(&self) -> u16 { self.code } @@ -124,6 +125,7 @@ impl fmt::Display for DecodeUtf16Error { #[stable(feature = "decode_utf16", since = "1.9.0")] impl Error for DecodeUtf16Error { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "unpaired surrogate found" } diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs index 5c42912874c66..0e4e1bf7d52bf 100644 --- a/library/core/src/char/mod.rs +++ b/library/core/src/char/mod.rs @@ -229,6 +229,7 @@ impl EscapeDefault { Self(escape::EscapeIterInner::from_array(data)) } + #[inline] fn from_unicode(esc: EscapeUnicode) -> Self { Self(esc.0) } @@ -304,6 +305,7 @@ enum EscapeDebugInner { } impl EscapeDebug { + #[inline] fn printable(chr: char) -> Self { Self(EscapeDebugInner::Char(chr)) } @@ -314,6 +316,7 @@ impl EscapeDebug { Self(EscapeDebugInner::Bytes(iter)) } + #[inline] fn from_unicode(esc: EscapeUnicode) -> Self { Self(EscapeDebugInner::Bytes(esc.0)) } @@ -339,6 +342,7 @@ impl Iterator for EscapeDebug { } } + #[inline] fn size_hint(&self) -> (usize, Option) { let n = self.len(); (n, Some(n)) @@ -352,6 +356,7 @@ impl Iterator for EscapeDebug { #[stable(feature = "char_escape_debug", since = "1.20.0")] impl ExactSizeIterator for EscapeDebug { + #[inline] fn len(&self) -> usize { match &self.0 { EscapeDebugInner::Bytes(bytes) => bytes.len(), @@ -389,6 +394,7 @@ impl Iterator for ToLowercase { fn next(&mut self) -> Option { self.0.next() } + #[inline] fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } @@ -423,6 +429,7 @@ impl Iterator for ToUppercase { fn next(&mut self) -> Option { self.0.next() } + #[inline] fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } @@ -450,6 +457,7 @@ enum CaseMappingIter { } impl CaseMappingIter { + #[inline] fn new(chars: [char; 3]) -> CaseMappingIter { if chars[2] == '\0' { if chars[1] == '\0' { @@ -465,6 +473,7 @@ impl CaseMappingIter { impl Iterator for CaseMappingIter { type Item = char; + #[inline] fn next(&mut self) -> Option { match *self { CaseMappingIter::Three(a, b, c) => { @@ -483,6 +492,7 @@ impl Iterator for CaseMappingIter { } } + #[inline] fn size_hint(&self) -> (usize, Option) { let size = match self { CaseMappingIter::Three(..) => 3, @@ -495,6 +505,7 @@ impl Iterator for CaseMappingIter { } impl DoubleEndedIterator for CaseMappingIter { + #[inline] fn next_back(&mut self) -> Option { match *self { CaseMappingIter::Three(a, b, c) => { diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index fc8d19d1a58e2..68595f32190f4 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -904,6 +904,7 @@ pub enum Infallible {} #[stable(feature = "convert_infallible", since = "1.34.0")] impl Clone for Infallible { + #[inline] fn clone(&self) -> Infallible { match *self {} } @@ -911,6 +912,7 @@ impl Clone for Infallible { #[stable(feature = "convert_infallible", since = "1.34.0")] impl fmt::Debug for Infallible { + #[inline] fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {} } @@ -918,6 +920,7 @@ impl fmt::Debug for Infallible { #[stable(feature = "convert_infallible", since = "1.34.0")] impl fmt::Display for Infallible { + #[inline] fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {} } @@ -925,6 +928,7 @@ impl fmt::Display for Infallible { #[stable(feature = "str_parse_error2", since = "1.8.0")] impl Error for Infallible { + #[inline] fn description(&self) -> &str { match *self {} } @@ -932,6 +936,7 @@ impl Error for Infallible { #[stable(feature = "convert_infallible", since = "1.34.0")] impl PartialEq for Infallible { + #[inline] fn eq(&self, _: &Infallible) -> bool { match *self {} } @@ -942,6 +947,7 @@ impl Eq for Infallible {} #[stable(feature = "convert_infallible", since = "1.34.0")] impl PartialOrd for Infallible { + #[inline] fn partial_cmp(&self, _other: &Self) -> Option { match *self {} } @@ -949,6 +955,7 @@ impl PartialOrd for Infallible { #[stable(feature = "convert_infallible", since = "1.34.0")] impl Ord for Infallible { + #[inline] fn cmp(&self, _other: &Self) -> crate::cmp::Ordering { match *self {} } diff --git a/library/core/src/error.rs b/library/core/src/error.rs index 1170221c10c43..a0b8593c661fd 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -514,6 +514,7 @@ pub struct Request<'a>(dyn Erased<'a> + 'a); impl<'a> Request<'a> { /// Create a new `&mut Request` from a `&mut dyn Erased` trait object. + #[inline] fn new<'b>(erased: &'b mut (dyn Erased<'a> + 'a)) -> &'b mut Request<'a> { // SAFETY: transmuting `&mut (dyn Erased<'a> + 'a)` to `&mut Request<'a>` is safe since // `Request` is repr(transparent). @@ -1046,6 +1047,7 @@ impl<'a, T: Error + ?Sized> Error for &'a T { #[stable(feature = "fmt_error", since = "1.11.0")] impl Error for crate::fmt::Error { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "an error occurred when formatting an argument" } @@ -1054,6 +1056,7 @@ impl Error for crate::fmt::Error { #[stable(feature = "try_borrow", since = "1.13.0")] impl Error for crate::cell::BorrowError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "already mutably borrowed" } @@ -1062,6 +1065,7 @@ impl Error for crate::cell::BorrowError { #[stable(feature = "try_borrow", since = "1.13.0")] impl Error for crate::cell::BorrowMutError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "already borrowed" } @@ -1070,6 +1074,7 @@ impl Error for crate::cell::BorrowMutError { #[stable(feature = "try_from", since = "1.34.0")] impl Error for crate::char::CharTryFromError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "converted integer out of range for `char`" } diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 93a6716d7ab3d..17fc89349b416 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -124,9 +124,11 @@ enum FromBytesWithNulErrorKind { } impl FromBytesWithNulError { + #[inline] const fn interior_nul(pos: usize) -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::InteriorNul(pos) } } + #[inline] const fn not_nul_terminated() -> FromBytesWithNulError { FromBytesWithNulError { kind: FromBytesWithNulErrorKind::NotNulTerminated } } @@ -135,6 +137,7 @@ impl FromBytesWithNulError { #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] impl Error for FromBytesWithNulError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { match self.kind { FromBytesWithNulErrorKind::InteriorNul(..) => { @@ -695,6 +698,7 @@ impl AsRef for CStr { /// located within `isize::MAX` from `ptr`. #[inline] const unsafe fn const_strlen(ptr: *const c_char) -> usize { + #[inline] const fn strlen_ct(s: *const c_char) -> usize { let mut len = 0; diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index b2c9a0800c91b..15c9af5ed1264 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -612,6 +612,7 @@ impl<'f> Clone for VaListImpl<'f> { issue = "44930" )] impl<'f> Drop for VaListImpl<'f> { + #[inline] fn drop(&mut self) { // FIXME: this should call `va_end`, but there's no clean way to // guarantee that `drop` always gets inlined into its caller, diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index 47db53ac6f34b..037f6ceb9b47e 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -12,6 +12,7 @@ struct PadAdapterState { } impl Default for PadAdapterState { + #[inline] fn default() -> Self { PadAdapterState { on_newline: true } } diff --git a/library/core/src/fmt/float.rs b/library/core/src/fmt/float.rs index 3bbf5d8770bd2..95e147fcd4209 100644 --- a/library/core/src/fmt/float.rs +++ b/library/core/src/fmt/float.rs @@ -13,6 +13,7 @@ trait GeneralFormat: PartialOrd { macro_rules! impl_general_format { ($($t:ident)*) => { $(impl GeneralFormat for $t { + #[inline] fn already_rounded_value_should_use_exponential(&self) -> bool { let abs = $t::abs_private(*self); (abs != 0.0 && abs < 1e-4) || abs >= 1e+16 diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index c45ab094a20d6..c08f6df0b5d11 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -260,6 +260,7 @@ impl<'a> Formatter<'a> { /// Currently not intended for use outside of the standard library. #[unstable(feature = "fmt_internals", reason = "internal to standard library", issue = "none")] #[doc(hidden)] + #[inline] pub fn new(buf: &'a mut (dyn Write + 'a)) -> Formatter<'a> { Formatter { flags: 0, @@ -1591,6 +1592,7 @@ impl<'a> Formatter<'a> { note = "use the `sign_plus`, `sign_minus`, `alternate`, \ or `sign_aware_zero_pad` methods instead" )] + #[inline] pub fn flags(&self) -> u32 { self.flags } @@ -1624,6 +1626,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn fill(&self) -> char { self.fill } @@ -1659,6 +1662,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags_align", since = "1.28.0")] + #[inline] pub fn align(&self) -> Option { match self.align { rt::Alignment::Left => Some(Alignment::Left), @@ -1694,6 +1698,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn width(&self) -> Option { self.width } @@ -1725,6 +1730,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn precision(&self) -> Option { self.precision } @@ -1757,6 +1763,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn sign_plus(&self) -> bool { self.flags & (1 << rt::Flag::SignPlus as u32) != 0 } @@ -1786,6 +1793,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn sign_minus(&self) -> bool { self.flags & (1 << rt::Flag::SignMinus as u32) != 0 } @@ -1814,6 +1822,7 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn alternate(&self) -> bool { self.flags & (1 << rt::Flag::Alternate as u32) != 0 } @@ -1840,16 +1849,19 @@ impl<'a> Formatter<'a> { /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] + #[inline] pub fn sign_aware_zero_pad(&self) -> bool { self.flags & (1 << rt::Flag::SignAwareZeroPad as u32) != 0 } // FIXME: Decide what public API we want for these two flags. // https://github.com/rust-lang/rust/issues/48584 + #[inline] fn debug_lower_hex(&self) -> bool { self.flags & (1 << rt::Flag::DebugLowerHex as u32) != 0 } + #[inline] fn debug_upper_hex(&self) -> bool { self.flags & (1 << rt::Flag::DebugUpperHex as u32) != 0 } diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 4f42f73ebbaff..2f6116ec059e7 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -24,12 +24,19 @@ trait DisplayInt: macro_rules! impl_int { ($($t:ident)*) => ( $(impl DisplayInt for $t { + #[inline] fn zero() -> Self { 0 } + #[inline] fn from_u8(u: u8) -> Self { u as Self } + #[inline] fn to_u8(&self) -> u8 { *self as u8 } + #[inline] fn to_u16(&self) -> u16 { *self as u16 } + #[inline] fn to_u32(&self) -> u32 { *self as u32 } + #[inline] fn to_u64(&self) -> u64 { *self as u64 } + #[inline] fn to_u128(&self) -> u128 { *self as u128 } })* ) @@ -37,12 +44,19 @@ macro_rules! impl_int { macro_rules! impl_uint { ($($t:ident)*) => ( $(impl DisplayInt for $t { + #[inline] fn zero() -> Self { 0 } + #[inline] fn from_u8(u: u8) -> Self { u as Self } + #[inline] fn to_u8(&self) -> u8 { *self as u8 } + #[inline] fn to_u16(&self) -> u16 { *self as u16 } + #[inline] fn to_u32(&self) -> u32 { *self as u32 } + #[inline] fn to_u64(&self) -> u64 { *self as u64 } + #[inline] fn to_u128(&self) -> u128 { *self as u128 } })* ) diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 0d1cf7941fb69..5d3e05a6ee038 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -391,6 +391,7 @@ impl Extend<()> for () { fn extend>(&mut self, iter: T) { iter.into_iter().for_each(drop) } + #[inline] fn extend_one(&mut self, _item: ()) {} } diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index f5cc86e7767e8..4bff9e54dcb83 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -64,6 +64,7 @@ impl Assume { /// Assume both `self` and `other_assumptions`. #[unstable(feature = "transmutability", issue = "99571")] + #[inline] pub const fn and(self, other_assumptions: Self) -> Self { Self { alignment: self.alignment || other_assumptions.alignment, @@ -75,6 +76,7 @@ impl Assume { /// Assume `self`, excepting `other_assumptions`. #[unstable(feature = "transmutability", issue = "99571")] + #[inline] pub const fn but_not(self, other_assumptions: Self) -> Self { Self { alignment: self.alignment && !other_assumptions.alignment, diff --git a/library/core/src/net/parser.rs b/library/core/src/net/parser.rs index b9a1924d66898..d8f97e769130b 100644 --- a/library/core/src/net/parser.rs +++ b/library/core/src/net/parser.rs @@ -485,6 +485,7 @@ impl fmt::Display for AddrParseError { #[stable(feature = "addr_parse_error_error", since = "1.4.0")] impl Error for AddrParseError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { match self.0 { AddrKind::Ip => "invalid IP address syntax", diff --git a/library/core/src/num/bignum.rs b/library/core/src/num/bignum.rs index d2a21b6b38260..c6d065cb3fb7d 100644 --- a/library/core/src/num/bignum.rs +++ b/library/core/src/num/bignum.rs @@ -35,6 +35,7 @@ macro_rules! impl_full_ops { ($($ty:ty: add($addfn:path), mul/div($bigty:ident);)*) => ( $( impl FullOps for $ty { + #[inline] fn full_mul_add(self, other: $ty, other2: $ty, carry: $ty) -> ($ty, $ty) { // This cannot overflow; // the output is between `0` and `2^nbits * (2^nbits - 1)`. @@ -90,6 +91,7 @@ macro_rules! define_bignum { impl $name { /// Makes a bignum from one digit. + #[inline] pub fn from_small(v: $ty) -> $name { let mut base = [0; $n]; base[0] = v; @@ -402,6 +404,7 @@ macro_rules! define_bignum { } impl crate::clone::Clone for $name { + #[inline] fn clone(&self) -> Self { Self { size: self.size, base: self.base } } diff --git a/library/core/src/num/dec2flt/decimal.rs b/library/core/src/num/dec2flt/decimal.rs index 350f64bb4f7a3..8e5f92a6e5e8c 100644 --- a/library/core/src/num/dec2flt/decimal.rs +++ b/library/core/src/num/dec2flt/decimal.rs @@ -24,6 +24,7 @@ pub struct Decimal { } impl Default for Decimal { + #[inline] fn default() -> Self { Self { num_digits: 0, decimal_point: 0, truncated: false, digits: [0; Self::MAX_DIGITS] } } diff --git a/library/core/src/num/dec2flt/float.rs b/library/core/src/num/dec2flt/float.rs index 1c9d68999d6f8..fc1dcc81c503e 100644 --- a/library/core/src/num/dec2flt/float.rs +++ b/library/core/src/num/dec2flt/float.rs @@ -137,6 +137,7 @@ impl RawFloat for f32 { } /// Returns the mantissa, exponent and sign as integers. + #[inline] fn integer_decode(self) -> (u64, i16, i8) { let bits = self.to_bits(); let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 }; @@ -191,6 +192,7 @@ impl RawFloat for f64 { } /// Returns the mantissa, exponent and sign as integers. + #[inline] fn integer_decode(self) -> (u64, i16, i8) { let bits = self.to_bits(); let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 }; @@ -205,6 +207,7 @@ impl RawFloat for f64 { (mantissa, exponent, sign) } + #[inline] fn classify(self) -> FpCategory { self.classify() } diff --git a/library/core/src/num/dec2flt/mod.rs b/library/core/src/num/dec2flt/mod.rs index a4bc8b1c9b0c3..039e4bc4f7959 100644 --- a/library/core/src/num/dec2flt/mod.rs +++ b/library/core/src/num/dec2flt/mod.rs @@ -192,6 +192,7 @@ enum FloatErrorKind { #[stable(feature = "rust1", since = "1.0.0")] impl Error for ParseFloatError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { match self.kind { FloatErrorKind::Empty => "cannot parse float from empty string", diff --git a/library/core/src/num/diy_float.rs b/library/core/src/num/diy_float.rs index ce7f6475d0599..885ae86c401f6 100644 --- a/library/core/src/num/diy_float.rs +++ b/library/core/src/num/diy_float.rs @@ -21,6 +21,7 @@ pub struct Fp { impl Fp { /// Returns a correctly rounded product of itself and `other`. + #[inline] pub fn mul(&self, other: &Fp) -> Fp { const MASK: u64 = 0xffffffff; let a = self.f >> 32; @@ -38,6 +39,7 @@ impl Fp { } /// Normalizes itself so that the resulting mantissa is at least `2^63`. + #[inline] pub fn normalize(&self) -> Fp { let mut f = self.f; let mut e = self.e; diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 14e99578a7c7d..4b09a9b814e11 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -20,6 +20,7 @@ impl fmt::Display for TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl Error for TryFromIntError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "out of range integral type conversion attempted" } @@ -27,6 +28,7 @@ impl Error for TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl From for TryFromIntError { + #[inline] fn from(x: Infallible) -> TryFromIntError { match x {} } @@ -114,6 +116,7 @@ impl ParseIntError { /// Outputs the detailed cause of parsing an integer failing. #[must_use] #[stable(feature = "int_error_matching", since = "1.55.0")] + #[inline] pub fn kind(&self) -> &IntErrorKind { &self.kind } @@ -130,6 +133,7 @@ impl fmt::Display for ParseIntError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for ParseIntError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { match self.kind { IntErrorKind::Empty => "cannot parse integer from empty string", diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index f60626b00dc8a..5173e618b8c33 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -615,6 +615,7 @@ impl f32 { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] + #[inline] pub const fn classify(self) -> FpCategory { // A previous implementation tried to only use bitmask-based checks, // using f32::to_bits to transmute the float to its bit repr and match on that. @@ -660,6 +661,7 @@ impl f32 { // but getting floats correct is important for not accidentally leaking const eval // runtime-deviating logic which may or may not be acceptable. #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] + #[inline] const unsafe fn partial_classify(self) -> FpCategory { const EXP_MASK: u32 = 0x7f800000; const MAN_MASK: u32 = 0x007fffff; @@ -677,6 +679,7 @@ impl f32 { // FIXME(jubilee): In a just world, this would be the entire impl for classify, // plus a transmute. We do not live in a just world, but we can make it more so. #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] + #[inline] const fn classify_bits(b: u32) -> FpCategory { const EXP_MASK: u32 = 0x7f800000; const MAN_MASK: u32 = 0x007fffff; @@ -765,6 +768,7 @@ impl f32 { /// [`MAX`]: Self::MAX #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] + #[inline] pub const fn next_up(self) -> Self { // We must use strictly integer arithmetic to prevent denormals from // flushing to zero after an arithmetic operation on some platforms. @@ -815,6 +819,7 @@ impl f32 { /// [`MAX`]: Self::MAX #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] + #[inline] pub const fn next_down(self) -> Self { // We must use strictly integer arithmetic to prevent denormals from // flushing to zero after an arithmetic operation on some platforms. @@ -1013,6 +1018,7 @@ impl f32 { /// assert_eq!((-5.5f32).midpoint(8.0), 1.25); /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] + #[inline] pub fn midpoint(self, other: f32) -> f32 { const LO: f32 = f32::MIN_POSITIVE * 2.; const HI: f32 = f32::MAX / 2.; diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 0a87021d8c183..af9bea195714c 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -616,6 +616,7 @@ impl f64 { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] + #[inline] pub const fn classify(self) -> FpCategory { // A previous implementation tried to only use bitmask-based checks, // using f64::to_bits to transmute the float to its bit repr and match on that. @@ -651,6 +652,7 @@ impl f64 { // seeing as how it cannot correctly discern between a floating point NaN, // and some normal floating point numbers truncated from an x87 FPU. #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] + #[inline] const unsafe fn partial_classify(self) -> FpCategory { const EXP_MASK: u64 = 0x7ff0000000000000; const MAN_MASK: u64 = 0x000fffffffffffff; @@ -669,6 +671,7 @@ impl f64 { // FIXME(jubilee): In a just world, this would be the entire impl for classify, // plus a transmute. We do not live in a just world, but we can make it more so. #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] + #[inline] const fn classify_bits(b: u64) -> FpCategory { const EXP_MASK: u64 = 0x7ff0000000000000; const MAN_MASK: u64 = 0x000fffffffffffff; @@ -775,6 +778,7 @@ impl f64 { /// [`MAX`]: Self::MAX #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] + #[inline] pub const fn next_up(self) -> Self { // We must use strictly integer arithmetic to prevent denormals from // flushing to zero after an arithmetic operation on some platforms. @@ -825,6 +829,7 @@ impl f64 { /// [`MAX`]: Self::MAX #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] + #[inline] pub const fn next_down(self) -> Self { // We must use strictly integer arithmetic to prevent denormals from // flushing to zero after an arithmetic operation on some platforms. @@ -1024,6 +1029,7 @@ impl f64 { /// assert_eq!((-5.5f64).midpoint(8.0), 1.25); /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] + #[inline] pub fn midpoint(self, other: f64) -> f64 { const LO: f64 = f64::MIN_POSITIVE * 2.; const HI: f64 = f64::MAX / 2.; diff --git a/library/core/src/num/flt2dec/decoder.rs b/library/core/src/num/flt2dec/decoder.rs index 5763860540aa4..e08b4c3f6d044 100644 --- a/library/core/src/num/flt2dec/decoder.rs +++ b/library/core/src/num/flt2dec/decoder.rs @@ -46,12 +46,14 @@ pub trait DecodableFloat: RawFloat + Copy { } impl DecodableFloat for f32 { + #[inline] fn min_pos_norm_value() -> Self { f32::MIN_POSITIVE } } impl DecodableFloat for f64 { + #[inline] fn min_pos_norm_value() -> Self { f64::MIN_POSITIVE } diff --git a/library/core/src/num/flt2dec/mod.rs b/library/core/src/num/flt2dec/mod.rs index 1ff2e8c8228c9..b42d46ff3cde5 100644 --- a/library/core/src/num/flt2dec/mod.rs +++ b/library/core/src/num/flt2dec/mod.rs @@ -307,6 +307,7 @@ pub enum Sign { /// Returns the static byte string corresponding to the sign to be formatted. /// It can be either `""`, `"+"` or `"-"`. +#[inline] fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static str { match (*decoded, sign) { (FullDecoded::Nan, _) => "", @@ -492,6 +493,7 @@ where /// allocate all the buffer beforehand. Consequently, for any given arguments, /// 826 bytes of buffer should be sufficient for `f64`. Compare this with /// the actual number for the worst case: 770 bytes (when `exp = -1074`). +#[inline] fn estimate_max_buf_len(exp: i16) -> usize { 21 + ((if exp < 0 { -12 } else { 5 } * exp as i32) as usize >> 4) } diff --git a/library/core/src/num/flt2dec/strategy/grisu.rs b/library/core/src/num/flt2dec/strategy/grisu.rs index b9f0d114c6a14..d339dd855cced 100644 --- a/library/core/src/num/flt2dec/strategy/grisu.rs +++ b/library/core/src/num/flt2dec/strategy/grisu.rs @@ -129,6 +129,7 @@ pub fn cached_power(alpha: i16, gamma: i16) -> (i16, Fp) { /// Given `x > 0`, returns `(k, 10^k)` such that `10^k <= x < 10^(k+1)`. #[doc(hidden)] +#[inline] pub fn max_pow10_no_more_than(x: u32) -> (u8, u32) { debug_assert!(x > 0); diff --git a/library/core/src/num/fmt.rs b/library/core/src/num/fmt.rs index ed61197157bf5..956ddb6b38443 100644 --- a/library/core/src/num/fmt.rs +++ b/library/core/src/num/fmt.rs @@ -19,6 +19,7 @@ pub enum Part<'a> { impl<'a> Part<'a> { /// Returns the exact byte length of given part. + #[inline] pub fn len(&self) -> usize { match *self { Part::Zero(nzeroes) => nzeroes, diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 3cbb55af3bc66..4a371762ac02a 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2412,12 +2412,14 @@ macro_rules! int_impl { // Map an $SelfT to an $UnsignedT // ex: i8 [-128; 127] to [0; 255] + #[inline] const fn map(a: $SelfT) -> $UnsignedT { (a as $UnsignedT) ^ U } // Map an $UnsignedT to an $SelfT // ex: u8 [0; 255] to [-128; 127] + #[inline] const fn demap(a: $UnsignedT) -> $SelfT { (a ^ U) as $SelfT } diff --git a/library/core/src/panic/location.rs b/library/core/src/panic/location.rs index 6dcf23dde87c7..2c237b246c90a 100644 --- a/library/core/src/panic/location.rs +++ b/library/core/src/panic/location.rs @@ -187,6 +187,7 @@ impl<'a> Location<'a> { )] impl<'a> Location<'a> { #[doc(hidden)] + #[inline] pub const fn internal_constructor(file: &'a str, line: u32, col: u32) -> Self { Location { file, line, col } } diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs index c77e9675a6ac5..46b9f88065d8f 100644 --- a/library/core/src/panic/panic_info.rs +++ b/library/core/src/panic/panic_info.rs @@ -83,6 +83,7 @@ impl<'a> PanicInfo<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] + #[inline] pub fn payload(&self) -> &(dyn Any + Send) { self.payload } @@ -92,6 +93,7 @@ impl<'a> PanicInfo<'a> { /// returns that message ready to be used for example with [`fmt::write`] #[must_use] #[unstable(feature = "panic_info_message", issue = "66745")] + #[inline] pub fn message(&self) -> Option<&fmt::Arguments<'_>> { self.message } @@ -122,6 +124,7 @@ impl<'a> PanicInfo<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] + #[inline] pub fn location(&self) -> Option<&Location<'_>> { // NOTE: If this is changed to sometimes return None, // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt. @@ -140,6 +143,7 @@ impl<'a> PanicInfo<'a> { /// again. #[must_use] #[unstable(feature = "panic_can_unwind", issue = "92988")] + #[inline] pub fn can_unwind(&self) -> bool { self.can_unwind } diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 5dc53caba0dd3..57ed959aea6b4 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -106,6 +106,7 @@ impl [u8] { #[must_use = "this returns the escaped bytes as an iterator, \ without modifying the original"] #[stable(feature = "inherent_ascii_escape", since = "1.60.0")] + #[inline] pub fn escape_ascii(&self) -> EscapeAscii<'_> { EscapeAscii { inner: self.iter().flat_map(EscapeByte) } } @@ -125,6 +126,7 @@ impl [u8] { /// assert_eq!(b"".trim_ascii_start(), b""); /// ``` #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[inline] pub const fn trim_ascii_start(&self) -> &[u8] { let mut bytes = self; // Note: A pattern matching based approach (instead of indexing) allows @@ -154,6 +156,7 @@ impl [u8] { /// assert_eq!(b"".trim_ascii_end(), b""); /// ``` #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[inline] pub const fn trim_ascii_end(&self) -> &[u8] { let mut bytes = self; // Note: A pattern matching based approach (instead of indexing) allows @@ -184,6 +187,7 @@ impl [u8] { /// assert_eq!(b"".trim_ascii(), b""); /// ``` #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[inline] pub const fn trim_ascii(&self) -> &[u8] { self.trim_ascii_start().trim_ascii_end() } diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index d313e8e012f20..23c2f1bafae09 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -727,6 +727,7 @@ where } /// Convert pair of `ops::Bound`s into `ops::Range` without performing any bounds checking and (in debug) overflow checking +#[inline] pub(crate) fn into_range_unchecked( len: usize, (start, end): (ops::Bound, ops::Bound), diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index a11b5add42ebf..627387ef1ba0b 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -126,6 +126,7 @@ impl fmt::Display for Utf8Error { #[stable(feature = "rust1", since = "1.0.0")] impl Error for Utf8Error { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "invalid utf-8: corrupt contents" } @@ -149,6 +150,7 @@ impl fmt::Display for ParseBoolError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for ParseBoolError { #[allow(deprecated)] + #[inline] fn description(&self) -> &str { "failed to parse bool" } diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 59f873d1268ce..065a34b5ac6d6 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -44,6 +44,7 @@ impl<'a> Utf8Chunk<'a> { /// broken UTF-8 characters. #[must_use] #[unstable(feature = "utf8_chunks", issue = "99543")] + #[inline] pub fn valid(&self) -> &'a str { self.valid } @@ -64,6 +65,7 @@ impl<'a> Utf8Chunk<'a> { /// [`U+FFFD REPLACEMENT CHARACTER`]: crate::char::REPLACEMENT_CHARACTER #[must_use] #[unstable(feature = "utf8_chunks", issue = "99543")] + #[inline] pub fn invalid(&self) -> &'a [u8] { self.invalid } @@ -149,12 +151,14 @@ pub struct Utf8Chunks<'a> { impl<'a> Utf8Chunks<'a> { /// Creates a new iterator to decode the bytes. #[unstable(feature = "utf8_chunks", issue = "99543")] + #[inline] pub fn new(bytes: &'a [u8]) -> Self { Self { source: bytes } } #[doc(hidden)] #[unstable(feature = "str_internals", issue = "none")] + #[inline] pub fn debug(&self) -> Debug<'_> { Debug(self.source) } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 899d572f0e342..df6b71bc5cf4c 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1021,6 +1021,7 @@ impl str { #[must_use = "this returns the encoded string as an iterator, \ without modifying the original"] #[stable(feature = "encode_utf16", since = "1.8.0")] + #[inline] pub fn encode_utf16(&self) -> EncodeUtf16<'_> { EncodeUtf16 { chars: self.chars(), extra: 0 } } @@ -2500,6 +2501,7 @@ impl str { #[must_use = "this returns the escaped string as an iterator, \ without modifying the original"] #[stable(feature = "str_escape", since = "1.34.0")] + #[inline] pub fn escape_default(&self) -> EscapeDefault<'_> { EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) } } @@ -2538,6 +2540,7 @@ impl str { #[must_use = "this returns the escaped string as an iterator, \ without modifying the original"] #[stable(feature = "str_escape", since = "1.34.0")] + #[inline] pub fn escape_unicode(&self) -> EscapeUnicode<'_> { EscapeUnicode { inner: self.chars().flat_map(CharEscapeUnicode) } } diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index cf1fbe2d389d7..6e2f580926e99 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -353,6 +353,7 @@ impl AtomicBool { /// [valid]: crate::ptr#safety #[unstable(feature = "atomic_from_ptr", issue = "108652")] #[rustc_const_unstable(feature = "atomic_from_ptr", issue = "108652")] + #[inline] pub const unsafe fn from_ptr<'a>(ptr: *mut bool) -> &'a AtomicBool { // SAFETY: guaranteed by the caller unsafe { &*ptr.cast() } @@ -2119,6 +2120,7 @@ macro_rules! atomic_int { /// [valid]: crate::ptr#safety #[unstable(feature = "atomic_from_ptr", issue = "108652")] #[rustc_const_unstable(feature = "atomic_from_ptr", issue = "108652")] + #[inline] pub const unsafe fn from_ptr<'a>(ptr: *mut $int_type) -> &'a $atomic_type { // SAFETY: guaranteed by the caller unsafe { &*ptr.cast() } diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index b63fd5c9095fc..2ef318b8b5f5e 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -160,6 +160,7 @@ impl RawWakerVTable { #[rustc_promotable] #[stable(feature = "futures_api", since = "1.36.0")] #[rustc_const_stable(feature = "futures_api", since = "1.36.0")] + #[inline] pub const fn new( clone: unsafe fn(*const ()) -> RawWaker, wake: unsafe fn(*const ()), diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 6ef35d8414be5..6d557c23a3a86 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -1241,6 +1241,7 @@ pub struct TryFromFloatSecsError { } impl TryFromFloatSecsError { + #[inline] const fn description(&self) -> &'static str { match self.kind { TryFromFloatSecsErrorKind::Negative => {