Skip to content

Commit 11735b6

Browse files
Gather stability information during cleaning
1 parent 6c5d212 commit 11735b6

File tree

4 files changed

+27
-55
lines changed

4 files changed

+27
-55
lines changed

src/librustdoc/clean/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl Clean<Item> for doctree::Module<'_> {
654654
attrs,
655655
source: whence.clean(cx),
656656
visibility: self.vis.clean(cx),
657-
stability: self.stab.clean(cx),
657+
stability: cx.stability(self.hid).clean(cx),
658658
deprecation: self.depr.clean(cx),
659659
def_id: cx.tcx.hir().local_def_id_from_node_id(self.id),
660660
inner: ModuleItem(Module {
@@ -1940,7 +1940,7 @@ impl Clean<Item> for doctree::Function<'_> {
19401940
attrs: self.attrs.clean(cx),
19411941
source: self.whence.clean(cx),
19421942
visibility: self.vis.clean(cx),
1943-
stability: self.stab.clean(cx),
1943+
stability: cx.stability(self.id).clean(cx),
19441944
deprecation: self.depr.clean(cx),
19451945
def_id: did,
19461946
inner: FunctionItem(Function {
@@ -2140,7 +2140,7 @@ impl Clean<Item> for doctree::Trait<'_> {
21402140
source: self.whence.clean(cx),
21412141
def_id: cx.tcx.hir().local_def_id(self.id),
21422142
visibility: self.vis.clean(cx),
2143-
stability: self.stab.clean(cx),
2143+
stability: cx.stability(self.id).clean(cx),
21442144
deprecation: self.depr.clean(cx),
21452145
inner: TraitItem(Trait {
21462146
auto: self.is_auto.clean(cx),
@@ -2170,7 +2170,7 @@ impl Clean<Item> for doctree::TraitAlias<'_> {
21702170
source: self.whence.clean(cx),
21712171
def_id: cx.tcx.hir().local_def_id(self.id),
21722172
visibility: self.vis.clean(cx),
2173-
stability: self.stab.clean(cx),
2173+
stability: cx.stability(self.id).clean(cx),
21742174
deprecation: self.depr.clean(cx),
21752175
inner: TraitAliasItem(TraitAlias {
21762176
generics: self.generics.clean(cx),
@@ -3244,7 +3244,7 @@ impl Clean<Item> for doctree::Struct<'_> {
32443244
source: self.whence.clean(cx),
32453245
def_id: cx.tcx.hir().local_def_id(self.id),
32463246
visibility: self.vis.clean(cx),
3247-
stability: self.stab.clean(cx),
3247+
stability: cx.stability(self.id).clean(cx),
32483248
deprecation: self.depr.clean(cx),
32493249
inner: StructItem(Struct {
32503250
struct_type: self.struct_type,
@@ -3264,7 +3264,7 @@ impl Clean<Item> for doctree::Union<'_> {
32643264
source: self.whence.clean(cx),
32653265
def_id: cx.tcx.hir().local_def_id(self.id),
32663266
visibility: self.vis.clean(cx),
3267-
stability: self.stab.clean(cx),
3267+
stability: cx.stability(self.id).clean(cx),
32683268
deprecation: self.depr.clean(cx),
32693269
inner: UnionItem(Union {
32703270
struct_type: self.struct_type,
@@ -3311,7 +3311,7 @@ impl Clean<Item> for doctree::Enum<'_> {
33113311
source: self.whence.clean(cx),
33123312
def_id: cx.tcx.hir().local_def_id(self.id),
33133313
visibility: self.vis.clean(cx),
3314-
stability: self.stab.clean(cx),
3314+
stability: cx.stability(self.id).clean(cx),
33153315
deprecation: self.depr.clean(cx),
33163316
inner: EnumItem(Enum {
33173317
variants: self.variants.iter().map(|v| v.clean(cx)).collect(),
@@ -3334,7 +3334,7 @@ impl Clean<Item> for doctree::Variant<'_> {
33343334
attrs: self.attrs.clean(cx),
33353335
source: self.whence.clean(cx),
33363336
visibility: None,
3337-
stability: self.stab.clean(cx),
3337+
stability: cx.stability(self.id).clean(cx),
33383338
deprecation: self.depr.clean(cx),
33393339
def_id: cx.tcx.hir().local_def_id(self.id),
33403340
inner: VariantItem(Variant {
@@ -3639,7 +3639,7 @@ impl Clean<Item> for doctree::Typedef<'_> {
36393639
source: self.whence.clean(cx),
36403640
def_id: cx.tcx.hir().local_def_id(self.id),
36413641
visibility: self.vis.clean(cx),
3642-
stability: self.stab.clean(cx),
3642+
stability: cx.stability(self.id).clean(cx),
36433643
deprecation: self.depr.clean(cx),
36443644
inner: TypedefItem(Typedef {
36453645
type_: self.ty.clean(cx),
@@ -3663,7 +3663,7 @@ impl Clean<Item> for doctree::OpaqueTy<'_> {
36633663
source: self.whence.clean(cx),
36643664
def_id: cx.tcx.hir().local_def_id(self.id),
36653665
visibility: self.vis.clean(cx),
3666-
stability: self.stab.clean(cx),
3666+
stability: cx.stability(self.id).clean(cx),
36673667
deprecation: self.depr.clean(cx),
36683668
inner: OpaqueTyItem(OpaqueTy {
36693669
bounds: self.opaque_ty.bounds.clean(cx),
@@ -3714,7 +3714,7 @@ impl Clean<Item> for doctree::Static<'_> {
37143714
source: self.whence.clean(cx),
37153715
def_id: cx.tcx.hir().local_def_id(self.id),
37163716
visibility: self.vis.clean(cx),
3717-
stability: self.stab.clean(cx),
3717+
stability: cx.stability(self.id).clean(cx),
37183718
deprecation: self.depr.clean(cx),
37193719
inner: StaticItem(Static {
37203720
type_: self.type_.clean(cx),
@@ -3739,7 +3739,7 @@ impl Clean<Item> for doctree::Constant<'_> {
37393739
source: self.whence.clean(cx),
37403740
def_id: cx.tcx.hir().local_def_id(self.id),
37413741
visibility: self.vis.clean(cx),
3742-
stability: self.stab.clean(cx),
3742+
stability: cx.stability(self.id).clean(cx),
37433743
deprecation: self.depr.clean(cx),
37443744
inner: ConstantItem(Constant {
37453745
type_: self.type_.clean(cx),
@@ -3826,7 +3826,7 @@ impl Clean<Vec<Item>> for doctree::Impl<'_> {
38263826
source: self.whence.clean(cx),
38273827
def_id: cx.tcx.hir().local_def_id(self.id),
38283828
visibility: self.vis.clean(cx),
3829-
stability: self.stab.clean(cx),
3829+
stability: cx.stability(self.id).clean(cx),
38303830
deprecation: self.depr.clean(cx),
38313831
inner: ImplItem(Impl {
38323832
unsafety: self.unsafety,
@@ -4065,7 +4065,7 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
40654065
source: self.whence.clean(cx),
40664066
def_id: cx.tcx.hir().local_def_id(self.id),
40674067
visibility: self.vis.clean(cx),
4068-
stability: self.stab.clean(cx),
4068+
stability: cx.stability(self.id).clean(cx),
40694069
deprecation: self.depr.clean(cx),
40704070
inner,
40714071
}
@@ -4248,7 +4248,7 @@ impl Clean<Item> for doctree::Macro<'_> {
42484248
attrs: self.attrs.clean(cx),
42494249
source: self.whence.clean(cx),
42504250
visibility: Some(Public),
4251-
stability: self.stab.clean(cx),
4251+
stability: cx.stability(self.hid).clean(cx),
42524252
deprecation: self.depr.clean(cx),
42534253
def_id: self.def_id,
42544254
inner: MacroItem(Macro {
@@ -4276,7 +4276,7 @@ impl Clean<Item> for doctree::ProcMacro<'_> {
42764276
attrs: self.attrs.clean(cx),
42774277
source: self.whence.clean(cx),
42784278
visibility: Some(Public),
4279-
stability: self.stab.clean(cx),
4279+
stability: cx.stability(self.id).clean(cx),
42804280
deprecation: self.depr.clean(cx),
42814281
def_id: cx.tcx.hir().local_def_id(self.id),
42824282
inner: ProcMacroItem(ProcMacro {

src/librustdoc/core.rs

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_metadata::cstore::CStore;
1616
use rustc_target::spec::TargetTriple;
1717

1818
use syntax::source_map;
19+
use syntax::attr;
1920
use syntax::feature_gate::UnstableFeatures;
2021
use syntax::json::JsonEmitter;
2122
use syntax::symbol::sym;
@@ -165,6 +166,11 @@ impl<'tcx> DocContext<'tcx> {
165166
self.tcx.hir().as_local_hir_id(def_id)
166167
}
167168
}
169+
170+
pub fn stability(&self, id: HirId) -> Option<attr::Stability> {
171+
self.tcx.hir().opt_local_def_id(id)
172+
.and_then(|def_id| self.tcx.lookup_stability(def_id)).cloned()
173+
}
168174
}
169175

170176
pub trait DocAccessLevels {

src/librustdoc/doctree.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub struct Module<'hir> {
2525
pub fns: Vec<Function<'hir>>,
2626
pub mods: Vec<Module<'hir>>,
2727
pub id: NodeId,
28+
pub hid: hir::HirId,
2829
pub typedefs: Vec<Typedef<'hir>>,
2930
pub opaque_tys: Vec<OpaqueTy<'hir>>,
3031
pub statics: Vec<Static<'hir>>,
3132
pub constants: Vec<Constant<'hir>>,
3233
pub traits: Vec<Trait<'hir>>,
3334
pub vis: &'hir hir::Visibility,
34-
pub stab: Option<attr::Stability>,
3535
pub depr: Option<attr::Deprecation>,
3636
pub impls: Vec<Impl<'hir>>,
3737
pub foreigns: Vec<ForeignItem<'hir>>,
@@ -50,8 +50,8 @@ impl Module<'hir> {
5050
Module {
5151
name : name,
5252
id: ast::CRATE_NODE_ID,
53+
hid: hir::CRATE_HIR_ID,
5354
vis,
54-
stab: None,
5555
depr: None,
5656
where_outer: syntax_pos::DUMMY_SP,
5757
where_inner: syntax_pos::DUMMY_SP,
@@ -90,7 +90,6 @@ pub enum StructType {
9090

9191
pub struct Struct<'hir> {
9292
pub vis: &'hir hir::Visibility,
93-
pub stab: Option<attr::Stability>,
9493
pub depr: Option<attr::Deprecation>,
9594
pub id: hir::HirId,
9695
pub struct_type: StructType,
@@ -103,7 +102,6 @@ pub struct Struct<'hir> {
103102

104103
pub struct Union<'hir> {
105104
pub vis: &'hir hir::Visibility,
106-
pub stab: Option<attr::Stability>,
107105
pub depr: Option<attr::Deprecation>,
108106
pub id: hir::HirId,
109107
pub struct_type: StructType,
@@ -116,7 +114,6 @@ pub struct Union<'hir> {
116114

117115
pub struct Enum<'hir> {
118116
pub vis: &'hir hir::Visibility,
119-
pub stab: Option<attr::Stability>,
120117
pub depr: Option<attr::Deprecation>,
121118
pub variants: Vec<Variant<'hir>>,
122119
pub generics: &'hir hir::Generics,
@@ -131,7 +128,6 @@ pub struct Variant<'hir> {
131128
pub id: hir::HirId,
132129
pub attrs: &'hir hir::HirVec<ast::Attribute>,
133130
pub def: &'hir hir::VariantData,
134-
pub stab: Option<attr::Stability>,
135131
pub depr: Option<attr::Deprecation>,
136132
pub whence: Span,
137133
}
@@ -142,7 +138,6 @@ pub struct Function<'hir> {
142138
pub id: hir::HirId,
143139
pub name: Name,
144140
pub vis: &'hir hir::Visibility,
145-
pub stab: Option<attr::Stability>,
146141
pub depr: Option<attr::Deprecation>,
147142
pub header: hir::FnHeader,
148143
pub whence: Span,
@@ -158,7 +153,6 @@ pub struct Typedef<'hir> {
158153
pub attrs: &'hir hir::HirVec<ast::Attribute>,
159154
pub whence: Span,
160155
pub vis: &'hir hir::Visibility,
161-
pub stab: Option<attr::Stability>,
162156
pub depr: Option<attr::Deprecation>,
163157
}
164158

@@ -169,7 +163,6 @@ pub struct OpaqueTy<'hir> {
169163
pub attrs: &'hir hir::HirVec<ast::Attribute>,
170164
pub whence: Span,
171165
pub vis: &'hir hir::Visibility,
172-
pub stab: Option<attr::Stability>,
173166
pub depr: Option<attr::Deprecation>,
174167
}
175168

@@ -181,7 +174,6 @@ pub struct Static<'hir> {
181174
pub name: Name,
182175
pub attrs: &'hir hir::HirVec<ast::Attribute>,
183176
pub vis: &'hir hir::Visibility,
184-
pub stab: Option<attr::Stability>,
185177
pub depr: Option<attr::Deprecation>,
186178
pub id: hir::HirId,
187179
pub whence: Span,
@@ -193,7 +185,6 @@ pub struct Constant<'hir> {
193185
pub name: Name,
194186
pub attrs: &'hir hir::HirVec<ast::Attribute>,
195187
pub vis: &'hir hir::Visibility,
196-
pub stab: Option<attr::Stability>,
197188
pub depr: Option<attr::Deprecation>,
198189
pub id: hir::HirId,
199190
pub whence: Span,
@@ -210,7 +201,6 @@ pub struct Trait<'hir> {
210201
pub id: hir::HirId,
211202
pub whence: Span,
212203
pub vis: &'hir hir::Visibility,
213-
pub stab: Option<attr::Stability>,
214204
pub depr: Option<attr::Deprecation>,
215205
}
216206

@@ -222,7 +212,6 @@ pub struct TraitAlias<'hir> {
222212
pub id: hir::HirId,
223213
pub whence: Span,
224214
pub vis: &'hir hir::Visibility,
225-
pub stab: Option<attr::Stability>,
226215
pub depr: Option<attr::Deprecation>,
227216
}
228217

@@ -238,14 +227,12 @@ pub struct Impl<'hir> {
238227
pub attrs: &'hir hir::HirVec<ast::Attribute>,
239228
pub whence: Span,
240229
pub vis: &'hir hir::Visibility,
241-
pub stab: Option<attr::Stability>,
242230
pub depr: Option<attr::Deprecation>,
243231
pub id: hir::HirId,
244232
}
245233

246234
pub struct ForeignItem<'hir> {
247235
pub vis: &'hir hir::Visibility,
248-
pub stab: Option<attr::Stability>,
249236
pub depr: Option<attr::Deprecation>,
250237
pub id: hir::HirId,
251238
pub name: Name,
@@ -258,11 +245,11 @@ pub struct ForeignItem<'hir> {
258245
// these imported macro_rules (which only have a DUMMY_NODE_ID).
259246
pub struct Macro<'hir> {
260247
pub name: Name,
248+
pub hid: hir::HirId,
261249
pub def_id: hir::def_id::DefId,
262250
pub attrs: &'hir hir::HirVec<ast::Attribute>,
263251
pub whence: Span,
264252
pub matchers: hir::HirVec<Span>,
265-
pub stab: Option<attr::Stability>,
266253
pub depr: Option<attr::Deprecation>,
267254
pub imported_from: Option<Name>,
268255
}
@@ -293,7 +280,6 @@ pub struct ProcMacro<'hir> {
293280
pub helpers: Vec<Name>,
294281
pub attrs: &'hir hir::HirVec<ast::Attribute>,
295282
pub whence: Span,
296-
pub stab: Option<attr::Stability>,
297283
pub depr: Option<attr::Deprecation>,
298284
}
299285

0 commit comments

Comments
 (0)