about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-07-24 16:22:48 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2019-08-10 07:52:07 -0400
commit4beb751575b40c0425775817bfd8f9c756c27487 (patch)
treed71d1a88045f6e52e4f119426e42ca8bbf5ff03a
parent11735b6235d0f1cdccf41296c076ffb133e9f1b2 (diff)
downloadrust-4beb751575b40c0425775817bfd8f9c756c27487.tar.gz
rust-4beb751575b40c0425775817bfd8f9c756c27487.zip
Gather deprecation information during cleaning
-rw-r--r--src/librustdoc/clean/mod.rs32
-rw-r--r--src/librustdoc/core.rs5
-rw-r--r--src/librustdoc/doctree.rs18
-rw-r--r--src/librustdoc/visit_ast.rs22
4 files changed, 21 insertions, 56 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index c031e8d2bc1..bf09e8785ad 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -655,7 +655,7 @@ impl Clean<Item> for doctree::Module<'_> {
             source: whence.clean(cx),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.hid).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.hid).clean(cx),
             def_id: cx.tcx.hir().local_def_id_from_node_id(self.id),
             inner: ModuleItem(Module {
                is_crate: self.is_crate,
@@ -1941,7 +1941,7 @@ impl Clean<Item> for doctree::Function<'_> {
             source: self.whence.clean(cx),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             def_id: did,
             inner: FunctionItem(Function {
                 decl,
@@ -2141,7 +2141,7 @@ impl Clean<Item> for doctree::Trait<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: TraitItem(Trait {
                 auto: self.is_auto.clean(cx),
                 unsafety: self.unsafety,
@@ -2171,7 +2171,7 @@ impl Clean<Item> for doctree::TraitAlias<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: TraitAliasItem(TraitAlias {
                 generics: self.generics.clean(cx),
                 bounds: self.bounds.clean(cx),
@@ -3245,7 +3245,7 @@ impl Clean<Item> for doctree::Struct<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: StructItem(Struct {
                 struct_type: self.struct_type,
                 generics: self.generics.clean(cx),
@@ -3265,7 +3265,7 @@ impl Clean<Item> for doctree::Union<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: UnionItem(Union {
                 struct_type: self.struct_type,
                 generics: self.generics.clean(cx),
@@ -3312,7 +3312,7 @@ impl Clean<Item> for doctree::Enum<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: EnumItem(Enum {
                 variants: self.variants.iter().map(|v| v.clean(cx)).collect(),
                 generics: self.generics.clean(cx),
@@ -3335,7 +3335,7 @@ impl Clean<Item> for doctree::Variant<'_> {
             source: self.whence.clean(cx),
             visibility: None,
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             def_id: cx.tcx.hir().local_def_id(self.id),
             inner: VariantItem(Variant {
                 kind: self.def.clean(cx),
@@ -3640,7 +3640,7 @@ impl Clean<Item> for doctree::Typedef<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: TypedefItem(Typedef {
                 type_: self.ty.clean(cx),
                 generics: self.gen.clean(cx),
@@ -3664,7 +3664,7 @@ impl Clean<Item> for doctree::OpaqueTy<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: OpaqueTyItem(OpaqueTy {
                 bounds: self.opaque_ty.bounds.clean(cx),
                 generics: self.opaque_ty.generics.clean(cx),
@@ -3715,7 +3715,7 @@ impl Clean<Item> for doctree::Static<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: StaticItem(Static {
                 type_: self.type_.clean(cx),
                 mutability: self.mutability.clean(cx),
@@ -3740,7 +3740,7 @@ impl Clean<Item> for doctree::Constant<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: ConstantItem(Constant {
                 type_: self.type_.clean(cx),
                 expr: print_const_expr(cx, self.expr),
@@ -3827,7 +3827,7 @@ impl Clean<Vec<Item>> for doctree::Impl<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner: ImplItem(Impl {
                 unsafety: self.unsafety,
                 generics: self.generics.clean(cx),
@@ -4066,7 +4066,7 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
             def_id: cx.tcx.hir().local_def_id(self.id),
             visibility: self.vis.clean(cx),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             inner,
         }
     }
@@ -4249,7 +4249,7 @@ impl Clean<Item> for doctree::Macro<'_> {
             source: self.whence.clean(cx),
             visibility: Some(Public),
             stability: cx.stability(self.hid).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.hid).clean(cx),
             def_id: self.def_id,
             inner: MacroItem(Macro {
                 source: format!("macro_rules! {} {{\n{}}}",
@@ -4277,7 +4277,7 @@ impl Clean<Item> for doctree::ProcMacro<'_> {
             source: self.whence.clean(cx),
             visibility: Some(Public),
             stability: cx.stability(self.id).clean(cx),
-            deprecation: self.depr.clean(cx),
+            deprecation: cx.deprecation(self.id).clean(cx),
             def_id: cx.tcx.hir().local_def_id(self.id),
             inner: ProcMacroItem(ProcMacro {
                 kind: self.kind,
diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
index 976d1b0b6b1..e23a24a8dc5 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -171,6 +171,11 @@ impl<'tcx> DocContext<'tcx> {
         self.tcx.hir().opt_local_def_id(id)
             .and_then(|def_id| self.tcx.lookup_stability(def_id)).cloned()
     }
+
+    pub fn deprecation(&self, id: HirId) -> Option<attr::Deprecation> {
+        self.tcx.hir().opt_local_def_id(id)
+            .and_then(|def_id| self.tcx.lookup_deprecation(def_id))
+    }
 }
 
 pub trait DocAccessLevels {
diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs
index c380c5e08a3..39714708572 100644
--- a/src/librustdoc/doctree.rs
+++ b/src/librustdoc/doctree.rs
@@ -4,7 +4,6 @@ pub use self::StructType::*;
 
 use syntax::ast;
 use syntax::ast::{Name, NodeId};
-use syntax::attr;
 use syntax::ext::base::MacroKind;
 use syntax_pos::{self, Span};
 
@@ -32,7 +31,6 @@ pub struct Module<'hir> {
     pub constants: Vec<Constant<'hir>>,
     pub traits: Vec<Trait<'hir>>,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub impls: Vec<Impl<'hir>>,
     pub foreigns: Vec<ForeignItem<'hir>>,
     pub macros: Vec<Macro<'hir>>,
@@ -52,7 +50,6 @@ impl Module<'hir> {
             id: ast::CRATE_NODE_ID,
             hid: hir::CRATE_HIR_ID,
             vis,
-            depr: None,
             where_outer: syntax_pos::DUMMY_SP,
             where_inner: syntax_pos::DUMMY_SP,
             attrs,
@@ -90,7 +87,6 @@ pub enum StructType {
 
 pub struct Struct<'hir> {
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub id: hir::HirId,
     pub struct_type: StructType,
     pub name: Name,
@@ -102,7 +98,6 @@ pub struct Struct<'hir> {
 
 pub struct Union<'hir> {
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub id: hir::HirId,
     pub struct_type: StructType,
     pub name: Name,
@@ -114,7 +109,6 @@ pub struct Union<'hir> {
 
 pub struct Enum<'hir> {
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub variants: Vec<Variant<'hir>>,
     pub generics: &'hir hir::Generics,
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
@@ -128,7 +122,6 @@ pub struct Variant<'hir> {
     pub id: hir::HirId,
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub def: &'hir hir::VariantData,
-    pub depr: Option<attr::Deprecation>,
     pub whence: Span,
 }
 
@@ -138,7 +131,6 @@ pub struct Function<'hir> {
     pub id: hir::HirId,
     pub name: Name,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub header: hir::FnHeader,
     pub whence: Span,
     pub generics: &'hir hir::Generics,
@@ -153,7 +145,6 @@ pub struct Typedef<'hir> {
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub whence: Span,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
 }
 
 pub struct OpaqueTy<'hir> {
@@ -163,7 +154,6 @@ pub struct OpaqueTy<'hir> {
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub whence: Span,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
 }
 
 #[derive(Debug)]
@@ -174,7 +164,6 @@ pub struct Static<'hir> {
     pub name: Name,
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub id: hir::HirId,
     pub whence: Span,
 }
@@ -185,7 +174,6 @@ pub struct Constant<'hir> {
     pub name: Name,
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub id: hir::HirId,
     pub whence: Span,
 }
@@ -201,7 +189,6 @@ pub struct Trait<'hir> {
     pub id: hir::HirId,
     pub whence: Span,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
 }
 
 pub struct TraitAlias<'hir> {
@@ -212,7 +199,6 @@ pub struct TraitAlias<'hir> {
     pub id: hir::HirId,
     pub whence: Span,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
 }
 
 #[derive(Debug)]
@@ -227,13 +213,11 @@ pub struct Impl<'hir> {
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub whence: Span,
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub id: hir::HirId,
 }
 
 pub struct ForeignItem<'hir> {
     pub vis: &'hir hir::Visibility,
-    pub depr: Option<attr::Deprecation>,
     pub id: hir::HirId,
     pub name: Name,
     pub kind: &'hir hir::ForeignItemKind,
@@ -250,7 +234,6 @@ pub struct Macro<'hir> {
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub whence: Span,
     pub matchers: hir::HirVec<Span>,
-    pub depr: Option<attr::Deprecation>,
     pub imported_from: Option<Name>,
 }
 
@@ -280,7 +263,6 @@ pub struct ProcMacro<'hir> {
     pub helpers: Vec<Name>,
     pub attrs: &'hir hir::HirVec<ast::Attribute>,
     pub whence: Span,
-    pub depr: Option<attr::Deprecation>,
 }
 
 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index 56c91bf405f..002721afbc4 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -7,7 +7,6 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
 use rustc::middle::privacy::AccessLevel;
 use rustc::util::nodemap::{FxHashSet, FxHashMap};
 use syntax::ast;
-use syntax::attr;
 use syntax::ext::base::MacroKind;
 use syntax::source_map::Spanned;
 use syntax::symbol::sym;
@@ -57,11 +56,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
         }
     }
 
-    fn deprecation(&self, id: hir::HirId) -> Option<attr::Deprecation> {
-        self.cx.tcx.hir().opt_local_def_id(id)
-            .and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
-    }
-
     pub fn visit(mut self, krate: &'tcx hir::Crate) -> Module<'tcx> {
         let mut module = self.visit_mod_contents(krate.span,
                                               &krate.attrs,
@@ -91,7 +85,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             struct_type,
             name,
             vis: &item.vis,
-            depr: self.deprecation(item.hir_id),
             attrs: &item.attrs,
             generics,
             fields: sd.fields(),
@@ -109,7 +102,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             struct_type,
             name,
             vis: &item.vis,
-            depr: self.deprecation(item.hir_id),
             attrs: &item.attrs,
             generics,
             fields: sd.fields(),
@@ -127,12 +119,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                 name: v.node.ident.name,
                 id: v.node.id,
                 attrs: &v.node.attrs,
-                depr: self.deprecation(v.node.id),
                 def: &v.node.data,
                 whence: v.span,
             }).collect(),
             vis: &it.vis,
-            depr: self.deprecation(it.hir_id),
             generics,
             attrs: &it.attrs,
             id: it.hir_id,
@@ -191,14 +181,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     helpers,
                     attrs: &item.attrs,
                     whence: item.span,
-                    depr: self.deprecation(item.hir_id),
                 });
             }
             None => {
                 om.fns.push(Function {
                     id: item.hir_id,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                     attrs: &item.attrs,
                     decl,
                     name,
@@ -218,7 +206,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
         let mut om = Module::new(name, attrs, vis);
         om.where_outer = span;
         om.where_inner = m.inner;
-        om.depr = self.deprecation(id);
         om.hid = id;
         om.id = self.cx.tcx.hir().hir_to_node_id(id);
         // Keep track of if there were any private modules in the path.
@@ -449,7 +436,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     attrs: &item.attrs,
                     whence: item.span,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                 };
                 om.typedefs.push(t);
             },
@@ -461,7 +447,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     attrs: &item.attrs,
                     whence: item.span,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                 };
                 om.opaque_tys.push(t);
             },
@@ -475,7 +460,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     attrs: &item.attrs,
                     whence: item.span,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                 };
                 om.statics.push(s);
             },
@@ -488,7 +472,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     attrs: &item.attrs,
                     whence: item.span,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                 };
                 om.constants.push(s);
             },
@@ -507,7 +490,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     attrs: &item.attrs,
                     whence: item.span,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                 };
                 om.traits.push(t);
             },
@@ -520,7 +502,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                     attrs: &item.attrs,
                     whence: item.span,
                     vis: &item.vis,
-                    depr: self.deprecation(item.hir_id),
                 };
                 om.trait_aliases.push(t);
             },
@@ -550,7 +531,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                         id: item.hir_id,
                         whence: item.span,
                         vis: &item.vis,
-                        depr: self.deprecation(item.hir_id),
                     };
                     om.impls.push(i);
                 }
@@ -570,7 +550,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             name: renamed.unwrap_or(item.ident).name,
             kind: &item.node,
             vis: &item.vis,
-            depr: self.deprecation(item.hir_id),
             attrs: &item.attrs,
             whence: item.span
         });
@@ -594,7 +573,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             name: renamed.unwrap_or(def.name),
             whence: def.span,
             matchers,
-            depr: self.deprecation(def.hir_id),
             imported_from: None,
         }
     }