@@ -65,6 +65,10 @@ fn get_stability(cx: &DocContext, def_id: DefId) -> Option<Stability> {
65
65
cx. tcx_opt ( ) . and_then ( |tcx| stability:: lookup_stability ( tcx, def_id) ) . clean ( cx)
66
66
}
67
67
68
+ fn get_deprecation ( cx : & DocContext , def_id : DefId ) -> Option < Deprecation > {
69
+ cx. tcx_opt ( ) . and_then ( |tcx| stability:: lookup_deprecation ( tcx, def_id) ) . clean ( cx)
70
+ }
71
+
68
72
pub trait Clean < T > {
69
73
fn clean ( & self , cx : & DocContext ) -> T ;
70
74
}
@@ -188,6 +192,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
188
192
attrs : child. attrs . clone ( ) ,
189
193
visibility : Some ( hir:: Public ) ,
190
194
stability : None ,
195
+ deprecation : None ,
191
196
def_id : DefId :: local ( prim. to_def_index ( ) ) ,
192
197
inner : PrimitiveItem ( prim) ,
193
198
} ) ;
@@ -254,6 +259,7 @@ pub struct Item {
254
259
pub visibility : Option < Visibility > ,
255
260
pub def_id : DefId ,
256
261
pub stability : Option < Stability > ,
262
+ pub deprecation : Option < Deprecation > ,
257
263
}
258
264
259
265
impl Item {
@@ -417,6 +423,7 @@ impl Clean<Item> for doctree::Module {
417
423
source : whence. clean ( cx) ,
418
424
visibility : self . vis . clean ( cx) ,
419
425
stability : self . stab . clean ( cx) ,
426
+ deprecation : self . depr . clean ( cx) ,
420
427
def_id : cx. map . local_def_id ( self . id ) ,
421
428
inner : ModuleItem ( Module {
422
429
is_crate : self . is_crate ,
@@ -1078,6 +1085,7 @@ impl Clean<Item> for doctree::Function {
1078
1085
source : self . whence . clean ( cx) ,
1079
1086
visibility : self . vis . clean ( cx) ,
1080
1087
stability : self . stab . clean ( cx) ,
1088
+ deprecation : self . depr . clean ( cx) ,
1081
1089
def_id : cx. map . local_def_id ( self . id ) ,
1082
1090
inner : FunctionItem ( Function {
1083
1091
decl : self . decl . clean ( cx) ,
@@ -1204,6 +1212,7 @@ impl Clean<Item> for doctree::Trait {
1204
1212
def_id : cx. map . local_def_id ( self . id ) ,
1205
1213
visibility : self . vis . clean ( cx) ,
1206
1214
stability : self . stab . clean ( cx) ,
1215
+ deprecation : self . depr . clean ( cx) ,
1207
1216
inner : TraitItem ( Trait {
1208
1217
unsafety : self . unsafety ,
1209
1218
items : self . items . clean ( cx) ,
@@ -1254,6 +1263,7 @@ impl Clean<Item> for hir::TraitItem {
1254
1263
def_id : cx. map . local_def_id ( self . id ) ,
1255
1264
visibility : None ,
1256
1265
stability : get_stability ( cx, cx. map . local_def_id ( self . id ) ) ,
1266
+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . id ) ) ,
1257
1267
inner : inner
1258
1268
}
1259
1269
}
@@ -1287,6 +1297,7 @@ impl Clean<Item> for hir::ImplItem {
1287
1297
def_id : cx. map . local_def_id ( self . id ) ,
1288
1298
visibility : self . vis . clean ( cx) ,
1289
1299
stability : get_stability ( cx, cx. map . local_def_id ( self . id ) ) ,
1300
+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . id ) ) ,
1290
1301
inner : inner
1291
1302
}
1292
1303
}
@@ -1357,6 +1368,7 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
1357
1368
name : Some ( self . name . clean ( cx) ) ,
1358
1369
visibility : Some ( hir:: Inherited ) ,
1359
1370
stability : get_stability ( cx, self . def_id ) ,
1371
+ deprecation : get_deprecation ( cx, self . def_id ) ,
1360
1372
def_id : self . def_id ,
1361
1373
attrs : inline:: load_attrs ( cx, cx. tcx ( ) , self . def_id ) ,
1362
1374
source : Span :: empty ( ) ,
@@ -1715,6 +1727,7 @@ impl Clean<Item> for hir::StructField {
1715
1727
source : self . span . clean ( cx) ,
1716
1728
visibility : Some ( vis) ,
1717
1729
stability : get_stability ( cx, cx. map . local_def_id ( self . node . id ) ) ,
1730
+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . node . id ) ) ,
1718
1731
def_id : cx. map . local_def_id ( self . node . id ) ,
1719
1732
inner : StructFieldItem ( TypedStructField ( self . node . ty . clean ( cx) ) ) ,
1720
1733
}
@@ -1740,6 +1753,7 @@ impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
1740
1753
source : Span :: empty ( ) ,
1741
1754
visibility : Some ( self . vis ) ,
1742
1755
stability : get_stability ( cx, self . did ) ,
1756
+ deprecation : get_deprecation ( cx, self . did ) ,
1743
1757
def_id : self . did ,
1744
1758
inner : StructFieldItem ( TypedStructField ( self . unsubst_ty ( ) . clean ( cx) ) ) ,
1745
1759
}
@@ -1771,6 +1785,7 @@ impl Clean<Item> for doctree::Struct {
1771
1785
def_id : cx. map . local_def_id ( self . id ) ,
1772
1786
visibility : self . vis . clean ( cx) ,
1773
1787
stability : self . stab . clean ( cx) ,
1788
+ deprecation : self . depr . clean ( cx) ,
1774
1789
inner : StructItem ( Struct {
1775
1790
struct_type : self . struct_type ,
1776
1791
generics : self . generics . clean ( cx) ,
@@ -1817,6 +1832,7 @@ impl Clean<Item> for doctree::Enum {
1817
1832
def_id : cx. map . local_def_id ( self . id ) ,
1818
1833
visibility : self . vis . clean ( cx) ,
1819
1834
stability : self . stab . clean ( cx) ,
1835
+ deprecation : self . depr . clean ( cx) ,
1820
1836
inner : EnumItem ( Enum {
1821
1837
variants : self . variants . clean ( cx) ,
1822
1838
generics : self . generics . clean ( cx) ,
@@ -1839,6 +1855,7 @@ impl Clean<Item> for doctree::Variant {
1839
1855
source : self . whence . clean ( cx) ,
1840
1856
visibility : None ,
1841
1857
stability : self . stab . clean ( cx) ,
1858
+ deprecation : self . depr . clean ( cx) ,
1842
1859
def_id : cx. map . local_def_id ( self . def . id ( ) ) ,
1843
1860
inner : VariantItem ( Variant {
1844
1861
kind : struct_def_to_variant_kind ( & self . def , cx) ,
@@ -1876,6 +1893,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
1876
1893
// at the needed information here.
1877
1894
def_id : self . did ,
1878
1895
stability : get_stability ( cx, self . did ) ,
1896
+ deprecation : get_deprecation ( cx, self . did ) ,
1879
1897
inner : StructFieldItem (
1880
1898
TypedStructField ( field. unsubst_ty ( ) . clean ( cx) )
1881
1899
)
@@ -1892,6 +1910,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
1892
1910
def_id : self . did ,
1893
1911
inner : VariantItem ( Variant { kind : kind } ) ,
1894
1912
stability : get_stability ( cx, self . did ) ,
1913
+ deprecation : get_deprecation ( cx, self . did ) ,
1895
1914
}
1896
1915
}
1897
1916
}
@@ -2067,6 +2086,7 @@ impl Clean<Item> for doctree::Typedef {
2067
2086
def_id : cx. map . local_def_id ( self . id . clone ( ) ) ,
2068
2087
visibility : self . vis . clean ( cx) ,
2069
2088
stability : self . stab . clean ( cx) ,
2089
+ deprecation : self . depr . clean ( cx) ,
2070
2090
inner : TypedefItem ( Typedef {
2071
2091
type_ : self . ty . clean ( cx) ,
2072
2092
generics : self . gen . clean ( cx) ,
@@ -2118,6 +2138,7 @@ impl Clean<Item> for doctree::Static {
2118
2138
def_id : cx. map . local_def_id ( self . id ) ,
2119
2139
visibility : self . vis . clean ( cx) ,
2120
2140
stability : self . stab . clean ( cx) ,
2141
+ deprecation : self . depr . clean ( cx) ,
2121
2142
inner : StaticItem ( Static {
2122
2143
type_ : self . type_ . clean ( cx) ,
2123
2144
mutability : self . mutability . clean ( cx) ,
@@ -2142,6 +2163,7 @@ impl Clean<Item> for doctree::Constant {
2142
2163
def_id : cx. map . local_def_id ( self . id ) ,
2143
2164
visibility : self . vis . clean ( cx) ,
2144
2165
stability : self . stab . clean ( cx) ,
2166
+ deprecation : self . depr . clean ( cx) ,
2145
2167
inner : ConstantItem ( Constant {
2146
2168
type_ : self . type_ . clean ( cx) ,
2147
2169
expr : self . expr . span . to_src ( cx) ,
@@ -2216,6 +2238,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
2216
2238
def_id : cx. map . local_def_id ( self . id ) ,
2217
2239
visibility : self . vis . clean ( cx) ,
2218
2240
stability : self . stab . clean ( cx) ,
2241
+ deprecation : self . depr . clean ( cx) ,
2219
2242
inner : ImplItem ( Impl {
2220
2243
unsafety : self . unsafety ,
2221
2244
generics : self . generics . clean ( cx) ,
@@ -2298,6 +2321,7 @@ impl Clean<Item> for doctree::DefaultImpl {
2298
2321
def_id : cx. map . local_def_id ( self . id ) ,
2299
2322
visibility : Some ( hir:: Public ) ,
2300
2323
stability : None ,
2324
+ deprecation : None ,
2301
2325
inner : DefaultImplItem ( DefaultImpl {
2302
2326
unsafety : self . unsafety ,
2303
2327
trait_ : self . trait_ . clean ( cx) ,
@@ -2315,6 +2339,7 @@ impl Clean<Item> for doctree::ExternCrate {
2315
2339
def_id : cx. map . local_def_id ( 0 ) ,
2316
2340
visibility : self . vis . clean ( cx) ,
2317
2341
stability : None ,
2342
+ deprecation : None ,
2318
2343
inner : ExternCrateItem ( self . name . clean ( cx) , self . path . clone ( ) )
2319
2344
}
2320
2345
}
@@ -2380,6 +2405,7 @@ impl Clean<Vec<Item>> for doctree::Import {
2380
2405
def_id : cx. map . local_def_id ( 0 ) ,
2381
2406
visibility : self . vis . clean ( cx) ,
2382
2407
stability : None ,
2408
+ deprecation : None ,
2383
2409
inner : ImportItem ( inner)
2384
2410
} ) ;
2385
2411
ret
@@ -2466,6 +2492,7 @@ impl Clean<Item> for hir::ForeignItem {
2466
2492
def_id : cx. map . local_def_id ( self . id ) ,
2467
2493
visibility : self . vis . clean ( cx) ,
2468
2494
stability : get_stability ( cx, cx. map . local_def_id ( self . id ) ) ,
2495
+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . id ) ) ,
2469
2496
inner : inner,
2470
2497
}
2471
2498
}
@@ -2659,6 +2686,7 @@ impl Clean<Item> for doctree::Macro {
2659
2686
source : self . whence . clean ( cx) ,
2660
2687
visibility : hir:: Public . clean ( cx) ,
2661
2688
stability : self . stab . clean ( cx) ,
2689
+ deprecation : self . depr . clean ( cx) ,
2662
2690
def_id : cx. map . local_def_id ( self . id ) ,
2663
2691
inner : MacroItem ( Macro {
2664
2692
source : format ! ( "macro_rules! {} {{\n {}}}" ,
@@ -2680,6 +2708,12 @@ pub struct Stability {
2680
2708
pub issue : Option < u32 >
2681
2709
}
2682
2710
2711
+ #[ derive( Clone , RustcEncodable , RustcDecodable , Debug ) ]
2712
+ pub struct Deprecation {
2713
+ pub since : String ,
2714
+ pub note : String ,
2715
+ }
2716
+
2683
2717
impl Clean < Stability > for attr:: Stability {
2684
2718
fn clean ( & self , _: & DocContext ) -> Stability {
2685
2719
Stability {
@@ -2716,6 +2750,15 @@ impl<'a> Clean<Stability> for &'a attr::Stability {
2716
2750
}
2717
2751
}
2718
2752
2753
+ impl Clean < Deprecation > for attr:: Deprecation {
2754
+ fn clean ( & self , _: & DocContext ) -> Deprecation {
2755
+ Deprecation {
2756
+ since : self . since . as_ref ( ) . map_or ( "" . to_string ( ) , |s| s. to_string ( ) ) ,
2757
+ note : self . note . as_ref ( ) . map_or ( "" . to_string ( ) , |s| s. to_string ( ) ) ,
2758
+ }
2759
+ }
2760
+ }
2761
+
2719
2762
impl < ' tcx > Clean < Item > for ty:: AssociatedConst < ' tcx > {
2720
2763
fn clean ( & self , cx : & DocContext ) -> Item {
2721
2764
Item {
@@ -2726,6 +2769,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedConst<'tcx> {
2726
2769
visibility : None ,
2727
2770
def_id : self . def_id ,
2728
2771
stability : None ,
2772
+ deprecation : None ,
2729
2773
}
2730
2774
}
2731
2775
}
@@ -2783,6 +2827,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedType<'tcx> {
2783
2827
visibility : self . vis . clean ( cx) ,
2784
2828
def_id : self . def_id ,
2785
2829
stability : stability:: lookup_stability ( cx. tcx ( ) , self . def_id ) . clean ( cx) ,
2830
+ deprecation : stability:: lookup_deprecation ( cx. tcx ( ) , self . def_id ) . clean ( cx) ,
2786
2831
}
2787
2832
}
2788
2833
}
0 commit comments