Skip to content

Commit

Permalink
Support #[deprecated] in rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 12, 2015
1 parent 105bd15 commit 67a9784
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
inner: inner,
visibility: Some(hir::Public),
stability: stability::lookup_stability(tcx, did).clean(cx),
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
def_id: did,
});
Some(ret)
Expand Down Expand Up @@ -304,6 +305,7 @@ pub fn build_impl(cx: &DocContext,
attrs: attrs,
visibility: Some(hir::Inherited),
stability: stability::lookup_stability(tcx, did).clean(cx),
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
def_id: did,
});
}
Expand Down Expand Up @@ -334,6 +336,7 @@ pub fn build_impl(cx: &DocContext,
attrs: vec![],
visibility: None,
stability: stability::lookup_stability(tcx, did).clean(cx),
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
def_id: did
})
}
Expand Down Expand Up @@ -382,6 +385,7 @@ pub fn build_impl(cx: &DocContext,
attrs: vec![],
visibility: None,
stability: stability::lookup_stability(tcx, did).clean(cx),
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
def_id: did
})
}
Expand Down Expand Up @@ -415,6 +419,7 @@ pub fn build_impl(cx: &DocContext,
attrs: attrs,
visibility: Some(hir::Inherited),
stability: stability::lookup_stability(tcx, did).clean(cx),
deprecation: stability::lookup_deprecation(tcx, did).clean(cx),
def_id: did,
});

Expand Down
45 changes: 45 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ fn get_stability(cx: &DocContext, def_id: DefId) -> Option<Stability> {
cx.tcx_opt().and_then(|tcx| stability::lookup_stability(tcx, def_id)).clean(cx)
}

fn get_deprecation(cx: &DocContext, def_id: DefId) -> Option<Deprecation> {
cx.tcx_opt().and_then(|tcx| stability::lookup_deprecation(tcx, def_id)).clean(cx)
}

pub trait Clean<T> {
fn clean(&self, cx: &DocContext) -> T;
}
Expand Down Expand Up @@ -188,6 +192,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
attrs: child.attrs.clone(),
visibility: Some(hir::Public),
stability: None,
deprecation: None,
def_id: DefId::local(prim.to_def_index()),
inner: PrimitiveItem(prim),
});
Expand Down Expand Up @@ -254,6 +259,7 @@ pub struct Item {
pub visibility: Option<Visibility>,
pub def_id: DefId,
pub stability: Option<Stability>,
pub deprecation: Option<Deprecation>,
}

impl Item {
Expand Down Expand Up @@ -417,6 +423,7 @@ impl Clean<Item> for doctree::Module {
source: whence.clean(cx),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
def_id: cx.map.local_def_id(self.id),
inner: ModuleItem(Module {
is_crate: self.is_crate,
Expand Down Expand Up @@ -1078,6 +1085,7 @@ impl Clean<Item> for doctree::Function {
source: self.whence.clean(cx),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
def_id: cx.map.local_def_id(self.id),
inner: FunctionItem(Function {
decl: self.decl.clean(cx),
Expand Down Expand Up @@ -1204,6 +1212,7 @@ impl Clean<Item> for doctree::Trait {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: TraitItem(Trait {
unsafety: self.unsafety,
items: self.items.clean(cx),
Expand Down Expand Up @@ -1254,6 +1263,7 @@ impl Clean<Item> for hir::TraitItem {
def_id: cx.map.local_def_id(self.id),
visibility: None,
stability: get_stability(cx, cx.map.local_def_id(self.id)),
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
inner: inner
}
}
Expand Down Expand Up @@ -1287,6 +1297,7 @@ impl Clean<Item> for hir::ImplItem {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: get_stability(cx, cx.map.local_def_id(self.id)),
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
inner: inner
}
}
Expand Down Expand Up @@ -1357,6 +1368,7 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
name: Some(self.name.clean(cx)),
visibility: Some(hir::Inherited),
stability: get_stability(cx, self.def_id),
deprecation: get_deprecation(cx, self.def_id),
def_id: self.def_id,
attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
source: Span::empty(),
Expand Down Expand Up @@ -1715,6 +1727,7 @@ impl Clean<Item> for hir::StructField {
source: self.span.clean(cx),
visibility: Some(vis),
stability: get_stability(cx, cx.map.local_def_id(self.node.id)),
deprecation: get_deprecation(cx, cx.map.local_def_id(self.node.id)),
def_id: cx.map.local_def_id(self.node.id),
inner: StructFieldItem(TypedStructField(self.node.ty.clean(cx))),
}
Expand All @@ -1740,6 +1753,7 @@ impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
source: Span::empty(),
visibility: Some(self.vis),
stability: get_stability(cx, self.did),
deprecation: get_deprecation(cx, self.did),
def_id: self.did,
inner: StructFieldItem(TypedStructField(self.unsubst_ty().clean(cx))),
}
Expand Down Expand Up @@ -1771,6 +1785,7 @@ impl Clean<Item> for doctree::Struct {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: StructItem(Struct {
struct_type: self.struct_type,
generics: self.generics.clean(cx),
Expand Down Expand Up @@ -1817,6 +1832,7 @@ impl Clean<Item> for doctree::Enum {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: EnumItem(Enum {
variants: self.variants.clean(cx),
generics: self.generics.clean(cx),
Expand All @@ -1839,6 +1855,7 @@ impl Clean<Item> for doctree::Variant {
source: self.whence.clean(cx),
visibility: None,
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
def_id: cx.map.local_def_id(self.def.id()),
inner: VariantItem(Variant {
kind: struct_def_to_variant_kind(&self.def, cx),
Expand Down Expand Up @@ -1876,6 +1893,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
// at the needed information here.
def_id: self.did,
stability: get_stability(cx, self.did),
deprecation: get_deprecation(cx, self.did),
inner: StructFieldItem(
TypedStructField(field.unsubst_ty().clean(cx))
)
Expand All @@ -1892,6 +1910,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
def_id: self.did,
inner: VariantItem(Variant { kind: kind }),
stability: get_stability(cx, self.did),
deprecation: get_deprecation(cx, self.did),
}
}
}
Expand Down Expand Up @@ -2067,6 +2086,7 @@ impl Clean<Item> for doctree::Typedef {
def_id: cx.map.local_def_id(self.id.clone()),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: TypedefItem(Typedef {
type_: self.ty.clean(cx),
generics: self.gen.clean(cx),
Expand Down Expand Up @@ -2118,6 +2138,7 @@ impl Clean<Item> for doctree::Static {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: StaticItem(Static {
type_: self.type_.clean(cx),
mutability: self.mutability.clean(cx),
Expand All @@ -2142,6 +2163,7 @@ impl Clean<Item> for doctree::Constant {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: ConstantItem(Constant {
type_: self.type_.clean(cx),
expr: self.expr.span.to_src(cx),
Expand Down Expand Up @@ -2216,6 +2238,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: ImplItem(Impl {
unsafety: self.unsafety,
generics: self.generics.clean(cx),
Expand Down Expand Up @@ -2298,6 +2321,7 @@ impl Clean<Item> for doctree::DefaultImpl {
def_id: cx.map.local_def_id(self.id),
visibility: Some(hir::Public),
stability: None,
deprecation: None,
inner: DefaultImplItem(DefaultImpl {
unsafety: self.unsafety,
trait_: self.trait_.clean(cx),
Expand All @@ -2315,6 +2339,7 @@ impl Clean<Item> for doctree::ExternCrate {
def_id: cx.map.local_def_id(0),
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
}
}
Expand Down Expand Up @@ -2380,6 +2405,7 @@ impl Clean<Vec<Item>> for doctree::Import {
def_id: cx.map.local_def_id(0),
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,
inner: ImportItem(inner)
});
ret
Expand Down Expand Up @@ -2466,6 +2492,7 @@ impl Clean<Item> for hir::ForeignItem {
def_id: cx.map.local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: get_stability(cx, cx.map.local_def_id(self.id)),
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
inner: inner,
}
}
Expand Down Expand Up @@ -2659,6 +2686,7 @@ impl Clean<Item> for doctree::Macro {
source: self.whence.clean(cx),
visibility: hir::Public.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
def_id: cx.map.local_def_id(self.id),
inner: MacroItem(Macro {
source: format!("macro_rules! {} {{\n{}}}",
Expand All @@ -2680,6 +2708,12 @@ pub struct Stability {
pub issue: Option<u32>
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Deprecation {
pub since: String,
pub note: String,
}

impl Clean<Stability> for attr::Stability {
fn clean(&self, _: &DocContext) -> Stability {
Stability {
Expand Down Expand Up @@ -2716,6 +2750,15 @@ impl<'a> Clean<Stability> for &'a attr::Stability {
}
}

impl Clean<Deprecation> for attr::Deprecation {
fn clean(&self, _: &DocContext) -> Deprecation {
Deprecation {
since: self.since.as_ref().map_or("".to_string(), |s| s.to_string()),
note: self.note.as_ref().map_or("".to_string(), |s| s.to_string()),
}
}
}

impl<'tcx> Clean<Item> for ty::AssociatedConst<'tcx> {
fn clean(&self, cx: &DocContext) -> Item {
Item {
Expand All @@ -2726,6 +2769,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedConst<'tcx> {
visibility: None,
def_id: self.def_id,
stability: None,
deprecation: None,
}
}
}
Expand Down Expand Up @@ -2783,6 +2827,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedType<'tcx> {
visibility: self.vis.clean(cx),
def_id: self.def_id,
stability: stability::lookup_stability(cx.tcx(), self.def_id).clean(cx),
deprecation: stability::lookup_deprecation(cx.tcx(), self.def_id).clean(cx),
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct Module {
pub traits: Vec<Trait>,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub impls: Vec<Impl>,
pub def_traits: Vec<DefaultImpl>,
pub foreigns: Vec<hir::ForeignMod>,
Expand All @@ -54,6 +55,7 @@ impl Module {
id: 0,
vis: hir::Inherited,
stab: None,
depr: None,
where_outer: syntax::codemap::DUMMY_SP,
where_inner: syntax::codemap::DUMMY_SP,
attrs : Vec::new(),
Expand Down Expand Up @@ -96,6 +98,7 @@ pub enum TypeBound {
pub struct Struct {
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub id: NodeId,
pub struct_type: StructType,
pub name: Name,
Expand All @@ -108,6 +111,7 @@ pub struct Struct {
pub struct Enum {
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub variants: Vec<Variant>,
pub generics: hir::Generics,
pub attrs: Vec<ast::Attribute>,
Expand All @@ -121,6 +125,7 @@ pub struct Variant {
pub attrs: Vec<ast::Attribute>,
pub def: hir::VariantData,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub whence: Span,
}

Expand All @@ -131,6 +136,7 @@ pub struct Function {
pub name: Name,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub unsafety: hir::Unsafety,
pub constness: hir::Constness,
pub whence: Span,
Expand All @@ -147,6 +153,7 @@ pub struct Typedef {
pub whence: Span,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
}

#[derive(Debug)]
Expand All @@ -158,6 +165,7 @@ pub struct Static {
pub attrs: Vec<ast::Attribute>,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub id: ast::NodeId,
pub whence: Span,
}
Expand All @@ -169,6 +177,7 @@ pub struct Constant {
pub attrs: Vec<ast::Attribute>,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub id: ast::NodeId,
pub whence: Span,
}
Expand All @@ -184,6 +193,7 @@ pub struct Trait {
pub whence: Span,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
}

pub struct Impl {
Expand All @@ -197,6 +207,7 @@ pub struct Impl {
pub whence: Span,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub id: ast::NodeId,
}

Expand All @@ -215,6 +226,7 @@ pub struct Macro {
pub whence: Span,
pub matchers: Vec<Span>,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
pub imported_from: Option<Name>,
}

Expand Down
Loading

0 comments on commit 67a9784

Please sign in to comment.