Allow fail messages to be caught, and introduce the Any trait
Some code cleanup, sorting of import blocks Removed std::unstable::UnsafeArc's use of Either Added run-fail tests for the new FailWithCause impls Changed future_result and try to return Result<(), ~Any>. - Internally, there is an enum of possible fail messages passend around. - In case of linked failure or a string message, the ~Any gets lazyly allocated in future_results recv method. - For that, future result now returns a wrapper around a Port. - Moved and renamed task::TaskResult into rt::task::UnwindResult and made it an internal enum. - Introduced a replacement typedef `type TaskResult = Result<(), ~Any>`.
This commit is contained in:
parent
cb5b21eba7
commit
fa8e71a825
24 changed files with 913 additions and 215 deletions
|
|
@ -60,7 +60,7 @@ fn spawn_supervised_blocking(myname: &str, f: ~fn()) {
|
|||
builder.spawn(f);
|
||||
error!("{} group waiting", myname);
|
||||
let x = res.recv();
|
||||
assert_eq!(x, task::Success);
|
||||
assert!(x.is_ok());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
@ -78,7 +78,7 @@ fn main() {
|
|||
// Main group #0 waits for unsupervised group #1.
|
||||
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
|
||||
// Middle group #2 creates grandchild_group #3, waits for it to be ready, exits.
|
||||
let x: result::Result<(),()> = do task::try { // unlinked
|
||||
let x: result::Result<(), ~Any> = do task::try { // unlinked
|
||||
do spawn_supervised_blocking("grandparent") {
|
||||
do spawn_supervised_blocking("middle") {
|
||||
grandchild_group(num_tasks);
|
||||
|
|
|
|||
15
src/test/run-fail/fail-macro-any-wrapped.rs
Normal file
15
src/test/run-fail/fail-macro-any-wrapped.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:failed at '~Any'
|
||||
|
||||
fn main() {
|
||||
fail!(~612_i64);
|
||||
}
|
||||
15
src/test/run-fail/fail-macro-any.rs
Normal file
15
src/test/run-fail/fail-macro-any.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:failed at '~Any'
|
||||
|
||||
fn main() {
|
||||
fail!(~413 as ~Any);
|
||||
}
|
||||
15
src/test/run-fail/fail-macro-send_str.rs
Normal file
15
src/test/run-fail/fail-macro-send_str.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:failed at 'test-fail-send-str'
|
||||
|
||||
fn main() {
|
||||
fail!("test-fail-send-str".into_send_str());
|
||||
}
|
||||
|
|
@ -24,5 +24,7 @@ pub fn main() {
|
|||
let x = do task::try {
|
||||
let _b = Foo;
|
||||
};
|
||||
assert_eq!(x, Err(()));
|
||||
|
||||
let s = x.unwrap_err().move::<SendStr>().unwrap();
|
||||
assert_eq!(s.as_slice(), "This failure should happen.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue