1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::DefId;
use crate::{
clean::{self, Import, ImportSource, Item},
fold::DocFolder,
};
pub(crate) fn get_imports(krate: clean::Crate) -> (clean::Crate, FxHashSet<DefId>) {
let mut finder = ImportFinder { imported: FxHashSet::default() };
let krate = finder.fold_crate(krate);
(krate, finder.imported)
}
struct ImportFinder {
imported: FxHashSet<DefId>,
}
impl DocFolder for ImportFinder {
fn fold_item(&mut self, i: Item) -> Option<Item> {
match *i.kind {
clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => {
self.imported.insert(did);
Some(i)
}
_ => Some(self.fold_item_recur(i)),
}
}
}