Skip to content

Commit 67a9784

Browse files
committed
Support #[deprecated] in rustdoc
1 parent 105bd15 commit 67a9784

File tree

7 files changed

+121
-4
lines changed

7 files changed

+121
-4
lines changed

src/librustdoc/clean/inline.rs

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
121121
inner: inner,
122122
visibility: Some(hir::Public),
123123
stability: stability::lookup_stability(tcx, did).clean(cx),
124+
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
124125
def_id: did,
125126
});
126127
Some(ret)
@@ -304,6 +305,7 @@ pub fn build_impl(cx: &DocContext,
304305
attrs: attrs,
305306
visibility: Some(hir::Inherited),
306307
stability: stability::lookup_stability(tcx, did).clean(cx),
308+
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
307309
def_id: did,
308310
});
309311
}
@@ -334,6 +336,7 @@ pub fn build_impl(cx: &DocContext,
334336
attrs: vec![],
335337
visibility: None,
336338
stability: stability::lookup_stability(tcx, did).clean(cx),
339+
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
337340
def_id: did
338341
})
339342
}
@@ -382,6 +385,7 @@ pub fn build_impl(cx: &DocContext,
382385
attrs: vec![],
383386
visibility: None,
384387
stability: stability::lookup_stability(tcx, did).clean(cx),
388+
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
385389
def_id: did
386390
})
387391
}
@@ -415,6 +419,7 @@ pub fn build_impl(cx: &DocContext,
415419
attrs: attrs,
416420
visibility: Some(hir::Inherited),
417421
stability: stability::lookup_stability(tcx, did).clean(cx),
422+
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
418423
def_id: did,
419424
});
420425

src/librustdoc/clean/mod.rs

+45
Original file line numberDiff line numberDiff line change
@@ -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+
6872
pub 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

259265
impl 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+
26832717
impl 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+
27192762
impl<'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
}

src/librustdoc/doctree.rs

+12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct Module {
4040
pub traits: Vec<Trait>,
4141
pub vis: hir::Visibility,
4242
pub stab: Option<attr::Stability>,
43+
pub depr: Option<attr::Deprecation>,
4344
pub impls: Vec<Impl>,
4445
pub def_traits: Vec<DefaultImpl>,
4546
pub foreigns: Vec<hir::ForeignMod>,
@@ -54,6 +55,7 @@ impl Module {
5455
id: 0,
5556
vis: hir::Inherited,
5657
stab: None,
58+
depr: None,
5759
where_outer: syntax::codemap::DUMMY_SP,
5860
where_inner: syntax::codemap::DUMMY_SP,
5961
attrs : Vec::new(),
@@ -96,6 +98,7 @@ pub enum TypeBound {
9698
pub struct Struct {
9799
pub vis: hir::Visibility,
98100
pub stab: Option<attr::Stability>,
101+
pub depr: Option<attr::Deprecation>,
99102
pub id: NodeId,
100103
pub struct_type: StructType,
101104
pub name: Name,
@@ -108,6 +111,7 @@ pub struct Struct {
108111
pub struct Enum {
109112
pub vis: hir::Visibility,
110113
pub stab: Option<attr::Stability>,
114+
pub depr: Option<attr::Deprecation>,
111115
pub variants: Vec<Variant>,
112116
pub generics: hir::Generics,
113117
pub attrs: Vec<ast::Attribute>,
@@ -121,6 +125,7 @@ pub struct Variant {
121125
pub attrs: Vec<ast::Attribute>,
122126
pub def: hir::VariantData,
123127
pub stab: Option<attr::Stability>,
128+
pub depr: Option<attr::Deprecation>,
124129
pub whence: Span,
125130
}
126131

@@ -131,6 +136,7 @@ pub struct Function {
131136
pub name: Name,
132137
pub vis: hir::Visibility,
133138
pub stab: Option<attr::Stability>,
139+
pub depr: Option<attr::Deprecation>,
134140
pub unsafety: hir::Unsafety,
135141
pub constness: hir::Constness,
136142
pub whence: Span,
@@ -147,6 +153,7 @@ pub struct Typedef {
147153
pub whence: Span,
148154
pub vis: hir::Visibility,
149155
pub stab: Option<attr::Stability>,
156+
pub depr: Option<attr::Deprecation>,
150157
}
151158

152159
#[derive(Debug)]
@@ -158,6 +165,7 @@ pub struct Static {
158165
pub attrs: Vec<ast::Attribute>,
159166
pub vis: hir::Visibility,
160167
pub stab: Option<attr::Stability>,
168+
pub depr: Option<attr::Deprecation>,
161169
pub id: ast::NodeId,
162170
pub whence: Span,
163171
}
@@ -169,6 +177,7 @@ pub struct Constant {
169177
pub attrs: Vec<ast::Attribute>,
170178
pub vis: hir::Visibility,
171179
pub stab: Option<attr::Stability>,
180+
pub depr: Option<attr::Deprecation>,
172181
pub id: ast::NodeId,
173182
pub whence: Span,
174183
}
@@ -184,6 +193,7 @@ pub struct Trait {
184193
pub whence: Span,
185194
pub vis: hir::Visibility,
186195
pub stab: Option<attr::Stability>,
196+
pub depr: Option<attr::Deprecation>,
187197
}
188198

189199
pub struct Impl {
@@ -197,6 +207,7 @@ pub struct Impl {
197207
pub whence: Span,
198208
pub vis: hir::Visibility,
199209
pub stab: Option<attr::Stability>,
210+
pub depr: Option<attr::Deprecation>,
200211
pub id: ast::NodeId,
201212
}
202213

@@ -215,6 +226,7 @@ pub struct Macro {
215226
pub whence: Span,
216227
pub matchers: Vec<Span>,
217228
pub stab: Option<attr::Stability>,
229+
pub depr: Option<attr::Deprecation>,
218230
pub imported_from: Option<Name>,
219231
}
220232

0 commit comments

Comments
 (0)