Skip to content

Commit ad9933e

Browse files
committed
[extremely broken] try to get rid of doctree
this compiles but does not run
1 parent 8d2d001 commit ad9933e

File tree

2 files changed

+82
-24
lines changed

2 files changed

+82
-24
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_span::{self, ExpnKind, Pos};
2929
use rustc_typeck::hir_ty_to_ty;
3030

3131
use std::collections::hash_map::Entry;
32+
use std::collections::BTreeMap;
3233
use std::default::Default;
3334
use std::hash::Hash;
3435
use std::rc::Rc;
@@ -60,6 +61,12 @@ impl<T: Clean<U>, U> Clean<Vec<U>> for [T] {
6061
}
6162
}
6263

64+
impl<K, V: Clean<U>, U> Clean<Vec<U>> for BTreeMap<K, V> {
65+
fn clean(&self, cx: &DocContext<'_>) -> Vec<U> {
66+
self.values().map(|x| x.clean(cx)).collect()
67+
}
68+
}
69+
6370
impl<T: Clean<U>, U, V: Idx> Clean<IndexVec<V, U>> for IndexVec<V, T> {
6471
fn clean(&self, cx: &DocContext<'_>) -> IndexVec<V, U> {
6572
self.iter().map(|x| x.clean(cx)).collect()
@@ -221,6 +228,72 @@ impl Clean<ExternalCrate> for CrateNum {
221228
}
222229
}
223230

231+
impl Clean<Item> for hir::Item<'_> {
232+
fn clean(&self, _cx: &DocContext<'_>) -> Item {
233+
unimplemented!()
234+
}
235+
}
236+
237+
impl Clean<Item> for hir::Crate<'_> {
238+
fn clean(&self, cx: &DocContext<'_>) -> Item {
239+
// TODO: use tcx.crate_name instead
240+
let name = None;
241+
let attrs = self.item.attrs.clean(cx);
242+
243+
// Get _all_ the items!
244+
let mut items = self.items.clean(cx);
245+
items.extend(self.exported_macros.clean(cx));
246+
items.extend(self.trait_items.clean(cx));
247+
items.extend(self.impl_items.clean(cx));
248+
// NOTE: bodies intentionally skipped
249+
250+
items.extend(self.trait_impls.iter().flat_map(|(_trait, impls)| {
251+
impls.into_iter().map(|&impl_| cx.tcx.hir().item(impl_).clean(cx))
252+
}));
253+
items.extend(self.modules.clean(cx).into_iter().flatten());
254+
items.extend(self.proc_macros.iter().map(|hir_id| {
255+
let _def_id = hir_id.owner.local_def_index;
256+
// TODO: look how `rustc_metadata::rmeta::encoder` does this
257+
unimplemented!()
258+
}));
259+
260+
// determine if we should display the inner contents or
261+
// the outer `mod` item for the source code.
262+
// TODO: for the crate root, I think this should always be `self.item.span`?
263+
let span = {
264+
let sm = cx.sess().source_map();
265+
let outer = sm.lookup_char_pos(self.item.span.lo());
266+
let inner = sm.lookup_char_pos(self.item.module.inner.lo());
267+
if outer.file.start_pos == inner.file.start_pos {
268+
// mod foo { ... }
269+
self.item.span
270+
} else {
271+
// mod foo; (and a separate SourceFile for the contents)
272+
self.item.module.inner
273+
}
274+
};
275+
276+
let id = hir::CRATE_HIR_ID;
277+
Item {
278+
name,
279+
attrs,
280+
source: span.clean(cx),
281+
visibility: Visibility::Public,
282+
stability: cx.stability(id),
283+
deprecation: cx.deprecation(id).clean(cx),
284+
def_id: cx.tcx.hir().local_def_id(id).to_def_id(),
285+
kind: ModuleItem(Module { is_crate: true, items }),
286+
}
287+
}
288+
}
289+
290+
impl Clean<Vec<Item>> for hir::ModuleItems {
291+
fn clean(&self, _cx: &DocContext<'_>) -> Vec<Item> {
292+
unimplemented!()
293+
}
294+
}
295+
296+
/*
224297
impl Clean<Item> for doctree::Module<'_> {
225298
fn clean(&self, cx: &DocContext<'_>) -> Item {
226299
// maintain a stack of mod ids, for doc comment path resolution
@@ -276,6 +349,7 @@ impl Clean<Item> for doctree::Module<'_> {
276349
}
277350
}
278351
}
352+
*/
279353

280354
impl Clean<Attributes> for [ast::Attribute] {
281355
fn clean(&self, cx: &DocContext<'_>) -> Attributes {
@@ -718,7 +792,6 @@ impl Clean<Generics> for hir::Generics<'_> {
718792
impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx>) {
719793
fn clean(&self, cx: &DocContext<'_>) -> Generics {
720794
use self::WherePredicate as WP;
721-
use std::collections::BTreeMap;
722795

723796
let (gens, preds) = *self;
724797

@@ -2280,24 +2353,9 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
22802353
}
22812354
}
22822355

2283-
impl Clean<Item> for doctree::Macro {
2284-
fn clean(&self, cx: &DocContext<'_>) -> Item {
2285-
Item::from_def_id_and_parts(
2286-
self.def_id,
2287-
Some(self.name),
2288-
MacroItem(Macro {
2289-
source: format!(
2290-
"macro_rules! {} {{\n{}}}",
2291-
self.name,
2292-
self.matchers
2293-
.iter()
2294-
.map(|span| { format!(" {} => {{ ... }};\n", span.to_src(cx)) })
2295-
.collect::<String>()
2296-
),
2297-
imported_from: self.imported_from.clean(cx),
2298-
}),
2299-
cx,
2300-
)
2356+
impl Clean<Item> for hir::MacroDef<'_> {
2357+
fn clean(&self, _cx: &DocContext<'_>) -> Item {
2358+
unimplemented!()
23012359
}
23022360
}
23032361

src/librustdoc/clean/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
2424
use crate::visit_lib::LibEmbargoVisitor;
2525

2626
let krate = cx.tcx.hir().krate();
27-
let module = crate::visit_ast::RustdocVisitor::new(&mut cx).visit(krate);
27+
//let module = crate::visit_ast::RustdocVisitor::new(&mut cx).visit(krate);
2828

2929
let mut r = cx.renderinfo.get_mut();
3030
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
@@ -41,10 +41,10 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
4141

4242
// Clean the crate, translating the entire librustc_ast AST to one that is
4343
// understood by rustdoc.
44-
let mut module = module.clean(cx);
44+
let mut krate = krate.clean(cx);
4545
let mut masked_crates = FxHashSet::default();
4646

47-
match module.kind {
47+
match krate.kind {
4848
ItemKind::ModuleItem(ref module) => {
4949
for it in &module.items {
5050
// `compiler_builtins` should be masked too, but we can't apply
@@ -62,7 +62,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
6262

6363
let ExternalCrate { name, src, primitives, keywords, .. } = LOCAL_CRATE.clean(cx);
6464
{
65-
let m = match module.kind {
65+
let m = match krate.kind {
6666
ItemKind::ModuleItem(ref mut m) => m,
6767
_ => unreachable!(),
6868
};
@@ -92,7 +92,7 @@ crate fn krate(mut cx: &mut DocContext<'_>) -> Crate {
9292
name,
9393
version: None,
9494
src,
95-
module: Some(module),
95+
module: Some(krate),
9696
externs,
9797
primitives,
9898
external_traits: cx.external_traits.clone(),

0 commit comments

Comments
 (0)