@@ -27,7 +27,7 @@ use rustc::metadata::csearch;
27
27
use rustc:: metadata:: decoder;
28
28
use rustc:: middle:: ty;
29
29
30
- use std:: string :: String ;
30
+ use std:: rc :: Rc ;
31
31
32
32
use core;
33
33
use doctree;
@@ -53,6 +53,12 @@ impl<T: Clean<U>, U> Clean<U> for @T {
53
53
}
54
54
}
55
55
56
+ impl < T : Clean < U > , U > Clean < U > for Rc < T > {
57
+ fn clean ( & self ) -> U {
58
+ ( * * self ) . clean ( )
59
+ }
60
+ }
61
+
56
62
impl < T : Clean < U > , U > Clean < Option < U > > for Option < T > {
57
63
fn clean ( & self ) -> Option < U > {
58
64
match self {
@@ -337,6 +343,14 @@ impl attr::AttrMetaMethods for Attribute {
337
343
None
338
344
}
339
345
}
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
+ }
340
354
341
355
#[ deriving( Clone , Encodable , Decodable ) ]
342
356
pub struct TyParam {
@@ -859,10 +873,7 @@ impl Clean<TraitMethod> for ty::Method {
859
873
visibility : Some ( ast:: Inherited ) ,
860
874
def_id : self . def_id ,
861
875
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 ( ) ,
866
877
inner : TyMethodItem ( TyMethod {
867
878
fn_style : self . fty . fn_style ,
868
879
generics : self . generics . clean ( ) ,
@@ -1070,6 +1081,31 @@ impl Clean<Item> for ast::StructField {
1070
1081
}
1071
1082
}
1072
1083
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
+
1073
1109
pub type Visibility = ast:: Visibility ;
1074
1110
1075
1111
impl Clean < Option < Visibility > > for ast:: Visibility {
@@ -1199,6 +1235,16 @@ pub struct Span {
1199
1235
pub hicol : uint ,
1200
1236
}
1201
1237
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
+
1202
1248
impl Clean < Span > for syntax:: codemap:: Span {
1203
1249
fn clean ( & self ) -> Span {
1204
1250
let ctxt = super :: ctxtkey. get ( ) . unwrap ( ) ;
@@ -1270,6 +1316,12 @@ impl Clean<String> for ast::Ident {
1270
1316
}
1271
1317
}
1272
1318
1319
+ impl Clean < StrBuf > for ast:: Name {
1320
+ fn clean ( & self ) -> StrBuf {
1321
+ token:: get_name ( * self ) . get ( ) . to_strbuf ( )
1322
+ }
1323
+ }
1324
+
1273
1325
#[ deriving( Clone , Encodable , Decodable ) ]
1274
1326
pub struct Typedef {
1275
1327
pub type_ : Type ,
@@ -1366,19 +1418,14 @@ pub struct Impl {
1366
1418
pub derived : bool ,
1367
1419
}
1368
1420
1421
+ fn detect_derived < M : AttrMetaMethods > ( attrs : & [ M ] ) -> bool {
1422
+ attrs. iter ( ) . any ( |attr| {
1423
+ attr. name ( ) . get ( ) == "automatically_derived"
1424
+ } )
1425
+ }
1426
+
1369
1427
impl Clean < Item > for doctree:: Impl {
1370
1428
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
- }
1382
1429
Item {
1383
1430
name : None ,
1384
1431
attrs : self . attrs . clean ( ) ,
@@ -1390,7 +1437,7 @@ impl Clean<Item> for doctree::Impl {
1390
1437
trait_ : self . trait_ . clean ( ) ,
1391
1438
for_ : self . for_ . clean ( ) ,
1392
1439
methods : self . methods . clean ( ) ,
1393
- derived : derived ,
1440
+ derived : detect_derived ( self . attrs . as_slice ( ) ) ,
1394
1441
} ) ,
1395
1442
}
1396
1443
}
@@ -1427,7 +1474,9 @@ impl Clean<Vec<Item>> for ast::ViewItem {
1427
1474
ast:: ViewPathList ( ref a, ref list, ref b) => {
1428
1475
let remaining = list. iter ( ) . filter ( |path| {
1429
1476
match try_inline ( path. node . id ) {
1430
- Some ( item) => { ret. push ( item) ; false }
1477
+ Some ( items) => {
1478
+ ret. extend ( items. move_iter ( ) ) ; false
1479
+ }
1431
1480
None => true ,
1432
1481
}
1433
1482
} ) . map ( |a| a. clone ( ) ) . collect :: < Vec < ast:: PathListIdent > > ( ) ;
@@ -1441,7 +1490,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
1441
1490
}
1442
1491
ast:: ViewPathSimple ( _, _, id) => {
1443
1492
match try_inline ( id) {
1444
- Some ( item ) => ret. push ( item ) ,
1493
+ Some ( items ) => ret. extend ( items . move_iter ( ) ) ,
1445
1494
None => ret. push ( convert ( & self . node ) ) ,
1446
1495
}
1447
1496
}
@@ -1453,7 +1502,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
1453
1502
}
1454
1503
}
1455
1504
1456
- fn try_inline ( id : ast:: NodeId ) -> Option < Item > {
1505
+ fn try_inline ( id : ast:: NodeId ) -> Option < Vec < Item > > {
1457
1506
let cx = super :: ctxtkey. get ( ) . unwrap ( ) ;
1458
1507
let tcx = match cx. maybe_typed {
1459
1508
core:: Typed ( ref tycx) => tycx,
@@ -1465,23 +1514,28 @@ fn try_inline(id: ast::NodeId) -> Option<Item> {
1465
1514
} ;
1466
1515
let did = ast_util:: def_id_of_def ( def) ;
1467
1516
if ast_util:: is_local ( did) { return None }
1517
+
1518
+ let mut ret = Vec :: new ( ) ;
1468
1519
let inner = match def {
1469
1520
ast:: DefTrait ( did) => TraitItem ( build_external_trait ( tcx, did) ) ,
1470
1521
ast:: DefFn ( did, style) =>
1471
1522
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
+ }
1472
1527
_ => return None ,
1473
1528
} ;
1474
1529
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 ( ) ,
1479
1532
name : Some ( fqn. last ( ) . unwrap ( ) . to_str ( ) . to_strbuf ( ) ) ,
1480
1533
attrs : load_attrs ( tcx, did) ,
1481
1534
inner : inner,
1482
1535
visibility : Some ( ast:: Public ) ,
1483
1536
def_id : did,
1484
- } )
1537
+ } ) ;
1538
+ Some ( ret)
1485
1539
}
1486
1540
1487
1541
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 {
1726
1780
}
1727
1781
1728
1782
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) ;
1730
1784
let methods = ty:: trait_methods ( tcx, did) ;
1731
1785
Trait {
1732
1786
generics : def. generics . clean ( ) ,
@@ -1738,7 +1792,7 @@ fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> Trait {
1738
1792
fn build_external_function ( tcx : & ty:: ctxt ,
1739
1793
did : ast:: DefId ,
1740
1794
style : ast:: FnStyle ) -> Function {
1741
- let t = csearch :: get_type ( tcx, did) ;
1795
+ let t = ty :: lookup_item_type ( tcx, did) ;
1742
1796
Function {
1743
1797
decl : match ty:: get ( t. ty ) . sty {
1744
1798
ty:: ty_bare_fn( ref f) => f. sig . clean ( ) ,
@@ -1749,6 +1803,111 @@ fn build_external_function(tcx: &ty::ctxt,
1749
1803
}
1750
1804
}
1751
1805
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
+
1752
1911
fn resolve_use_source ( path : Path , id : ast:: NodeId ) -> ImportSource {
1753
1912
ImportSource {
1754
1913
path : path,
0 commit comments