Skip to content

Commit e46620a

Browse files
committed
std: Deprecate finally module
No in-tree users. Ugly interface. Closes #14332.
1 parent 3a44a19 commit e46620a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/libcore/finally.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! # }
3333
//! ```
3434
35-
#![unstable]
35+
#![deprecated = "this was an unsightly interface. just implement Drop"]
3636

3737
use ops::{Drop, FnMut, FnOnce};
3838

src/test/run-pass/backtrace.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,47 @@
1212
// ignore-windows FIXME #13259
1313

1414
#![feature(unboxed_closures)]
15+
#![feature(unsafe_destructor)]
1516

1617
use std::os;
1718
use std::io::process::Command;
18-
use std::finally::Finally;
1919
use std::str;
20+
use std::ops::{Drop, FnMut, FnOnce};
21+
22+
pub trait Finally<T> {
23+
fn finally<F>(&mut self, dtor: F) -> T where F: FnMut();
24+
}
25+
26+
impl<T, F> Finally<T> for F where F: FnMut() -> T {
27+
fn finally<G>(&mut self, mut dtor: G) -> T where G: FnMut() {
28+
try_finally(&mut (), self, |_, f| (*f)(), |_| dtor())
29+
}
30+
}
31+
32+
pub fn try_finally<T, U, R, F, G>(mutate: &mut T, drop: U, try_fn: F, finally_fn: G) -> R where
33+
F: FnOnce(&mut T, U) -> R,
34+
G: FnMut(&mut T),
35+
{
36+
let f = Finallyalizer {
37+
mutate: mutate,
38+
dtor: finally_fn,
39+
};
40+
try_fn(&mut *f.mutate, drop)
41+
}
42+
43+
struct Finallyalizer<'a, A:'a, F> where F: FnMut(&mut A) {
44+
mutate: &'a mut A,
45+
dtor: F,
46+
}
47+
48+
#[unsafe_destructor]
49+
impl<'a, A, F> Drop for Finallyalizer<'a, A, F> where F: FnMut(&mut A) {
50+
#[inline]
51+
fn drop(&mut self) {
52+
(self.dtor)(self.mutate);
53+
}
54+
}
55+
2056

2157
#[inline(never)]
2258
fn foo() {

0 commit comments

Comments
 (0)