Skip to content

Mark top level module as a crate in rustdoc #12632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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