Skip to content

Commit

Permalink
Experiment with panic() vs panic!().
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Dec 20, 2021
1 parent e04848e commit 3c0d5ee
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 108 deletions.
9 changes: 6 additions & 3 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,10 @@ macro_rules! writeln {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable(core_panic)]
macro_rules! unreachable {
() => ({
$crate::panic!("internal error: entered unreachable code")
$crate::panicking::panic("internal error: entered unreachable code")
});
($msg:expr $(,)?) => ({
$crate::unreachable!("{}", $msg)
Expand Down Expand Up @@ -674,8 +675,9 @@ macro_rules! unreachable {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable(core_panic)]
macro_rules! unimplemented {
() => ($crate::panic!("not implemented"));
() => ($crate::panicking::panic("not implemented"));
($($arg:tt)+) => ($crate::panic!("not implemented: {}", $crate::format_args!($($arg)+)));
}

Expand Down Expand Up @@ -735,8 +737,9 @@ macro_rules! unimplemented {
/// ```
#[macro_export]
#[stable(feature = "todo_macro", since = "1.40.0")]
#[allow_internal_unstable(core_panic)]
macro_rules! todo {
() => ($crate::panic!("not yet implemented"));
() => ($crate::panicking::panic("not yet implemented"));
($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
}

Expand Down
6 changes: 4 additions & 2 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
#![stable(feature = "rust1", since = "1.0.0")]

use crate::iter::{FromIterator, FusedIterator, TrustedLen};
use crate::panicking::{panic, panic_str};
use crate::pin::Pin;
use crate::{
convert, hint, mem,
Expand Down Expand Up @@ -755,7 +756,7 @@ impl<T> Option<T> {
pub const fn unwrap(self) -> T {
match self {
Some(val) => val,
None => panic!("called `Option::unwrap()` on a `None` value"),
None => panic("called `Option::unwrap()` on a `None` value"),
}
}

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

/////////////////////////////////////////////////////////////////////////////
Expand Down
77 changes: 12 additions & 65 deletions src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,18 @@
let mut _19: *const T; // in scope 0 at $DIR/issue_76432.rs:9:54: 9:68
let mut _20: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
let mut _21: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _23: std::fmt::Arguments; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _24: &[&str]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _25: &[&str; 1]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _26: &[&str; 1]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _27: [&str; 1]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _28: &[std::fmt::ArgumentV1]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _29: &[std::fmt::ArgumentV1; 0]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let _30: &[std::fmt::ArgumentV1; 0]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let _31: [std::fmt::ArgumentV1; 0]; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _32: (); // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _36: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:7:19: 7:29
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _23: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:7:19: 7:29
scope 1 {
debug v => _2; // in scope 1 at $DIR/issue_76432.rs:7:9: 7:10
let _13: &T; // in scope 1 at $DIR/issue_76432.rs:9:10: 9:16
let _14: &T; // in scope 1 at $DIR/issue_76432.rs:9:18: 9:24
let _15: &T; // in scope 1 at $DIR/issue_76432.rs:9:26: 9:32
let _33: (); // in scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _34: &[std::fmt::ArgumentV1; 0]; // in scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
let mut _35: &[&str; 1]; // in scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
scope 2 {
debug v1 => _13; // in scope 2 at $DIR/issue_76432.rs:9:10: 9:16
debug v2 => _14; // in scope 2 at $DIR/issue_76432.rs:9:18: 9:24
debug v3 => _15; // in scope 2 at $DIR/issue_76432.rs:9:26: 9:32
}
scope 3 {
debug _args => _33; // in scope 3 at $SRC_DIR/core/src/panic.rs:LL:COL
}
}

bb0: {
Expand All @@ -68,59 +52,31 @@
StorageDead(_6); // scope 0 at $DIR/issue_76432.rs:7:28: 7:29
_4 = &_5; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
_3 = _4; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
StorageLive(_36); // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
_36 = _3; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
StorageLive(_23); // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
_23 = _3; // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
_2 = move _3 as &[T] (Pointer(Unsize)); // scope 0 at $DIR/issue_76432.rs:7:19: 7:29
StorageDead(_3); // scope 0 at $DIR/issue_76432.rs:7:28: 7:29
StorageDead(_4); // scope 0 at $DIR/issue_76432.rs:7:29: 7:30
StorageLive(_9); // scope 1 at $DIR/issue_76432.rs:8:5: 11:6
_10 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
StorageDead(_36); // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
StorageDead(_23); // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
_11 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
_12 = const true; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
goto -> bb2; // scope 1 at $DIR/issue_76432.rs:9:9: 9:33
}

bb1: {
StorageLive(_22); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageLive(_23); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageLive(_24); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageLive(_25); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageLive(_26); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_35 = const test::<T>::promoted[1]; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// ty::Const
// + ty: &[&str; 1]
// + val: Unevaluated(test, [T], Some(promoted[1]))
StorageLive(_22); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
core::panicking::panic(const "internal error: entered unreachable code"); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
// + 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]) }) }
_26 = _35; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_25 = _26; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_24 = move _25 as &[&str] (Pointer(Unsize)); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageDead(_25); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageLive(_28); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageLive(_29); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageLive(_30); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageLive(_32); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageLive(_33); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
nop; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageDead(_33); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
_34 = const test::<T>::promoted[0]; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
// + literal: Const { ty: fn(&'static str) -> ! {core::panicking::panic}, val: Value(Scalar(<ZST>)) }
// ty::Const
// + ty: &[std::fmt::ArgumentV1; 0]
// + val: Unevaluated(test, [T], Some(promoted[0]))
// + 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 })
// mir::Constant
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
// + 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]) }) }
_30 = _34; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
_29 = _30; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
_28 = move _29 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageDead(_29); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
_23 = Arguments::new_v1(move _24, move _28) -> bb3; // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
// + user_ty: UserType(5)
// + literal: Const { ty: fn(&[&'static str], &[std::fmt::ArgumentV1]) -> std::fmt::Arguments {std::fmt::Arguments::new_v1}, val: Value(Scalar(<ZST>)) }
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
// + 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 }) }
}

bb2: {
Expand Down Expand Up @@ -158,14 +114,5 @@
StorageDead(_2); // scope 0 at $DIR/issue_76432.rs:12:1: 12:2
return; // scope 0 at $DIR/issue_76432.rs:12:2: 12:2
}

bb3: {
StorageDead(_28); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
StorageDead(_24); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
panic_fmt(move _23); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
// + literal: Const { ty: for<'r> fn(std::fmt::Arguments<'r>) -> ! {std::rt::panic_fmt}, val: Value(Scalar(<ZST>)) }
}
}

Loading

0 comments on commit 3c0d5ee

Please sign in to comment.