@@ -65,6 +65,10 @@ fn get_stability(cx: &DocContext, def_id: DefId) -> Option<Stability> {
6565 cx. tcx_opt ( ) . and_then ( |tcx| stability:: lookup_stability ( tcx, def_id) ) . clean ( cx)
6666}
6767
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+
6872pub trait Clean < T > {
6973 fn clean ( & self , cx : & DocContext ) -> T ;
7074}
@@ -188,6 +192,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
188192 attrs : child. attrs . clone ( ) ,
189193 visibility : Some ( hir:: Public ) ,
190194 stability : None ,
195+ deprecation : None ,
191196 def_id : DefId :: local ( prim. to_def_index ( ) ) ,
192197 inner : PrimitiveItem ( prim) ,
193198 } ) ;
@@ -254,6 +259,7 @@ pub struct Item {
254259 pub visibility : Option < Visibility > ,
255260 pub def_id : DefId ,
256261 pub stability : Option < Stability > ,
262+ pub deprecation : Option < Deprecation > ,
257263}
258264
259265impl Item {
@@ -417,6 +423,7 @@ impl Clean<Item> for doctree::Module {
417423 source : whence. clean ( cx) ,
418424 visibility : self . vis . clean ( cx) ,
419425 stability : self . stab . clean ( cx) ,
426+ deprecation : self . depr . clean ( cx) ,
420427 def_id : cx. map . local_def_id ( self . id ) ,
421428 inner : ModuleItem ( Module {
422429 is_crate : self . is_crate ,
@@ -1078,6 +1085,7 @@ impl Clean<Item> for doctree::Function {
10781085 source : self . whence . clean ( cx) ,
10791086 visibility : self . vis . clean ( cx) ,
10801087 stability : self . stab . clean ( cx) ,
1088+ deprecation : self . depr . clean ( cx) ,
10811089 def_id : cx. map . local_def_id ( self . id ) ,
10821090 inner : FunctionItem ( Function {
10831091 decl : self . decl . clean ( cx) ,
@@ -1204,6 +1212,7 @@ impl Clean<Item> for doctree::Trait {
12041212 def_id : cx. map . local_def_id ( self . id ) ,
12051213 visibility : self . vis . clean ( cx) ,
12061214 stability : self . stab . clean ( cx) ,
1215+ deprecation : self . depr . clean ( cx) ,
12071216 inner : TraitItem ( Trait {
12081217 unsafety : self . unsafety ,
12091218 items : self . items . clean ( cx) ,
@@ -1254,6 +1263,7 @@ impl Clean<Item> for hir::TraitItem {
12541263 def_id : cx. map . local_def_id ( self . id ) ,
12551264 visibility : None ,
12561265 stability : get_stability ( cx, cx. map . local_def_id ( self . id ) ) ,
1266+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . id ) ) ,
12571267 inner : inner
12581268 }
12591269 }
@@ -1287,6 +1297,7 @@ impl Clean<Item> for hir::ImplItem {
12871297 def_id : cx. map . local_def_id ( self . id ) ,
12881298 visibility : self . vis . clean ( cx) ,
12891299 stability : get_stability ( cx, cx. map . local_def_id ( self . id ) ) ,
1300+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . id ) ) ,
12901301 inner : inner
12911302 }
12921303 }
@@ -1357,6 +1368,7 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
13571368 name : Some ( self . name . clean ( cx) ) ,
13581369 visibility : Some ( hir:: Inherited ) ,
13591370 stability : get_stability ( cx, self . def_id ) ,
1371+ deprecation : get_deprecation ( cx, self . def_id ) ,
13601372 def_id : self . def_id ,
13611373 attrs : inline:: load_attrs ( cx, cx. tcx ( ) , self . def_id ) ,
13621374 source : Span :: empty ( ) ,
@@ -1715,6 +1727,7 @@ impl Clean<Item> for hir::StructField {
17151727 source : self . span . clean ( cx) ,
17161728 visibility : Some ( vis) ,
17171729 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 ) ) ,
17181731 def_id : cx. map . local_def_id ( self . node . id ) ,
17191732 inner : StructFieldItem ( TypedStructField ( self . node . ty . clean ( cx) ) ) ,
17201733 }
@@ -1740,6 +1753,7 @@ impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
17401753 source : Span :: empty ( ) ,
17411754 visibility : Some ( self . vis ) ,
17421755 stability : get_stability ( cx, self . did ) ,
1756+ deprecation : get_deprecation ( cx, self . did ) ,
17431757 def_id : self . did ,
17441758 inner : StructFieldItem ( TypedStructField ( self . unsubst_ty ( ) . clean ( cx) ) ) ,
17451759 }
@@ -1771,6 +1785,7 @@ impl Clean<Item> for doctree::Struct {
17711785 def_id : cx. map . local_def_id ( self . id ) ,
17721786 visibility : self . vis . clean ( cx) ,
17731787 stability : self . stab . clean ( cx) ,
1788+ deprecation : self . depr . clean ( cx) ,
17741789 inner : StructItem ( Struct {
17751790 struct_type : self . struct_type ,
17761791 generics : self . generics . clean ( cx) ,
@@ -1817,6 +1832,7 @@ impl Clean<Item> for doctree::Enum {
18171832 def_id : cx. map . local_def_id ( self . id ) ,
18181833 visibility : self . vis . clean ( cx) ,
18191834 stability : self . stab . clean ( cx) ,
1835+ deprecation : self . depr . clean ( cx) ,
18201836 inner : EnumItem ( Enum {
18211837 variants : self . variants . clean ( cx) ,
18221838 generics : self . generics . clean ( cx) ,
@@ -1839,6 +1855,7 @@ impl Clean<Item> for doctree::Variant {
18391855 source : self . whence . clean ( cx) ,
18401856 visibility : None ,
18411857 stability : self . stab . clean ( cx) ,
1858+ deprecation : self . depr . clean ( cx) ,
18421859 def_id : cx. map . local_def_id ( self . def . id ( ) ) ,
18431860 inner : VariantItem ( Variant {
18441861 kind : struct_def_to_variant_kind ( & self . def , cx) ,
@@ -1876,6 +1893,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
18761893 // at the needed information here.
18771894 def_id : self . did ,
18781895 stability : get_stability ( cx, self . did ) ,
1896+ deprecation : get_deprecation ( cx, self . did ) ,
18791897 inner : StructFieldItem (
18801898 TypedStructField ( field. unsubst_ty ( ) . clean ( cx) )
18811899 )
@@ -1892,6 +1910,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
18921910 def_id : self . did ,
18931911 inner : VariantItem ( Variant { kind : kind } ) ,
18941912 stability : get_stability ( cx, self . did ) ,
1913+ deprecation : get_deprecation ( cx, self . did ) ,
18951914 }
18961915 }
18971916}
@@ -2067,6 +2086,7 @@ impl Clean<Item> for doctree::Typedef {
20672086 def_id : cx. map . local_def_id ( self . id . clone ( ) ) ,
20682087 visibility : self . vis . clean ( cx) ,
20692088 stability : self . stab . clean ( cx) ,
2089+ deprecation : self . depr . clean ( cx) ,
20702090 inner : TypedefItem ( Typedef {
20712091 type_ : self . ty . clean ( cx) ,
20722092 generics : self . gen . clean ( cx) ,
@@ -2118,6 +2138,7 @@ impl Clean<Item> for doctree::Static {
21182138 def_id : cx. map . local_def_id ( self . id ) ,
21192139 visibility : self . vis . clean ( cx) ,
21202140 stability : self . stab . clean ( cx) ,
2141+ deprecation : self . depr . clean ( cx) ,
21212142 inner : StaticItem ( Static {
21222143 type_ : self . type_ . clean ( cx) ,
21232144 mutability : self . mutability . clean ( cx) ,
@@ -2142,6 +2163,7 @@ impl Clean<Item> for doctree::Constant {
21422163 def_id : cx. map . local_def_id ( self . id ) ,
21432164 visibility : self . vis . clean ( cx) ,
21442165 stability : self . stab . clean ( cx) ,
2166+ deprecation : self . depr . clean ( cx) ,
21452167 inner : ConstantItem ( Constant {
21462168 type_ : self . type_ . clean ( cx) ,
21472169 expr : self . expr . span . to_src ( cx) ,
@@ -2216,6 +2238,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
22162238 def_id : cx. map . local_def_id ( self . id ) ,
22172239 visibility : self . vis . clean ( cx) ,
22182240 stability : self . stab . clean ( cx) ,
2241+ deprecation : self . depr . clean ( cx) ,
22192242 inner : ImplItem ( Impl {
22202243 unsafety : self . unsafety ,
22212244 generics : self . generics . clean ( cx) ,
@@ -2298,6 +2321,7 @@ impl Clean<Item> for doctree::DefaultImpl {
22982321 def_id : cx. map . local_def_id ( self . id ) ,
22992322 visibility : Some ( hir:: Public ) ,
23002323 stability : None ,
2324+ deprecation : None ,
23012325 inner : DefaultImplItem ( DefaultImpl {
23022326 unsafety : self . unsafety ,
23032327 trait_ : self . trait_ . clean ( cx) ,
@@ -2315,6 +2339,7 @@ impl Clean<Item> for doctree::ExternCrate {
23152339 def_id : cx. map . local_def_id ( 0 ) ,
23162340 visibility : self . vis . clean ( cx) ,
23172341 stability : None ,
2342+ deprecation : None ,
23182343 inner : ExternCrateItem ( self . name . clean ( cx) , self . path . clone ( ) )
23192344 }
23202345 }
@@ -2380,6 +2405,7 @@ impl Clean<Vec<Item>> for doctree::Import {
23802405 def_id : cx. map . local_def_id ( 0 ) ,
23812406 visibility : self . vis . clean ( cx) ,
23822407 stability : None ,
2408+ deprecation : None ,
23832409 inner : ImportItem ( inner)
23842410 } ) ;
23852411 ret
@@ -2466,6 +2492,7 @@ impl Clean<Item> for hir::ForeignItem {
24662492 def_id : cx. map . local_def_id ( self . id ) ,
24672493 visibility : self . vis . clean ( cx) ,
24682494 stability : get_stability ( cx, cx. map . local_def_id ( self . id ) ) ,
2495+ deprecation : get_deprecation ( cx, cx. map . local_def_id ( self . id ) ) ,
24692496 inner : inner,
24702497 }
24712498 }
@@ -2659,6 +2686,7 @@ impl Clean<Item> for doctree::Macro {
26592686 source : self . whence . clean ( cx) ,
26602687 visibility : hir:: Public . clean ( cx) ,
26612688 stability : self . stab . clean ( cx) ,
2689+ deprecation : self . depr . clean ( cx) ,
26622690 def_id : cx. map . local_def_id ( self . id ) ,
26632691 inner : MacroItem ( Macro {
26642692 source : format ! ( "macro_rules! {} {{\n {}}}" ,
@@ -2680,6 +2708,12 @@ pub struct Stability {
26802708 pub issue : Option < u32 >
26812709}
26822710
2711+ #[ derive( Clone , RustcEncodable , RustcDecodable , Debug ) ]
2712+ pub struct Deprecation {
2713+ pub since : String ,
2714+ pub note : String ,
2715+ }
2716+
26832717impl Clean < Stability > for attr:: Stability {
26842718 fn clean ( & self , _: & DocContext ) -> Stability {
26852719 Stability {
@@ -2716,6 +2750,15 @@ impl<'a> Clean<Stability> for &'a attr::Stability {
27162750 }
27172751}
27182752
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+
27192762impl < ' tcx > Clean < Item > for ty:: AssociatedConst < ' tcx > {
27202763 fn clean ( & self , cx : & DocContext ) -> Item {
27212764 Item {
@@ -2726,6 +2769,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedConst<'tcx> {
27262769 visibility : None ,
27272770 def_id : self . def_id ,
27282771 stability : None ,
2772+ deprecation : None ,
27292773 }
27302774 }
27312775}
@@ -2783,6 +2827,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedType<'tcx> {
27832827 visibility : self . vis . clean ( cx) ,
27842828 def_id : self . def_id ,
27852829 stability : stability:: lookup_stability ( cx. tcx ( ) , self . def_id ) . clean ( cx) ,
2830+ deprecation : stability:: lookup_deprecation ( cx. tcx ( ) , self . def_id ) . clean ( cx) ,
27862831 }
27872832 }
27882833}
0 commit comments