Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a finally impl for extern "Rust" fn() #7056

Merged
merged 2 commits into from
Jun 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn test_package_version() {

// FIXME #7006: Fails on linux for some reason
#[test]
#[ignore(cfg(target_os = "linux"))]
#[ignore]
fn test_package_request_version() {
let temp_pkg_id = PkgId::new("github.com/catamorphism/test_pkg_version#0.3");
let temp = mk_empty_workspace(&LocalPath(Path("test_pkg_version")), &ExactRevision(~"0.3"));
Expand Down
38 changes: 16 additions & 22 deletions src/libstd/unstable/finally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ pub trait Finally<T> {
fn finally(&self, dtor: &fn()) -> T;
}

impl<'self,T> Finally<T> for &'self fn() -> T {
fn finally(&self, dtor: &fn()) -> T {
let _d = Finallyalizer {
dtor: dtor
};

(*self)()
macro_rules! finally_fn {
($fnty:ty) => {
impl<T> Finally<T> for $fnty {
fn finally(&self, dtor: &fn()) -> T {
let _d = Finallyalizer {
dtor: dtor
};
(*self)()
}
}
}
}

impl<T> Finally<T> for ~fn() -> T {
impl<'self,T> Finally<T> for &'self fn() -> T {
fn finally(&self, dtor: &fn()) -> T {
let _d = Finallyalizer {
dtor: dtor
Expand All @@ -51,15 +54,9 @@ impl<T> Finally<T> for ~fn() -> T {
}
}

impl<T> Finally<T> for @fn() -> T {
fn finally(&self, dtor: &fn()) -> T {
let _d = Finallyalizer {
dtor: dtor
};

(*self)()
}
}
finally_fn!(~fn() -> T)
finally_fn!(@fn() -> T)
finally_fn!(extern "Rust" fn() -> T)

struct Finallyalizer<'self> {
dtor: &'self fn()
Expand Down Expand Up @@ -108,10 +105,7 @@ fn test_retval() {

#[test]
fn test_compact() {
// FIXME #4727: Should be able to use a fn item instead
// of a closure for do_some_fallible_work,
// but it's a type error.
let do_some_fallible_work: &fn() = || { };
fn do_some_fallible_work() {}
fn but_always_run_this_function() { }
do_some_fallible_work.finally(
but_always_run_this_function);
Expand All @@ -136,4 +130,4 @@ fn test_managed() {
};
assert_eq!(do managed.finally {}, 10);
assert_eq!(*i, 20);
}
}