Skip to content

rustdoc: revise method counts in stability summary #18860

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
Nov 12, 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
24 changes: 11 additions & 13 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ pub enum ExternalLocation {

/// Metadata about an implementor of a trait.
pub struct Implementor {
def_id: ast::DefId,
generics: clean::Generics,
trait_: clean::Type,
for_: clean::Type,
stability: Option<clean::Stability>,
pub def_id: ast::DefId,
pub generics: clean::Generics,
pub trait_: clean::Type,
pub for_: clean::Type,
pub stability: Option<clean::Stability>,
}

/// Metadata about implementations for a type.
#[deriving(Clone)]
pub struct Impl {
impl_: clean::Impl,
dox: Option<String>,
stability: Option<clean::Stability>,
pub impl_: clean::Impl,
pub dox: Option<String>,
pub stability: Option<clean::Stability>,
}

/// This cache is used to store information about the `clean::Crate` being
Expand Down Expand Up @@ -254,11 +254,6 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->

try!(mkdir(&cx.dst));

// Crawl the crate, building a summary of the stability levels. NOTE: this
// summary *must* be computed with the original `krate`; the folding below
// removes the impls from their modules.
let summary = stability_summary::build(&krate);

// Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML
let default: &[_] = &[];
Expand Down Expand Up @@ -372,6 +367,9 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
try!(write_shared(&cx, &krate, &*cache, index));
let krate = try!(render_sources(&mut cx, krate));

// Crawl the crate, building a summary of the stability levels.
let summary = stability_summary::build(&krate);

// And finally render the whole crate's documentation
cx.krate(krate, summary)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#![crate_type = "rlib"]

#![allow(unknown_features)]
#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax)]
#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax, tuple_indexing)]

extern crate arena;
extern crate getopts;
Expand Down
38 changes: 30 additions & 8 deletions src/librustdoc/stability_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use syntax::ast::Public;

use clean::{Crate, Item, ModuleItem, Module, StructItem, Struct, EnumItem, Enum};
use clean::{ImplItem, Impl, Trait, TraitItem, TraitMethod, ProvidedMethod, RequiredMethod};
use clean::{TypeTraitItem, ViewItemItem, PrimitiveItem};
use clean::{TypeTraitItem, ViewItemItem, PrimitiveItem, Stability};

use html::render::cache_key;

#[deriving(Zero, Encodable, Decodable, PartialEq, Eq)]
/// The counts for each stability level.
Expand Down Expand Up @@ -88,12 +90,8 @@ fn visible(item: &Item) -> bool {
}
}

// Produce the summary for an arbitrary item. If the item is a module, include a
// module summary. The counts for items with nested items (e.g. modules, traits,
// impls) include all children counts.
fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
// count this item
let item_counts = match item.stability {
fn count_stability(stab: Option<&Stability>) -> Counts {
match stab {
None => Counts { unmarked: 1, .. Zero::zero() },
Some(ref stab) => match stab.level {
Deprecated => Counts { deprecated: 1, .. Zero::zero() },
Expand All @@ -103,7 +101,31 @@ fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
Frozen => Counts { frozen: 1, .. Zero::zero() },
Locked => Counts { locked: 1, .. Zero::zero() },
}
};
}
}

fn summarize_methods(item: &Item) -> Counts {
match cache_key.get().unwrap().impls.get(&item.def_id) {
Some(v) => {
v.iter().map(|i| {
let mut count = count_stability(i.stability.as_ref());
if i.impl_.trait_.is_none() {
count = count +
i.impl_.items.iter().map(|ti| summarize_item(ti).0).sum();
}
count
}).sum()
}
None => Zero::zero()
}
}


// Produce the summary for an arbitrary item. If the item is a module, include a
// module summary. The counts for items with nested items (e.g. modules, traits,
// impls) include all children counts.
fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
let item_counts = count_stability(item.stability.as_ref()) + summarize_methods(item);

// Count this item's children, if any. Note that a trait impl is
// considered to have no children.
Expand Down