diff options
Diffstat (limited to 'src/libstd/sys.rs')
| -rw-r--r-- | src/libstd/sys.rs | 89 |
1 files changed, 5 insertions, 84 deletions
diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index b35b25aeb6f..4216f91b602 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -10,99 +10,20 @@ //! Misc low level stuff +// NOTE: Remove this module after an snapshot + #[allow(missing_doc)]; use any::Any; use kinds::Send; -use rt::task::{UnwindReasonStr, UnwindReasonAny}; use rt::task; -use send_str::{SendStr, IntoSendStr}; -/// Trait for initiating task failure with a sendable cause. pub trait FailWithCause { - /// Fail the current task with `cause`. fn fail_with(cause: Self, file: &'static str, line: uint) -> !; } -impl FailWithCause for ~str { - fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! { - task::begin_unwind_reason(UnwindReasonStr(cause.into_send_str()), file, line) - } -} - -impl FailWithCause for &'static str { - fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! { - task::begin_unwind_reason(UnwindReasonStr(cause.into_send_str()), file, line) - } -} - -impl FailWithCause for SendStr { - fn fail_with(cause: SendStr, file: &'static str, line: uint) -> ! { - task::begin_unwind_reason(UnwindReasonStr(cause), file, line) - } -} - -impl FailWithCause for ~Any { - fn fail_with(cause: ~Any, file: &'static str, line: uint) -> ! { - task::begin_unwind_reason(UnwindReasonAny(cause), file, line) - } -} - -impl<T: Any + Send + 'static> FailWithCause for ~T { - fn fail_with(cause: ~T, file: &'static str, line: uint) -> ! { - task::begin_unwind_reason(UnwindReasonAny(cause as ~Any), file, line) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use any::Any; - use cast; - use send_str::IntoSendStr; - - #[test] - fn synthesize_closure() { - use unstable::raw::Closure; - unsafe { - let x = 10; - let f: &fn(int) -> int = |y| x + y; - - assert_eq!(f(20), 30); - - let original_closure: Closure = cast::transmute(f); - - let actual_function_pointer = original_closure.code; - let environment = original_closure.env; - - let new_closure = Closure { - code: actual_function_pointer, - env: environment - }; - - let new_f: &fn(int) -> int = cast::transmute(new_closure); - assert_eq!(new_f(20), 30); - } +impl<T: Any + Send> FailWithCause for T { + fn fail_with(msg: T, file: &'static str, line: uint) -> ! { + task::begin_unwind(msg, file, line) } - - #[test] - #[should_fail] - fn fail_static() { FailWithCause::fail_with("cause", file!(), line!()) } - - #[test] - #[should_fail] - fn fail_owned() { FailWithCause::fail_with(~"cause", file!(), line!()) } - - #[test] - #[should_fail] - fn fail_send() { FailWithCause::fail_with("cause".into_send_str(), file!(), line!()) } - - #[test] - #[should_fail] - fn fail_any() { FailWithCause::fail_with(~612_u16 as ~Any, file!(), line!()) } - - #[test] - #[should_fail] - fn fail_any_wrap() { FailWithCause::fail_with(~413_u16, file!(), line!()) } } |
