about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-30 18:31:26 -0700
committerbors <bors@rust-lang.org>2013-10-30 18:31:26 -0700
commitf73a48e9fd6c214976888d8583fb87de55dd05d8 (patch)
tree2b831b569632c393f36c3fccfc20ca8ba4f87b0f /src/libsyntax
parent6789a77fa02b5f7c3f9ca0261a5387a951d23caf (diff)
parent54f4dcd76aafe33c553f6b58fe3e808f055465e1 (diff)
downloadrust-f73a48e9fd6c214976888d8583fb87de55dd05d8.tar.gz
rust-f73a48e9fd6c214976888d8583fb87de55dd05d8.zip
auto merge of #10120 : Kimundi/rust/remove_sys, r=alexcrichton
- `begin_unwind` and `fail!` is now generic over any `T: Any + Send`.
- Every value you fail with gets boxed as an `~Any`.
- Because of implementation issues, `&'static str` and `~str` are still
  handled specially behind the scenes.
- Changed the big macro source string in libsyntax to a raw string
  literal, and enabled doc comments there.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/build.rs6
-rw-r--r--src/libsyntax/ext/expand.rs104
2 files changed, 51 insertions, 59 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 273ce180a5f..76d9f755d3c 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -604,9 +604,9 @@ impl AstBuilder for @ExtCtxt {
             span,
             ~[
                 self.ident_of("std"),
-                self.ident_of("sys"),
-                self.ident_of("FailWithCause"),
-                self.ident_of("fail_with"),
+                self.ident_of("rt"),
+                self.ident_of("task"),
+                self.ident_of("begin_unwind"),
             ],
             ~[
                 self.expr_str(span, msg),
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 575f8bc6278..052b177d4d8 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -763,8 +763,7 @@ pub fn new_span(cx: @ExtCtxt, sp: Span) -> Span {
 // syntax elements.
 
 pub fn std_macros() -> @str {
-    return
-@"mod __std_macros {
+@r#"mod __std_macros {
     #[macro_escape];
     #[doc(hidden)];
 
@@ -789,31 +788,30 @@ pub fn std_macros() -> @str {
 
     macro_rules! fail(
         () => (
-            fail!(\"explicit failure\")
+            fail!("explicit failure")
         );
-        ($fmt:expr) => (
-            ::std::sys::FailWithCause::fail_with($fmt, file!(), line!())
+        ($msg:expr) => (
+            ::std::rt::task::begin_unwind($msg, file!(), line!())
         );
         ($fmt:expr, $($arg:tt)*) => (
-            ::std::sys::FailWithCause::fail_with(format!($fmt, $($arg)*), file!(), line!())
+            ::std::rt::task::begin_unwind(format!($fmt, $($arg)*), file!(), line!())
         )
     )
 
     macro_rules! assert(
         ($cond:expr) => {
             if !$cond {
-                ::std::sys::FailWithCause::fail_with(
-                    \"assertion failed: \" + stringify!($cond), file!(), line!())
+                fail!("assertion failed: {:s}", stringify!($cond))
             }
         };
         ($cond:expr, $msg:expr) => {
             if !$cond {
-                ::std::sys::FailWithCause::fail_with($msg, file!(), line!())
+                fail!($msg)
             }
         };
         ($cond:expr, $( $arg:expr ),+) => {
             if !$cond {
-                ::std::sys::FailWithCause::fail_with(format!( $($arg),+ ), file!(), line!())
+                fail!( $($arg),+ )
             }
         }
     )
@@ -826,9 +824,8 @@ pub fn std_macros() -> @str {
                 // check both directions of equality....
                 if !((*given_val == *expected_val) &&
                      (*expected_val == *given_val)) {
-                    fail!(\"assertion failed: `(left == right) && (right == \
-                             left)` (left: `{:?}`, right: `{:?}`)\",
-                           *given_val, *expected_val);
+                    fail!("assertion failed: `(left == right) && (right == left)` \
+                           (left: `{:?}`, right: `{:?}`)", *given_val, *expected_val)
                 }
             }
         )
@@ -846,7 +843,7 @@ pub fn std_macros() -> @str {
                     given_val.approx_eq(&expected_val) &&
                     expected_val.approx_eq(&given_val)
                 ) {
-                    fail!(\"left: {:?} does not approximately equal right: {:?}\",
+                    fail!("left: {:?} does not approximately equal right: {:?}",
                            given_val, expected_val);
                 }
             }
@@ -863,42 +860,37 @@ pub fn std_macros() -> @str {
                     given_val.approx_eq_eps(&expected_val, &epsilon_val) &&
                     expected_val.approx_eq_eps(&given_val, &epsilon_val)
                 ) {
-                    fail!(\"left: {:?} does not approximately equal right: \
-                             {:?} with epsilon: {:?}\",
+                    fail!("left: {:?} does not approximately equal right: \
+                             {:?} with epsilon: {:?}",
                           given_val, expected_val, epsilon_val);
                 }
             }
         )
     )
 
-    // FIXME(#6266): change the /* to /** when attributes are supported on macros
-    // (Though even then—is it going to work according to the clear intent here?)
-    /*
-    A utility macro for indicating unreachable code. It will fail if
-    executed. This is occasionally useful to put after loops that never
-    terminate normally, but instead directly return from a function.
-
-    # Example
-
-    ```rust
-    fn choose_weighted_item(v: &[Item]) -> Item {
-        assert!(!v.is_empty());
-        let mut so_far = 0u;
-        for v.each |item| {
-            so_far += item.weight;
-            if so_far > 100 {
-                return item;
-            }
-        }
-        // The above loop always returns, so we must hint to the
-        // type checker that it isn't possible to get down here
-        unreachable!();
-    }
-    ```
-
-    */
+    /// A utility macro for indicating unreachable code. It will fail if
+    /// executed. This is occasionally useful to put after loops that never
+    /// terminate normally, but instead directly return from a function.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// fn choose_weighted_item(v: &[Item]) -> Item {
+    ///     assert!(!v.is_empty());
+    ///     let mut so_far = 0u;
+    ///     for item in v.iter() {
+    ///         so_far += item.weight;
+    ///         if so_far > 100 {
+    ///             return item;
+    ///         }
+    ///     }
+    ///     // The above loop always returns, so we must hint to the
+    ///     // type checker that it isn't possible to get down here
+    ///     unreachable!();
+    /// }
+    /// ```
     macro_rules! unreachable (() => (
-        fail!(\"internal error: entered unreachable code\");
+        fail!("internal error: entered unreachable code");
     ))
 
     macro_rules! condition (
@@ -968,18 +960,18 @@ pub fn std_macros() -> @str {
         )
     )
 
-    // externfn! declares a wrapper for an external function.
-    // It is intended to be used like:
-    //
-    // externfn!(#[nolink]
-    //           fn memcmp(cx: *u8, ct: *u8, n: u32) -> u32)
-    //
-    // Due to limitations in the macro parser, this pattern must be
-    // implemented with 4 distinct patterns (with attrs / without
-    // attrs CROSS with args / without ARGS).
-    //
-    // Also, this macro grammar allows for any number of return types
-    // because I couldn't figure out the syntax to specify at most one.
+    /// externfn! declares a wrapper for an external function.
+    /// It is intended to be used like:
+    ///
+    /// externfn!(#[nolink]
+    ///           fn memcmp(cx: *u8, ct: *u8, n: u32) -> u32)
+    ///
+    /// Due to limitations in the macro parser, this pattern must be
+    /// implemented with 4 distinct patterns (with attrs / without
+    /// attrs CROSS with args / without ARGS).
+    ///
+    /// Also, this macro grammar allows for any number of return types
+    /// because I couldn't figure out the syntax to specify at most one.
     macro_rules! externfn(
         (fn $name:ident () $(-> $ret_ty:ty),*) => (
             pub unsafe fn $name() $(-> $ret_ty),* {
@@ -1045,7 +1037,7 @@ pub fn std_macros() -> @str {
         )
     )
 
-}";
+}"#
 }
 
 struct Injector {