Skip to content

Commit 8f46be0

Browse files
committed
---
yaml --- r: 152013 b: refs/heads/try2 c: c81b511 h: refs/heads/master i: 152011: 5de0d48 v: v3
1 parent 833b041 commit 8f46be0

File tree

4 files changed

+193
-35
lines changed

4 files changed

+193
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 8b8e70ba1d47ca76217980f0c4c6f55b60a06e06
8+
refs/heads/try2: c81b511bfdbb5f0fb2a6c7522cf4b8dbe5c83ece
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustdoc/clean.rs

Lines changed: 186 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::metadata::csearch;
2727
use rustc::metadata::decoder;
2828
use rustc::middle::ty;
2929

30-
use std::string::String;
30+
use std::rc::Rc;
3131

3232
use core;
3333
use doctree;
@@ -53,6 +53,12 @@ impl<T: Clean<U>, U> Clean<U> for @T {
5353
}
5454
}
5555

56+
impl<T: Clean<U>, U> Clean<U> for Rc<T> {
57+
fn clean(&self) -> U {
58+
(**self).clean()
59+
}
60+
}
61+
5662
impl<T: Clean<U>, U> Clean<Option<U>> for Option<T> {
5763
fn clean(&self) -> Option<U> {
5864
match self {
@@ -337,6 +343,14 @@ impl attr::AttrMetaMethods for Attribute {
337343
None
338344
}
339345
}
346+
impl<'a> attr::AttrMetaMethods for &'a Attribute {
347+
fn name(&self) -> InternedString { (**self).name() }
348+
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
349+
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
350+
fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
351+
None
352+
}
353+
}
340354

341355
#[deriving(Clone, Encodable, Decodable)]
342356
pub struct TyParam {
@@ -859,10 +873,7 @@ impl Clean<TraitMethod> for ty::Method {
859873
visibility: Some(ast::Inherited),
860874
def_id: self.def_id,
861875
attrs: load_attrs(tcx, self.def_id),
862-
source: Span {
863-
filename: "".to_strbuf(),
864-
loline: 0, locol: 0, hiline: 0, hicol: 0,
865-
},
876+
source: Span::empty(),
866877
inner: TyMethodItem(TyMethod {
867878
fn_style: self.fty.fn_style,
868879
generics: self.generics.clean(),
@@ -1070,6 +1081,31 @@ impl Clean<Item> for ast::StructField {
10701081
}
10711082
}
10721083

1084+
impl Clean<Item> for ty::field_ty {
1085+
fn clean(&self) -> Item {
1086+
use syntax::parse::token::special_idents::unnamed_field;
1087+
let name = if self.name == unnamed_field.name {
1088+
None
1089+
} else {
1090+
Some(self.name)
1091+
};
1092+
let cx = super::ctxtkey.get().unwrap();
1093+
let tcx = match cx.maybe_typed {
1094+
core::Typed(ref tycx) => tycx,
1095+
core::NotTyped(_) => fail!(),
1096+
};
1097+
let ty = ty::lookup_item_type(tcx, self.id);
1098+
Item {
1099+
name: name.clean(),
1100+
attrs: load_attrs(tcx, self.id),
1101+
source: Span::empty(),
1102+
visibility: Some(self.vis),
1103+
def_id: self.id,
1104+
inner: StructFieldItem(TypedStructField(ty.ty.clean())),
1105+
}
1106+
}
1107+
}
1108+
10731109
pub type Visibility = ast::Visibility;
10741110

10751111
impl Clean<Option<Visibility>> for ast::Visibility {
@@ -1199,6 +1235,16 @@ pub struct Span {
11991235
pub hicol: uint,
12001236
}
12011237

1238+
impl Span {
1239+
fn empty() -> Span {
1240+
Span {
1241+
filename: "".to_strbuf(),
1242+
loline: 0, locol: 0,
1243+
hiline: 0, hicol: 0,
1244+
}
1245+
}
1246+
}
1247+
12021248
impl Clean<Span> for syntax::codemap::Span {
12031249
fn clean(&self) -> Span {
12041250
let ctxt = super::ctxtkey.get().unwrap();
@@ -1270,6 +1316,12 @@ impl Clean<String> for ast::Ident {
12701316
}
12711317
}
12721318

1319+
impl Clean<StrBuf> for ast::Name {
1320+
fn clean(&self) -> StrBuf {
1321+
token::get_name(*self).get().to_strbuf()
1322+
}
1323+
}
1324+
12731325
#[deriving(Clone, Encodable, Decodable)]
12741326
pub struct Typedef {
12751327
pub type_: Type,
@@ -1366,19 +1418,14 @@ pub struct Impl {
13661418
pub derived: bool,
13671419
}
13681420

1421+
fn detect_derived<M: AttrMetaMethods>(attrs: &[M]) -> bool {
1422+
attrs.iter().any(|attr| {
1423+
attr.name().get() == "automatically_derived"
1424+
})
1425+
}
1426+
13691427
impl Clean<Item> for doctree::Impl {
13701428
fn clean(&self) -> Item {
1371-
let mut derived = false;
1372-
for attr in self.attrs.iter() {
1373-
match attr.node.value.node {
1374-
ast::MetaWord(ref s) => {
1375-
if s.get() == "automatically_derived" {
1376-
derived = true;
1377-
}
1378-
}
1379-
_ => {}
1380-
}
1381-
}
13821429
Item {
13831430
name: None,
13841431
attrs: self.attrs.clean(),
@@ -1390,7 +1437,7 @@ impl Clean<Item> for doctree::Impl {
13901437
trait_: self.trait_.clean(),
13911438
for_: self.for_.clean(),
13921439
methods: self.methods.clean(),
1393-
derived: derived,
1440+
derived: detect_derived(self.attrs.as_slice()),
13941441
}),
13951442
}
13961443
}
@@ -1427,7 +1474,9 @@ impl Clean<Vec<Item>> for ast::ViewItem {
14271474
ast::ViewPathList(ref a, ref list, ref b) => {
14281475
let remaining = list.iter().filter(|path| {
14291476
match try_inline(path.node.id) {
1430-
Some(item) => { ret.push(item); false }
1477+
Some(items) => {
1478+
ret.extend(items.move_iter()); false
1479+
}
14311480
None => true,
14321481
}
14331482
}).map(|a| a.clone()).collect::<Vec<ast::PathListIdent>>();
@@ -1441,7 +1490,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
14411490
}
14421491
ast::ViewPathSimple(_, _, id) => {
14431492
match try_inline(id) {
1444-
Some(item) => ret.push(item),
1493+
Some(items) => ret.extend(items.move_iter()),
14451494
None => ret.push(convert(&self.node)),
14461495
}
14471496
}
@@ -1453,7 +1502,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
14531502
}
14541503
}
14551504

1456-
fn try_inline(id: ast::NodeId) -> Option<Item> {
1505+
fn try_inline(id: ast::NodeId) -> Option<Vec<Item>> {
14571506
let cx = super::ctxtkey.get().unwrap();
14581507
let tcx = match cx.maybe_typed {
14591508
core::Typed(ref tycx) => tycx,
@@ -1465,23 +1514,28 @@ fn try_inline(id: ast::NodeId) -> Option<Item> {
14651514
};
14661515
let did = ast_util::def_id_of_def(def);
14671516
if ast_util::is_local(did) { return None }
1517+
1518+
let mut ret = Vec::new();
14681519
let inner = match def {
14691520
ast::DefTrait(did) => TraitItem(build_external_trait(tcx, did)),
14701521
ast::DefFn(did, style) =>
14711522
FunctionItem(build_external_function(tcx, did, style)),
1523+
ast::DefStruct(did) => {
1524+
ret.extend(build_impls(tcx, did).move_iter());
1525+
StructItem(build_struct(tcx, did))
1526+
}
14721527
_ => return None,
14731528
};
14741529
let fqn = csearch::get_item_path(tcx, did);
1475-
Some(Item {
1476-
source: Span {
1477-
filename: "".to_strbuf(), loline: 0, locol: 0, hiline: 0, hicol: 0,
1478-
},
1530+
ret.push(Item {
1531+
source: Span::empty(),
14791532
name: Some(fqn.last().unwrap().to_str().to_strbuf()),
14801533
attrs: load_attrs(tcx, did),
14811534
inner: inner,
14821535
visibility: Some(ast::Public),
14831536
def_id: did,
1484-
})
1537+
});
1538+
Some(ret)
14851539
}
14861540

14871541
fn load_attrs(tcx: &ty::ctxt, did: ast::DefId) -> Vec<Attribute> {
@@ -1726,7 +1780,7 @@ fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
17261780
}
17271781

17281782
fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> Trait {
1729-
let def = csearch::get_trait_def(tcx, did);
1783+
let def = ty::lookup_trait_def(tcx, did);
17301784
let methods = ty::trait_methods(tcx, did);
17311785
Trait {
17321786
generics: def.generics.clean(),
@@ -1738,7 +1792,7 @@ fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> Trait {
17381792
fn build_external_function(tcx: &ty::ctxt,
17391793
did: ast::DefId,
17401794
style: ast::FnStyle) -> Function {
1741-
let t = csearch::get_type(tcx, did);
1795+
let t = ty::lookup_item_type(tcx, did);
17421796
Function {
17431797
decl: match ty::get(t.ty).sty {
17441798
ty::ty_bare_fn(ref f) => f.sig.clean(),
@@ -1749,6 +1803,111 @@ fn build_external_function(tcx: &ty::ctxt,
17491803
}
17501804
}
17511805

1806+
fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> Struct {
1807+
use syntax::parse::token::special_idents::unnamed_field;
1808+
1809+
let t = ty::lookup_item_type(tcx, did);
1810+
let fields = ty::lookup_struct_fields(tcx, did);
1811+
1812+
Struct {
1813+
struct_type: match fields.as_slice() {
1814+
[] => doctree::Unit,
1815+
[ref f] if f.name == unnamed_field.name => doctree::Newtype,
1816+
[ref f, ..] if f.name == unnamed_field.name => doctree::Tuple,
1817+
_ => doctree::Plain,
1818+
},
1819+
generics: t.generics.clean(),
1820+
fields: fields.iter().map(|f| f.clean()).collect(),
1821+
fields_stripped: false,
1822+
}
1823+
}
1824+
1825+
fn build_impls(tcx: &ty::ctxt,
1826+
did: ast::DefId) -> Vec<Item> {
1827+
ty::populate_implementations_for_type_if_necessary(tcx, did);
1828+
let mut impls = Vec::new();
1829+
1830+
match tcx.inherent_impls.borrow().find(&did) {
1831+
None => {}
1832+
Some(i) => {
1833+
impls.extend(i.borrow().iter().map(|&did| { build_impl(tcx, did) }));
1834+
}
1835+
}
1836+
1837+
// csearch::each_impl(&tcx.sess.cstore, did.krate, |imp| {
1838+
// // if imp.krate
1839+
// let t = ty::lookup_item_type(tcx, imp);
1840+
// println!("{}", ::rustc::util::ppaux::ty_to_str(tcx, t.ty));
1841+
// match ty::get(t.ty).sty {
1842+
// ty::ty_struct(tdid, _) |
1843+
// ty::ty_enum(tdid, _) if tdid == did => {
1844+
// impls.push(build_impl(tcx, imp));
1845+
// }
1846+
// _ => {}
1847+
// }
1848+
// });
1849+
// for (k, v) in tcx.trait_impls.borrow().iter() {
1850+
// if k.krate != did.krate { continue }
1851+
// for imp in v.borrow().iter() {
1852+
// if imp.krate != did.krate { continue }
1853+
// let t = ty::lookup_item_type(tcx, *imp);
1854+
// println!("{}", ::rustc::util::ppaux::ty_to_str(tcx, t.ty));
1855+
// match ty::get(t.ty).sty {
1856+
// ty::ty_struct(tdid, _) |
1857+
// ty::ty_enum(tdid, _) if tdid == did => {
1858+
// impls.push(build_impl(tcx, *imp));
1859+
// }
1860+
// _ => {}
1861+
// }
1862+
// }
1863+
// }
1864+
1865+
impls
1866+
}
1867+
1868+
fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> Item {
1869+
let associated_trait = csearch::get_impl_trait(tcx, did);
1870+
let attrs = load_attrs(tcx, did);
1871+
let ty = ty::lookup_item_type(tcx, did);
1872+
let methods = tcx.impl_methods.borrow().get(&did).iter().map(|did| {
1873+
let mut item = match ty::method(tcx, *did).clean() {
1874+
Provided(item) => item,
1875+
Required(item) => item,
1876+
};
1877+
item.inner = match item.inner.clone() {
1878+
TyMethodItem(TyMethod { fn_style, decl, self_, generics }) => {
1879+
MethodItem(Method {
1880+
fn_style: fn_style,
1881+
decl: decl,
1882+
self_: self_,
1883+
generics: generics,
1884+
})
1885+
}
1886+
_ => fail!("not a tymethod"),
1887+
};
1888+
item
1889+
}).collect();
1890+
Item {
1891+
inner: ImplItem(Impl {
1892+
derived: detect_derived(attrs.as_slice()),
1893+
trait_: associated_trait.clean().map(|bound| {
1894+
match bound {
1895+
TraitBound(ty) => ty,
1896+
RegionBound => fail!(),
1897+
}
1898+
}),
1899+
for_: ty.ty.clean(),
1900+
generics: ty.generics.clean(),
1901+
methods: methods,
1902+
}),
1903+
source: Span::empty(),
1904+
name: None,
1905+
attrs: attrs,
1906+
visibility: Some(ast::Inherited),
1907+
def_id: did,
1908+
}
1909+
}
1910+
17521911
fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource {
17531912
ImportSource {
17541913
path: path,

branches/try2/src/librustdoc/html/render.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct Cache {
132132
///
133133
/// The values of the map are a list of implementations and documentation
134134
/// found on that implementation.
135-
pub impls: HashMap<ast::NodeId, Vec<(clean::Impl, Option<String>)>>,
135+
pub impls: HashMap<ast::DefId, Vec<(clean::Impl, Option<String>)>>,
136136

137137
/// Maintains a mapping of local crate node ids to the fully qualified name
138138
/// and "short type description" of that node. This is used when generating
@@ -837,10 +837,8 @@ impl DocFolder for Cache {
837837
match item {
838838
clean::Item{ attrs, inner: clean::ImplItem(i), .. } => {
839839
match i.for_ {
840-
clean::ResolvedPath { did, .. }
841-
if ast_util::is_local(did) =>
842-
{
843-
let v = self.impls.find_or_insert_with(did.node, |_| {
840+
clean::ResolvedPath { did, .. } => {
841+
let v = self.impls.find_or_insert_with(did, |_| {
844842
Vec::new()
845843
});
846844
// extract relevant documentation for this impl
@@ -1664,7 +1662,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
16641662
}
16651663

16661664
fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
1667-
match cache_key.get().unwrap().impls.find(&it.def_id.node) {
1665+
match cache_key.get().unwrap().impls.find(&it.def_id) {
16681666
Some(v) => {
16691667
let mut non_trait = v.iter().filter(|p| {
16701668
p.ref0().trait_.is_none()

branches/try2/src/librustdoc/passes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ impl<'a> fold::DocFolder for Stripper<'a> {
152152
clean::ImplItem(clean::Impl{
153153
for_: clean::ResolvedPath{ did, .. }, ..
154154
}) => {
155-
if !self.exported_items.contains(&did.node) {
155+
if ast_util::is_local(did) &&
156+
!self.exported_items.contains(&did.node) {
156157
return None;
157158
}
158159
}

0 commit comments

Comments
 (0)