Skip to content

Commit 0487e63

Browse files
committed
Bug fixes for stability tracking
This commit adds correct stability tracking for struct fields and corrects some places where rustdoc was not pulling the stability data.
1 parent 4d16de0 commit 0487e63

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ fn encode_info_for_struct(ecx: &EncodeContext,
693693
encode_name(ebml_w, nm);
694694
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
695695
encode_def_id(ebml_w, local_def(id));
696+
697+
let stab = stability::lookup(ecx.tcx, field.id);
698+
encode_stability(ebml_w, stab);
699+
696700
ebml_w.end_tag();
697701
}
698702
index

src/librustc/middle/stability.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
use util::nodemap::{NodeMap, DefIdMap};
1515
use syntax::codemap::Span;
1616
use syntax::{attr, visit};
17+
use syntax::ast;
1718
use syntax::ast::{Attribute, Block, Crate, DefId, FnDecl, NodeId, Variant};
1819
use syntax::ast::{Item, Required, Provided, TraitMethod, TypeMethod, Method};
19-
use syntax::ast::{Generics, StructDef, Ident};
20+
use syntax::ast::{Generics, StructDef, StructField, Ident};
2021
use syntax::ast_util::is_local;
2122
use syntax::attr::Stability;
2223
use syntax::visit::{FnKind, FkMethod, Visitor};
@@ -91,6 +92,11 @@ impl Visitor<Option<Stability>> for Annotator {
9192
s.ctor_id.map(|id| self.annotate(id, &[], parent.clone()));
9293
visit::walk_struct_def(self, s, parent)
9394
}
95+
96+
fn visit_struct_field(&mut self, s: &StructField, parent: Option<Stability>) {
97+
let stab = self.annotate(s.node.id, s.node.attrs.as_slice(), parent);
98+
visit::walk_struct_field(self, s, stab)
99+
}
94100
}
95101

96102
impl Index {
@@ -102,8 +108,8 @@ impl Index {
102108
extern_cache: DefIdMap::new()
103109
}
104110
};
105-
visit::walk_crate(&mut annotator, krate,
106-
attr::find_stability(krate.attrs.as_slice()));
111+
let stab = annotator.annotate(ast::CRATE_NODE_ID, krate.attrs.as_slice(), None);
112+
visit::walk_crate(&mut annotator, krate, stab);
107113
annotator.index
108114
}
109115
}

src/librustdoc/clean/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,12 +1461,15 @@ impl Clean<Item> for ty::VariantInfo {
14611461
name: Some(name.clean()),
14621462
attrs: Vec::new(),
14631463
visibility: Some(ast::Public),
1464-
stability: get_stability(self.id),
14651464
// FIXME: this is not accurate, we need an id for
14661465
// the specific field but we're using the id
1467-
// for the whole variant. Nothing currently
1468-
// uses this so we should be good for now.
1466+
// for the whole variant. Thus we read the
1467+
// stability from the whole variant as well.
1468+
// Struct variants are experimental and need
1469+
// more infrastructure work before we can get
1470+
// at the needed information here.
14691471
def_id: self.id,
1472+
stability: get_stability(self.id),
14701473
inner: StructFieldItem(
14711474
TypedStructField(ty.clean())
14721475
)
@@ -1482,7 +1485,7 @@ impl Clean<Item> for ty::VariantInfo {
14821485
visibility: Some(ast::Public),
14831486
def_id: self.id,
14841487
inner: VariantItem(Variant { kind: kind }),
1485-
stability: None,
1488+
stability: get_stability(self.id),
14861489
}
14871490
}
14881491
}
@@ -1890,7 +1893,7 @@ impl Clean<Item> for ast::ForeignItem {
18901893
source: self.span.clean(),
18911894
def_id: ast_util::local_def(self.id),
18921895
visibility: self.vis.clean(),
1893-
stability: None,
1896+
stability: get_stability(ast_util::local_def(self.id)),
18941897
inner: inner,
18951898
}
18961899
}

0 commit comments

Comments
 (0)