Skip to content

Commit c1c4913

Browse files
committed
Use panic() instead of panic!() in some places in core.
1 parent dbc2991 commit c1c4913

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
#![feature(const_type_id)]
142142
#![feature(const_type_name)]
143143
#![feature(const_default_impls)]
144+
#![feature(core_panic)]
144145
#![feature(duration_consts_float)]
145146
#![feature(maybe_uninit_uninit_array)]
146147
#![feature(ptr_metadata)]

core/src/macros/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,10 @@ macro_rules! writeln {
589589
/// ```
590590
#[macro_export]
591591
#[stable(feature = "rust1", since = "1.0.0")]
592+
#[allow_internal_unstable(core_panic)]
592593
macro_rules! unreachable {
593594
() => ({
594-
$crate::panic!("internal error: entered unreachable code")
595+
$crate::panicking::panic("internal error: entered unreachable code")
595596
});
596597
($msg:expr $(,)?) => ({
597598
$crate::unreachable!("{}", $msg)
@@ -674,8 +675,9 @@ macro_rules! unreachable {
674675
/// ```
675676
#[macro_export]
676677
#[stable(feature = "rust1", since = "1.0.0")]
678+
#[allow_internal_unstable(core_panic)]
677679
macro_rules! unimplemented {
678-
() => ($crate::panic!("not implemented"));
680+
() => ($crate::panicking::panic("not implemented"));
679681
($($arg:tt)+) => ($crate::panic!("not implemented: {}", $crate::format_args!($($arg)+)));
680682
}
681683

@@ -735,8 +737,9 @@ macro_rules! unimplemented {
735737
/// ```
736738
#[macro_export]
737739
#[stable(feature = "todo_macro", since = "1.40.0")]
740+
#[allow_internal_unstable(core_panic)]
738741
macro_rules! todo {
739-
() => ($crate::panic!("not yet implemented"));
742+
() => ($crate::panicking::panic("not yet implemented"));
740743
($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
741744
}
742745

core/src/option.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@
501501
#![stable(feature = "rust1", since = "1.0.0")]
502502

503503
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
504+
use crate::panicking::{panic, panic_str};
504505
use crate::pin::Pin;
505506
use crate::{
506507
convert, hint, mem,
@@ -755,7 +756,7 @@ impl<T> Option<T> {
755756
pub const fn unwrap(self) -> T {
756757
match self {
757758
Some(val) => val,
758-
None => panic!("called `Option::unwrap()` on a `None` value"),
759+
None => panic("called `Option::unwrap()` on a `None` value"),
759760
}
760761
}
761762

@@ -1815,8 +1816,9 @@ impl<T, E> Option<Result<T, E>> {
18151816
#[cfg_attr(feature = "panic_immediate_abort", inline)]
18161817
#[cold]
18171818
#[track_caller]
1819+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
18181820
const fn expect_failed(msg: &str) -> ! {
1819-
panic!("{}", msg)
1821+
panic_str(msg)
18201822
}
18211823

18221824
/////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)