about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2018-04-30 10:55:24 +0200
committerJorge Aparicio <jorge@japaric.io>2018-06-03 13:46:19 +0200
commite44ad61a2d8e3bac1d2cbf2467a7202250b8a77e (patch)
treee9b2eede0e5f2703640bb76f3e7f1b1c8e23fbd2 /src/libcore
parent3575be60eab140e69e5a75fe5c3b4119c2a17179 (diff)
downloadrust-e44ad61a2d8e3bac1d2cbf2467a7202250b8a77e.tar.gz
rust-e44ad61a2d8e3bac1d2cbf2467a7202250b8a77e.zip
implement #[panic_implementation]
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/macros.rs22
-rw-r--r--src/libcore/panic.rs6
-rw-r--r--src/libcore/panicking.rs40
3 files changed, 66 insertions, 2 deletions
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index c830c22ee5f..f98626d939d 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 /// Entry point of thread panic, for details, see std::macros
+#[cfg(stage0)]
 #[macro_export]
 #[allow_internal_unstable]
 #[stable(feature = "core", since = "1.6.0")]
@@ -28,6 +29,27 @@ macro_rules! panic {
     });
 }
 
+/// Entry point of thread panic, for details, see std::macros
+#[cfg(not(stage0))]
+#[macro_export]
+#[allow_internal_unstable]
+#[stable(feature = "core", since = "1.6.0")]
+macro_rules! panic {
+    () => (
+        panic!("explicit panic")
+    );
+    ($msg:expr) => ({
+        $crate::panicking::panic_payload($msg, &(file!(), line!(), __rust_unstable_column!()))
+    });
+    ($msg:expr,) => (
+        panic!($msg)
+    );
+    ($fmt:expr, $($arg:tt)+) => ({
+        $crate::panicking::panic_fmt(format_args!($fmt, $($arg)*),
+                                     &(file!(), line!(), __rust_unstable_column!()))
+    });
+}
+
 /// Asserts that two expressions are equal to each other (using [`PartialEq`]).
 ///
 /// On panic, this macro will print the values of the expressions with their
diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs
index 27ec4aaac75..37ae05309af 100644
--- a/src/libcore/panic.rs
+++ b/src/libcore/panic.rs
@@ -35,6 +35,7 @@ use fmt;
 ///
 /// panic!("Normal panic");
 /// ```
+#[cfg_attr(not(stage0), lang = "panic_info")]
 #[stable(feature = "panic_hooks", since = "1.10.0")]
 #[derive(Debug)]
 pub struct PanicInfo<'a> {
@@ -53,7 +54,8 @@ impl<'a> PanicInfo<'a> {
     pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>,
                                 location: Location<'a>)
                                 -> Self {
-        PanicInfo { payload: &(), location, message }
+        struct NoPayload;
+        PanicInfo { payload: &NoPayload, location, message }
     }
 
     #[doc(hidden)]
@@ -121,7 +123,7 @@ impl<'a> PanicInfo<'a> {
     #[stable(feature = "panic_hooks", since = "1.10.0")]
     pub fn location(&self) -> Option<&Location> {
         // NOTE: If this is changed to sometimes return None,
-        // deal with that case in std::panicking::default_hook.
+        // deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt.
         Some(&self.location)
     }
 }
diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs
index 6b3dc75af46..1470a01e0e6 100644
--- a/src/libcore/panicking.rs
+++ b/src/libcore/panicking.rs
@@ -36,7 +36,33 @@
                       and related macros",
             issue = "0")]
 
+#[cfg(not(stage0))]
+use any::Any;
 use fmt;
+#[cfg(not(stage0))]
+use panic::{Location, PanicInfo};
+
+#[cfg(not(stage0))]
+#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
+extern "C" {
+    #[lang = "panic_impl"]
+    fn panic_impl(pi: &PanicInfo) -> !;
+}
+
+#[cfg(not(stage0))]
+#[cold] #[inline(never)]
+pub fn panic_payload<M>(msg: M, file_line_col: &(&'static str, u32, u32)) -> !
+where
+    M: Any + Send,
+{
+    let (file, line, col) = *file_line_col;
+    let mut pi = PanicInfo::internal_constructor(
+        None,
+        Location::internal_constructor(file, line, col),
+    );
+    pi.set_payload(&msg);
+    unsafe { panic_impl(&pi) }
+}
 
 #[cold] #[inline(never)] // this is the slow path, always
 #[lang = "panic"]
@@ -59,6 +85,7 @@ fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
                            len, index), file_line_col)
 }
 
+#[cfg(stage0)]
 #[cold] #[inline(never)]
 pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
     #[allow(improper_ctypes)]
@@ -70,3 +97,16 @@ pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32))
     let (file, line, col) = *file_line_col;
     unsafe { panic_impl(fmt, file, line, col) }
 }
+
+#[cfg(not(stage0))]
+#[cold] #[inline(never)]
+pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
+    struct NoPayload;
+
+    let (file, line, col) = *file_line_col;
+    let pi = PanicInfo::internal_constructor(
+        Some(&fmt),
+        Location::internal_constructor(file, line, col),
+    );
+    unsafe { panic_impl(&pi) }
+}