Skip to content

Commit 3c0d5ee

Browse files
committed
Experiment with panic() vs panic!().
1 parent e04848e commit 3c0d5ee

File tree

10 files changed

+79
-108
lines changed

10 files changed

+79
-108
lines changed

library/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

library/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
/////////////////////////////////////////////////////////////////////////////

src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,18 @@
2121
let mut _19: *const T; // in scope 0 at $DIR/issue_76432.rs:9:54: 9:68
2222
let mut _20: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
2323
let mut _21: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
24-
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
25-
let mut _23: std::fmt::Arguments; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
26-
let mut _24: &[&str]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
27-
let mut _25: &[&str; 1]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
28-
let _26: &[&str; 1]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
29-
let _27: [&str; 1]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
30-
let mut _28: &[std::fmt::ArgumentV1]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
31-
let mut _29: &[std::fmt::ArgumentV1; 0]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
32-
let _30: &[std::fmt::ArgumentV1; 0]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
33-
let _31: [std::fmt::ArgumentV1; 0]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
34-
let mut _32: (); // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
35-
let mut _36: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:7:19: 7:29
24+
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
25+
let mut _23: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:7:19: 7:29
3626
scope 1 {
3727
debug v => _2; // in scope 1 at $DIR/issue_76432.rs:7:9: 7:10
3828
let _13: &T; // in scope 1 at $DIR/issue_76432.rs:9:10: 9:16
3929
let _14: &T; // in scope 1 at $DIR/issue_76432.rs:9:18: 9:24
4030
let _15: &T; // in scope 1 at $DIR/issue_76432.rs:9:26: 9:32
41-
let _33: (); // in scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
42-
let mut _34: &[std::fmt::ArgumentV1; 0]; // in scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
43-
let mut _35: &[&str; 1]; // in scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
4431
scope 2 {
4532
debug v1 => _13; // in scope 2 at $DIR/issue_76432.rs:9:10: 9:16
4633
debug v2 => _14; // in scope 2 at $DIR/issue_76432.rs:9:18: 9:24
4734
debug v3 => _15; // in scope 2 at $DIR/issue_76432.rs:9:26: 9:32
4835
}
49-
scope 3 {
50-
debug _args => _33; // in scope 3 at $SRC_DIR/core/src/panic.rs:LL:COL
51-
}
5236
}
5337

5438
bb0: {
@@ -68,59 +52,31 @@
6852
StorageDead(_6); // scope 0 at $DIR/issue_76432.rs:7:28: 7:29
6953
_4 = &_5; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
7054
_3 = _4; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
71-
StorageLive(_36); // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
72-
_36 = _3; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
55+
StorageLive(_23); // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
56+
_23 = _3; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
7357
_2 = move _3 as &[T] (Pointer(Unsize)); // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
7458
StorageDead(_3); // scope 0 at $DIR/issue_76432.rs:7:28: 7:29
7559
StorageDead(_4); // scope 0 at $DIR/issue_76432.rs:7:29: 7:30
7660
StorageLive(_9); // scope 1 at $DIR/issue_76432.rs:8:5: 11:6
7761
_10 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
78-
StorageDead(_36); // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
62+
StorageDead(_23); // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
7963
_11 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
8064
_12 = const true; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
8165
goto -> bb2; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
8266
}
8367

8468
bb1: {
85-
StorageLive(_22); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
86-
StorageLive(_23); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
87-
StorageLive(_24); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
88-
StorageLive(_25); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
89-
StorageLive(_26); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
90-
_35 = const test::<T>::promoted[1]; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
91-
// ty::Const
92-
// + ty: &[&str; 1]
93-
// + val: Unevaluated(test, [T], Some(promoted[1]))
69+
StorageLive(_22); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
70+
core::panicking::panic(const "internal error: entered unreachable code"); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
9471
// mir::Constant
9572
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
96-
// + literal: Const { ty: &[&str; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ issue_76432[HASH]::test), const_param_did: None }, substs_: Some([T]), promoted: Some(promoted[1]) }) }
97-
_26 = _35; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
98-
_25 = _26; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
99-
_24 = move _25 as &[&str] (Pointer(Unsize)); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
100-
StorageDead(_25); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
101-
StorageLive(_28); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
102-
StorageLive(_29); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
103-
StorageLive(_30); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
104-
StorageLive(_32); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
105-
StorageLive(_33); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
106-
nop; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
107-
StorageDead(_33); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
108-
_34 = const test::<T>::promoted[0]; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
73+
// + literal: Const { ty: fn(&'static str) -> ! {core::panicking::panic}, val: Value(Scalar(<ZST>)) }
10974
// ty::Const
110-
// + ty: &[std::fmt::ArgumentV1; 0]
111-
// + val: Unevaluated(test, [T], Some(promoted[0]))
75+
// + ty: &str
76+
// + val: Value(Slice { data: Allocation { bytes: [105, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 58, 32, 101, 110, 116, 101, 114, 101, 100, 32, 117, 110, 114, 101, 97, 99, 104, 97, 98, 108, 101, 32, 99, 111, 100, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1099511627775], len: Size { raw: 40 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 40 })
11277
// mir::Constant
113-
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
114-
// + literal: Const { ty: &[std::fmt::ArgumentV1; 0], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ issue_76432[HASH]::test), const_param_did: None }, substs_: Some([T]), promoted: Some(promoted[0]) }) }
115-
_30 = _34; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
116-
_29 = _30; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
117-
_28 = move _29 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
118-
StorageDead(_29); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
119-
_23 = Arguments::new_v1(move _24, move _28) -> bb3; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
120-
// mir::Constant
121-
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
122-
// + user_ty: UserType(5)
123-
// + literal: Const { ty: fn(&[&'static str], &[std::fmt::ArgumentV1]) -> std::fmt::Arguments {std::fmt::Arguments::new_v1}, val: Value(Scalar(<ZST>)) }
78+
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
79+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [105, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 58, 32, 101, 110, 116, 101, 114, 101, 100, 32, 117, 110, 114, 101, 97, 99, 104, 97, 98, 108, 101, 32, 99, 111, 100, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1099511627775], len: Size { raw: 40 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 40 }) }
12480
}
12581

12682
bb2: {
@@ -158,14 +114,5 @@
158114
StorageDead(_2); // scope 0 at $DIR/issue_76432.rs:12:1: 12:2
159115
return; // scope 0 at $DIR/issue_76432.rs:12:2: 12:2
160116
}
161-
162-
bb3: {
163-
StorageDead(_28); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
164-
StorageDead(_24); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
165-
panic_fmt(move _23); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
166-
// mir::Constant
167-
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
168-
// + literal: Const { ty: for<'r> fn(std::fmt::Arguments<'r>) -> ! {std::rt::panic_fmt}, val: Value(Scalar(<ZST>)) }
169-
}
170117
}
171118

0 commit comments

Comments
 (0)