about summary refs log tree commit diff
path: root/example
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-04-25 19:07:25 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-04-25 19:07:53 +0200
commit7031c96fb3dc829586676d55e4d451f2c8de88bd (patch)
tree404178259b8c91cb72553b2c69af96d13eda11a2 /example
parent7dbbfe668fa78f83d72bae264cfd712ff7a900d1 (diff)
downloadrust-7031c96fb3dc829586676d55e4d451f2c8de88bd.tar.gz
rust-7031c96fb3dc829586676d55e4d451f2c8de88bd.zip
Call panic lang item on failed TerminatorKind::Assert
Fixes #164
Diffstat (limited to 'example')
-rw-r--r--example/arbitrary_self_types_pointers_and_wrappers.rs2
-rw-r--r--example/mini_core.rs16
-rw-r--r--example/mini_core_hello_world.rs4
3 files changed, 16 insertions, 6 deletions
diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs
index 10934cebcf1..0b0039a1370 100644
--- a/example/arbitrary_self_types_pointers_and_wrappers.rs
+++ b/example/arbitrary_self_types_pointers_and_wrappers.rs
@@ -13,7 +13,7 @@ use mini_core::*;
 macro_rules! assert_eq {
     ($l:expr, $r: expr) => {
         if $l != $r {
-            panic(&(stringify!($l != $r), file!(), line!(), 0));
+            panic(stringify!($l != $r));
         }
     }
 }
diff --git a/example/mini_core.rs b/example/mini_core.rs
index 0c95ac6772a..60085d35ae1 100644
--- a/example/mini_core.rs
+++ b/example/mini_core.rs
@@ -1,7 +1,7 @@
 #![feature(
     no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
     untagged_unions, decl_macro, rustc_attrs, transparent_unions, optin_builtin_traits,
-    thread_local,
+    thread_local, track_caller
 )]
 #![no_core]
 #![allow(dead_code)]
@@ -394,9 +394,19 @@ pub trait FnMut<Args>: FnOnce<Args> {
 }
 
 #[lang = "panic"]
-pub fn panic(&(_msg, _file, _line, _col): &(&'static str, &'static str, u32, u32)) -> ! {
+#[track_caller]
+pub fn panic(msg: &str) -> ! {
     unsafe {
-        libc::puts("Panicking\0" as *const str as *const u8);
+        libc::puts("Panicking\n\0" as *const str as *const u8);
+        intrinsics::abort();
+    }
+}
+
+#[lang = "panic_bounds_check"]
+#[track_caller]
+fn panic_bounds_check(index: usize, len: usize) -> ! {
+    unsafe {
+        libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
         intrinsics::abort();
     }
 }
diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs
index 1a7534849e9..93eda4be31a 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -97,7 +97,7 @@ static NUM_REF: &'static u8 = unsafe { &NUM };
 macro_rules! assert {
     ($e:expr) => {
         if !$e {
-            panic(&(stringify!(! $e), file!(), line!(), 0));
+            panic(stringify!(! $e));
         }
     };
 }
@@ -105,7 +105,7 @@ macro_rules! assert {
 macro_rules! assert_eq {
     ($l:expr, $r: expr) => {
         if $l != $r {
-            panic(&(stringify!($l != $r), file!(), line!(), 0));
+            panic(stringify!($l != $r));
         }
     }
 }