Skip to content

Commit 37c44a4

Browse files
committed
Remove panic optimization
With Rust 1.93 now stable, this brings the new implementation of `format_args!`. Given this, the standalone method is no longer necessary.
1 parent b8b879a commit 37c44a4

4 files changed

Lines changed: 18 additions & 23 deletions

File tree

time/src/duration.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use num_conv::prelude::*;
1515
#[expect(deprecated)]
1616
use crate::Instant;
1717
use crate::convert::*;
18+
use crate::error;
1819
use crate::internal_macros::const_try_opt;
19-
use crate::{error, panic};
2020

2121
#[derive(Debug)]
2222
enum FloatConstructorError {
@@ -587,9 +587,11 @@ impl Duration {
587587
pub const fn seconds_f64(seconds: f64) -> Self {
588588
match Self::try_seconds_f64(seconds) {
589589
Ok(duration) => duration,
590-
Err(FloatConstructorError::Nan) => panic("passed NaN to `time::Duration::seconds_f64`"),
590+
Err(FloatConstructorError::Nan) => {
591+
panic!("passed NaN to `time::Duration::seconds_f64`");
592+
}
591593
Err(FloatConstructorError::NegOverflow | FloatConstructorError::PosOverflow) => {
592-
panic("overflow constructing `time::Duration`")
594+
panic!("overflow constructing `time::Duration`");
593595
}
594596
}
595597
}
@@ -606,9 +608,11 @@ impl Duration {
606608
pub const fn seconds_f32(seconds: f32) -> Self {
607609
match Self::try_seconds_f32(seconds) {
608610
Ok(duration) => duration,
609-
Err(FloatConstructorError::Nan) => panic("passed NaN to `time::Duration::seconds_f32`"),
611+
Err(FloatConstructorError::Nan) => {
612+
panic!("passed NaN to `time::Duration::seconds_f32`");
613+
}
610614
Err(FloatConstructorError::NegOverflow | FloatConstructorError::PosOverflow) => {
611-
panic("overflow constructing `time::Duration`")
615+
panic!("overflow constructing `time::Duration`");
612616
}
613617
}
614618
}
@@ -794,7 +798,7 @@ impl Duration {
794798
let nanoseconds = nanoseconds % Nanosecond::per_t::<i128>(Second);
795799

796800
if seconds > i64::MAX as i128 || seconds < i64::MIN as i128 {
797-
panic("overflow constructing `time::Duration`");
801+
panic!("overflow constructing `time::Duration`");
798802
}
799803

800804
// Safety: `nanoseconds` is guaranteed to be in range because of the modulus above.

time/src/format_description/well_known/iso8601/adt_hack.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use core::num::NonZero;
55
#[cfg(feature = "formatting")]
66
use super::Iso8601;
77
use super::{Config, DateKind, FormattedComponents as FC, OffsetPrecision, TimePrecision};
8-
use crate::panic;
98

109
// This provides a way to include `EncodedConfig` in documentation without displaying the type it is
1110
// aliased to.
@@ -107,23 +106,23 @@ impl Config {
107106
4 => FC::DateTime,
108107
5 => FC::DateTimeOffset,
109108
6 => FC::TimeOffset,
110-
_ => panic("invalid configuration"),
109+
_ => panic!("invalid configuration"),
111110
};
112111
let use_separators = match bytes[1] {
113112
0 => false,
114113
1 => true,
115-
_ => panic("invalid configuration"),
114+
_ => panic!("invalid configuration"),
116115
};
117116
let year_is_six_digits = match bytes[2] {
118117
0 => false,
119118
1 => true,
120-
_ => panic("invalid configuration"),
119+
_ => panic!("invalid configuration"),
121120
};
122121
let date_kind = match bytes[3] {
123122
0 => DateKind::Calendar,
124123
1 => DateKind::Week,
125124
2 => DateKind::Ordinal,
126-
_ => panic("invalid configuration"),
125+
_ => panic!("invalid configuration"),
127126
};
128127
let time_precision = match bytes[4] {
129128
0 => TimePrecision::Hour {
@@ -135,19 +134,19 @@ impl Config {
135134
2 => TimePrecision::Second {
136135
decimal_digits: NonZero::new(bytes[5]),
137136
},
138-
_ => panic("invalid configuration"),
137+
_ => panic!("invalid configuration"),
139138
};
140139
let offset_precision = match bytes[6] {
141140
0 => OffsetPrecision::Hour,
142141
1 => OffsetPrecision::Minute,
143-
_ => panic("invalid configuration"),
142+
_ => panic!("invalid configuration"),
144143
};
145144

146145
// No `for` loops in `const fn`.
147146
let mut idx = 7; // first unused byte
148147
while idx < EncodedConfig::BITS as usize / 8 {
149148
if bytes[idx] != 0 {
150-
panic("invalid configuration");
149+
panic!("invalid configuration");
151150
}
152151
idx += 1;
153152
}

time/src/internal_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ macro_rules! bug {
201201
compile_error!("provide an error message to help fix a possible bug")
202202
};
203203
($descr:literal) => {
204-
$crate::panic(concat!("internal error: ", $descr))
204+
panic!(concat!("internal error: ", $descr))
205205
};
206206
}
207207

time/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,3 @@ pub use crate::weekday::Weekday;
149149

150150
/// An alias for [`std::result::Result`] with a generic error from the time crate.
151151
pub type Result<T> = core::result::Result<T, Error>;
152-
153-
/// This is a separate function to reduce the code size of explicit panics.
154-
#[inline(never)]
155-
#[cold]
156-
#[track_caller]
157-
const fn panic(message: &str) -> ! {
158-
panic!("{}", message)
159-
}

0 commit comments

Comments
 (0)