Skip to content

Commit e4ead7b

Browse files
committed
auto merge of #18860 : aturon/rust/reexports-in-stab-summary, r=brson
Previously, the stability summary page attempted to associate impl blocks with the module in which they were defined, rather than the module defining the type they apply to (which is usually, but not always, the same). Unfortunately, due to the basic architecture of rustdoc, this meant that impls from re-exports were not being counted. This commit makes the stability summary work the same way that rustdoc's rendered output does: all methods are counted alongside the type they apply to, no matter where the methods are defined. In addition, for trait impl blocks only the stability of the overall block is counted; the stability of the methods within is not counted (since that stability level is part of the trait definition). Fixes #18812
2 parents 7ea23e5 + 5f09a50 commit e4ead7b

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

src/librustdoc/html/render.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ pub enum ExternalLocation {
114114

115115
/// Metadata about an implementor of a trait.
116116
pub struct Implementor {
117-
def_id: ast::DefId,
118-
generics: clean::Generics,
119-
trait_: clean::Type,
120-
for_: clean::Type,
121-
stability: Option<clean::Stability>,
117+
pub def_id: ast::DefId,
118+
pub generics: clean::Generics,
119+
pub trait_: clean::Type,
120+
pub for_: clean::Type,
121+
pub stability: Option<clean::Stability>,
122122
}
123123

124124
/// Metadata about implementations for a type.
125125
#[deriving(Clone)]
126126
pub struct Impl {
127-
impl_: clean::Impl,
128-
dox: Option<String>,
129-
stability: Option<clean::Stability>,
127+
pub impl_: clean::Impl,
128+
pub dox: Option<String>,
129+
pub stability: Option<clean::Stability>,
130130
}
131131

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

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

257-
// Crawl the crate, building a summary of the stability levels. NOTE: this
258-
// summary *must* be computed with the original `krate`; the folding below
259-
// removes the impls from their modules.
260-
let summary = stability_summary::build(&krate);
261-
262257
// Crawl the crate attributes looking for attributes which control how we're
263258
// going to emit HTML
264259
let default: &[_] = &[];
@@ -372,6 +367,9 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
372367
try!(write_shared(&cx, &krate, &*cache, index));
373368
let krate = try!(render_sources(&mut cx, krate));
374369

370+
// Crawl the crate, building a summary of the stability levels.
371+
let summary = stability_summary::build(&krate);
372+
375373
// And finally render the whole crate's documentation
376374
cx.krate(krate, summary)
377375
}

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#![crate_type = "rlib"]
1717

1818
#![allow(unknown_features)]
19-
#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax)]
19+
#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax, tuple_indexing)]
2020

2121
extern crate arena;
2222
extern crate getopts;

src/librustdoc/stability_summary.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use syntax::ast::Public;
2222

2323
use clean::{Crate, Item, ModuleItem, Module, StructItem, Struct, EnumItem, Enum};
2424
use clean::{ImplItem, Impl, Trait, TraitItem, TraitMethod, ProvidedMethod, RequiredMethod};
25-
use clean::{TypeTraitItem, ViewItemItem, PrimitiveItem};
25+
use clean::{TypeTraitItem, ViewItemItem, PrimitiveItem, Stability};
26+
27+
use html::render::cache_key;
2628

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

91-
// Produce the summary for an arbitrary item. If the item is a module, include a
92-
// module summary. The counts for items with nested items (e.g. modules, traits,
93-
// impls) include all children counts.
94-
fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
95-
// count this item
96-
let item_counts = match item.stability {
93+
fn count_stability(stab: Option<&Stability>) -> Counts {
94+
match stab {
9795
None => Counts { unmarked: 1, .. Zero::zero() },
9896
Some(ref stab) => match stab.level {
9997
Deprecated => Counts { deprecated: 1, .. Zero::zero() },
@@ -103,7 +101,31 @@ fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
103101
Frozen => Counts { frozen: 1, .. Zero::zero() },
104102
Locked => Counts { locked: 1, .. Zero::zero() },
105103
}
106-
};
104+
}
105+
}
106+
107+
fn summarize_methods(item: &Item) -> Counts {
108+
match cache_key.get().unwrap().impls.get(&item.def_id) {
109+
Some(v) => {
110+
v.iter().map(|i| {
111+
let mut count = count_stability(i.stability.as_ref());
112+
if i.impl_.trait_.is_none() {
113+
count = count +
114+
i.impl_.items.iter().map(|ti| summarize_item(ti).0).sum();
115+
}
116+
count
117+
}).sum()
118+
}
119+
None => Zero::zero()
120+
}
121+
}
122+
123+
124+
// Produce the summary for an arbitrary item. If the item is a module, include a
125+
// module summary. The counts for items with nested items (e.g. modules, traits,
126+
// impls) include all children counts.
127+
fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
128+
let item_counts = count_stability(item.stability.as_ref()) + summarize_methods(item);
107129

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

0 commit comments

Comments
 (0)