Skip to content

Commit

Permalink
Mark top level module as a crate in rustdoc, closes rust-lang#12507
Browse files Browse the repository at this point in the history
  • Loading branch information
fhahn committed Feb 26, 2014
1 parent 68a92c5 commit 5d825de
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub enum ItemEnum {
#[deriving(Clone, Encodable, Decodable)]
pub struct Module {
items: ~[Item],
is_crate: bool,
}

impl Clean<Item> for doctree::Module {
Expand All @@ -202,6 +203,7 @@ impl Clean<Item> for doctree::Module {
visibility: self.vis.clean(),
id: self.id,
inner: ModuleItem(Module {
is_crate: self.is_crate,
items: [self.structs.clean(), self.enums.clean(),
self.fns.clean(), self.foreigns.clean().concat_vec(),
self.mods.clean(), self.typedefs.clean(),
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Module {
foreigns: ~[ast::ForeignMod],
view_items: ~[ast::ViewItem],
macros: ~[Macro],
is_crate: bool,
}

impl Module {
Expand All @@ -54,6 +55,7 @@ impl Module {
view_items : ~[],
foreigns : ~[],
macros : ~[],
is_crate : false,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ pub trait DocFolder {
}

fn fold_mod(&mut self, m: Module) -> Module {
Module { items: m.items.move_iter().filter_map(|i| self.fold_item(i)).collect() }
Module {
is_crate: m.is_crate,
items: m.items.move_iter().filter_map(|i| self.fold_item(i)).collect()
}
}

fn fold_crate(&mut self, mut c: Crate) -> Crate {
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,11 @@ impl<'a> fmt::Show for Item<'a> {
// Write the breadcrumb trail header for the top
try!(write!(fmt.buf, "<h1 class='fqn'>"));
match self.item.inner {
clean::ModuleItem(..) => try!(write!(fmt.buf, "Module ")),
clean::ModuleItem(ref m) => if m.is_crate {
try!(write!(fmt.buf, "Crate "));
} else {
try!(write!(fmt.buf, "Module "));
},
clean::FunctionItem(..) => try!(write!(fmt.buf, "Function ")),
clean::TraitItem(..) => try!(write!(fmt.buf, "Trait ")),
clean::StructItem(..) => try!(write!(fmt.buf, "Struct ")),
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl<'a> RustdocVisitor<'a> {
self.module = self.visit_mod_contents(krate.span, krate.attrs.clone(),
ast::Public, ast::CRATE_NODE_ID,
&krate.module, None);
self.module.is_crate = true;
}

pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef,
Expand Down

0 comments on commit 5d825de

Please sign in to comment.