Skip to content

Commit 888f249

Browse files
author
Jorge Aparicio
committed
librustdoc: use unboxed closures
1 parent 0676c3b commit 888f249

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/librustdoc/html/format.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,14 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
218218
})
219219
}
220220

221-
fn path(w: &mut fmt::Formatter, path: &clean::Path, print_all: bool,
222-
root: |&render::Cache, &[String]| -> Option<String>,
223-
info: |&render::Cache| -> Option<(Vec<String> , ItemType)>)
224-
-> fmt::Result
221+
fn path<F, G>(w: &mut fmt::Formatter,
222+
path: &clean::Path,
223+
print_all: bool,
224+
root: F,
225+
info: G)
226+
-> fmt::Result where
227+
F: FnOnce(&render::Cache, &[String]) -> Option<String>,
228+
G: FnOnce(&render::Cache) -> Option<(Vec<String>, ItemType)>,
225229
{
226230
// The generics will get written to both the title and link
227231
let mut generics = String::new();

src/librustdoc/html/render.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,9 @@ fn shortty(item: &clean::Item) -> ItemType {
646646
/// static HTML tree.
647647
// FIXME (#9639): The closure should deal with &[u8] instead of &str
648648
// FIXME (#9639): This is too conservative, rejecting non-UTF-8 paths
649-
fn clean_srcpath(src_root: &Path, src: &[u8], f: |&str|) {
649+
fn clean_srcpath<F>(src_root: &Path, src: &[u8], mut f: F) where
650+
F: FnMut(&str),
651+
{
650652
let p = Path::new(src);
651653

652654
// make it relative, if possible
@@ -1051,7 +1053,9 @@ impl<'a> Cache {
10511053
impl Context {
10521054
/// Recurse in the directory structure and change the "root path" to make
10531055
/// sure it always points to the top (relatively)
1054-
fn recurse<T>(&mut self, s: String, f: |&mut Context| -> T) -> T {
1056+
fn recurse<T, F>(&mut self, s: String, f: F) -> T where
1057+
F: FnOnce(&mut Context) -> T,
1058+
{
10551059
if s.len() == 0 {
10561060
panic!("Unexpected empty destination: {}", self.current);
10571061
}
@@ -1131,8 +1135,9 @@ impl Context {
11311135
/// all sub-items which need to be rendered.
11321136
///
11331137
/// The rendering driver uses this closure to queue up more work.
1134-
fn item(&mut self, item: clean::Item,
1135-
f: |&mut Context, clean::Item|) -> io::IoResult<()> {
1138+
fn item<F>(&mut self, item: clean::Item, mut f: F) -> io::IoResult<()> where
1139+
F: FnMut(&mut Context, clean::Item),
1140+
{
11361141
fn render(w: io::File, cx: &Context, it: &clean::Item,
11371142
pushname: bool) -> io::IoResult<()> {
11381143
info!("Rendering an item to {}", w.path().display());

0 commit comments

Comments
 (0)