Skip to content

Commit 28bdf89

Browse files
committed
rustdoc: Use DocVisitor for sources collection
1 parent 5a9bbba commit 28bdf89

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/librustdoc/html/sources.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::clean;
22
use crate::docfs::PathError;
33
use crate::error::Error;
4-
use crate::fold::DocFolder;
54
use crate::html::format::Buffer;
65
use crate::html::highlight;
76
use crate::html::layout;
87
use crate::html::render::{Context, BASIC_KEYWORDS};
8+
use crate::visit::DocVisitor;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_hir::def_id::LOCAL_CRATE;
1111
use rustc_middle::ty::TyCtxt;
@@ -18,10 +18,13 @@ use std::path::{Component, Path, PathBuf};
1818

1919
crate fn render(cx: &mut Context<'_>, krate: clean::Crate) -> Result<clean::Crate, Error> {
2020
info!("emitting source files");
21+
2122
let dst = cx.dst.join("src").join(&*krate.name(cx.tcx()).as_str());
2223
cx.shared.ensure_dir(&dst)?;
23-
let mut folder = SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default() };
24-
Ok(folder.fold_crate(krate))
24+
25+
let mut collector = SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default() };
26+
collector.visit_crate(&krate);
27+
Ok(krate)
2528
}
2629

2730
crate fn collect_local_sources<'tcx>(
@@ -30,8 +33,7 @@ crate fn collect_local_sources<'tcx>(
3033
krate: clean::Crate,
3134
) -> (clean::Crate, FxHashMap<PathBuf, String>) {
3235
let mut lsc = LocalSourcesCollector { tcx, local_sources: FxHashMap::default(), src_root };
33-
34-
let krate = lsc.fold_crate(krate);
36+
lsc.visit_crate(&krate);
3537
(krate, lsc.local_sources)
3638
}
3739

@@ -79,13 +81,13 @@ impl LocalSourcesCollector<'_, '_> {
7981
}
8082
}
8183

82-
impl DocFolder for LocalSourcesCollector<'_, '_> {
83-
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
84-
self.add_local_source(&item);
84+
impl DocVisitor for LocalSourcesCollector<'_, '_> {
85+
fn visit_item(&mut self, item: &clean::Item) {
86+
self.add_local_source(item);
8587

8688
// FIXME: if `include_sources` isn't set and DocFolder didn't require consuming the crate by value,
8789
// we could return None here without having to walk the rest of the crate.
88-
Some(self.fold_item_recur(item))
90+
self.visit_item_recur(item)
8991
}
9092
}
9193

@@ -98,8 +100,8 @@ struct SourceCollector<'a, 'tcx> {
98100
emitted_local_sources: FxHashSet<PathBuf>,
99101
}
100102

101-
impl DocFolder for SourceCollector<'_, '_> {
102-
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
103+
impl DocVisitor for SourceCollector<'_, '_> {
104+
fn visit_item(&mut self, item: &clean::Item) {
103105
let tcx = self.cx.tcx();
104106
let span = item.span(tcx);
105107
let sess = tcx.sess;
@@ -134,7 +136,7 @@ impl DocFolder for SourceCollector<'_, '_> {
134136
}
135137
// FIXME: if `include_sources` isn't set and DocFolder didn't require consuming the crate by value,
136138
// we could return None here without having to walk the rest of the crate.
137-
Some(self.fold_item_recur(item))
139+
self.visit_item_recur(item)
138140
}
139141
}
140142

0 commit comments

Comments
 (0)