mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Move span into StructField
+ some cleanup in rustdoc
This commit is contained in:
parent
8b026a6e48
commit
9047b201bf
@ -150,8 +150,8 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
for field in v.node.data.fields() {
|
||||
self.create_def_with_parent(
|
||||
Some(variant_def_index),
|
||||
field.node.id,
|
||||
DefPathData::Field(field.node.name));
|
||||
field.id,
|
||||
DefPathData::Field(field.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
}
|
||||
|
||||
for field in struct_def.fields() {
|
||||
self.create_def(field.node.id, DefPathData::Field(field.node.name));
|
||||
self.create_def(field.id, DefPathData::Field(field.name));
|
||||
}
|
||||
}
|
||||
ItemTrait(_, _, ref bounds, _) => {
|
||||
|
@ -811,7 +811,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &hir::StructField) {
|
||||
self.with_lint_attrs(&s.node.attrs, |cx| {
|
||||
self.with_lint_attrs(&s.attrs, |cx| {
|
||||
run_lints!(cx, check_struct_field, late_passes, s);
|
||||
hir_visit::walk_struct_field(cx, s);
|
||||
})
|
||||
|
@ -221,9 +221,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
let has_extern_repr = self.struct_has_extern_repr;
|
||||
let inherited_pub_visibility = self.inherited_pub_visibility;
|
||||
let live_fields = def.fields().iter().filter(|f| {
|
||||
has_extern_repr || inherited_pub_visibility || f.node.vis == hir::Public
|
||||
has_extern_repr || inherited_pub_visibility || f.vis == hir::Public
|
||||
});
|
||||
self.live_symbols.extend(live_fields.map(|f| f.node.id));
|
||||
self.live_symbols.extend(live_fields.map(|f| f.id));
|
||||
|
||||
intravisit::walk_struct_def(self, def);
|
||||
}
|
||||
@ -428,16 +428,16 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
should_warn && !self.symbol_is_live(item.id, ctor_id)
|
||||
}
|
||||
|
||||
fn should_warn_about_field(&mut self, node: &hir::StructField_) -> bool {
|
||||
let field_type = self.tcx.node_id_to_type(node.id);
|
||||
fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
|
||||
let field_type = self.tcx.node_id_to_type(field.id);
|
||||
let is_marker_field = match field_type.ty_to_def_id() {
|
||||
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
|
||||
_ => false
|
||||
};
|
||||
!node.is_positional()
|
||||
&& !self.symbol_is_live(node.id, None)
|
||||
!field.is_positional()
|
||||
&& !self.symbol_is_live(field.id, None)
|
||||
&& !is_marker_field
|
||||
&& !has_allow_dead_code_or_lang_attr(&node.attrs)
|
||||
&& !has_allow_dead_code_or_lang_attr(&field.attrs)
|
||||
}
|
||||
|
||||
fn should_warn_about_variant(&mut self, variant: &hir::Variant_) -> bool {
|
||||
@ -543,9 +543,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, field: &hir::StructField) {
|
||||
if self.should_warn_about_field(&field.node) {
|
||||
self.warn_dead_code(field.node.id, field.span,
|
||||
field.node.name, "struct field");
|
||||
if self.should_warn_about_field(&field) {
|
||||
self.warn_dead_code(field.id, field.span,
|
||||
field.name, "struct field");
|
||||
}
|
||||
|
||||
intravisit::walk_struct_field(self, field);
|
||||
|
@ -259,7 +259,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &StructField) {
|
||||
self.annotate(s.node.id, &s.node.attrs, s.span, AnnotationKind::Required, |v| {
|
||||
self.annotate(s.id, &s.attrs, s.span, AnnotationKind::Required, |v| {
|
||||
intravisit::walk_struct_field(v, s);
|
||||
});
|
||||
}
|
||||
|
@ -700,16 +700,13 @@ pub fn noop_fold_poly_trait_ref<T: Folder>(p: PolyTraitRef, fld: &mut T) -> Poly
|
||||
}
|
||||
|
||||
pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructField {
|
||||
let StructField {node: StructField_ {id, name, vis, ty, attrs}, span} = f;
|
||||
Spanned {
|
||||
node: StructField_ {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
vis: vis,
|
||||
ty: fld.fold_ty(ty),
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
},
|
||||
span: fld.new_span(span),
|
||||
StructField {
|
||||
span: fld.new_span(f.span),
|
||||
id: fld.new_id(f.id),
|
||||
name: f.name,
|
||||
vis: f.vis,
|
||||
ty: fld.fold_ty(f.ty),
|
||||
attrs: fold_attrs(f.attrs, fld),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1241,7 +1241,8 @@ impl Visibility {
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct StructField_ {
|
||||
pub struct StructField {
|
||||
pub span: Span,
|
||||
pub name: Name,
|
||||
pub vis: Visibility,
|
||||
pub id: NodeId,
|
||||
@ -1249,9 +1250,7 @@ pub struct StructField_ {
|
||||
pub attrs: HirVec<Attribute>,
|
||||
}
|
||||
|
||||
pub type StructField = Spanned<StructField_>;
|
||||
|
||||
impl StructField_ {
|
||||
impl StructField {
|
||||
// Still necessary in couple of places
|
||||
pub fn is_positional(&self) -> bool {
|
||||
let first = self.name.as_str().as_bytes()[0];
|
||||
|
@ -669,9 +669,9 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &
|
||||
}
|
||||
|
||||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) {
|
||||
visitor.visit_name(struct_field.span, struct_field.node.name);
|
||||
visitor.visit_ty(&struct_field.node.ty);
|
||||
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);
|
||||
visitor.visit_name(struct_field.span, struct_field.name);
|
||||
visitor.visit_ty(&struct_field.ty);
|
||||
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
|
||||
|
@ -612,16 +612,14 @@ pub fn lower_poly_trait_ref(lctx: &LoweringContext, p: &PolyTraitRef) -> hir::Po
|
||||
pub fn lower_struct_field(lctx: &LoweringContext,
|
||||
(index, f): (usize, &StructField))
|
||||
-> hir::StructField {
|
||||
Spanned {
|
||||
node: hir::StructField_ {
|
||||
id: f.node.id,
|
||||
name: f.node.ident().map(|ident| ident.name)
|
||||
.unwrap_or(token::intern(&index.to_string())),
|
||||
vis: lower_visibility(lctx, f.node.kind.visibility()),
|
||||
ty: lower_ty(lctx, &f.node.ty),
|
||||
attrs: lower_attrs(lctx, &f.node.attrs),
|
||||
},
|
||||
hir::StructField {
|
||||
span: f.span,
|
||||
id: f.node.id,
|
||||
name: f.node.ident().map(|ident| ident.name)
|
||||
.unwrap_or(token::intern(&index.to_string())),
|
||||
vis: lower_visibility(lctx, f.node.kind.visibility()),
|
||||
ty: lower_ty(lctx, &f.node.ty),
|
||||
attrs: lower_attrs(lctx, &f.node.attrs),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -915,9 +915,9 @@ impl<'a> State<'a> {
|
||||
if struct_def.is_tuple() {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Inconsistent, struct_def.fields(), |s, field| {
|
||||
try!(s.print_visibility(field.node.vis));
|
||||
try!(s.print_visibility(field.vis));
|
||||
try!(s.maybe_print_comment(field.span.lo));
|
||||
s.print_type(&field.node.ty)
|
||||
s.print_type(&field.ty)
|
||||
}));
|
||||
try!(self.pclose());
|
||||
}
|
||||
@ -936,11 +936,11 @@ impl<'a> State<'a> {
|
||||
for field in struct_def.fields() {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(field.span.lo));
|
||||
try!(self.print_outer_attributes(&field.node.attrs));
|
||||
try!(self.print_visibility(field.node.vis));
|
||||
try!(self.print_name(field.node.name));
|
||||
try!(self.print_outer_attributes(&field.attrs));
|
||||
try!(self.print_visibility(field.vis));
|
||||
try!(self.print_name(field.name));
|
||||
try!(self.word_nbsp(":"));
|
||||
try!(self.print_type(&field.node.ty));
|
||||
try!(self.print_type(&field.ty));
|
||||
try!(word(&mut self.s, ","));
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, struct_field: &StructField) {
|
||||
self.operation.visit_id(struct_field.node.id);
|
||||
self.operation.visit_id(struct_field.id);
|
||||
intravisit::walk_struct_field(self, struct_field)
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ impl LateLintPass for NonSnakeCase {
|
||||
fn check_struct_def(&mut self, cx: &LateContext, s: &hir::VariantData,
|
||||
_: ast::Name, _: &hir::Generics, _: ast::NodeId) {
|
||||
for sf in s.fields() {
|
||||
self.check_snake_case(cx, "structure field", &sf.node.name.as_str(), Some(sf.span));
|
||||
self.check_snake_case(cx, "structure field", &sf.name.as_str(), Some(sf.span));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl LateLintPass for BoxPointers {
|
||||
hir::ItemStruct(ref struct_def, _) => {
|
||||
for struct_field in struct_def.fields() {
|
||||
self.check_heap_type(cx, struct_field.span,
|
||||
cx.tcx.node_id_to_type(struct_field.node.id));
|
||||
cx.tcx.node_id_to_type(struct_field.id));
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
@ -428,12 +428,12 @@ impl LateLintPass for MissingDoc {
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext, sf: &hir::StructField) {
|
||||
if !sf.node.is_positional() {
|
||||
if sf.node.vis == hir::Public || self.in_variant {
|
||||
if !sf.is_positional() {
|
||||
if sf.vis == hir::Public || self.in_variant {
|
||||
let cur_struct_def = *self.struct_def_stack.last()
|
||||
.expect("empty struct_def_stack");
|
||||
self.check_missing_docs_attrs(cx, Some(cur_struct_def),
|
||||
&sf.node.attrs, sf.span,
|
||||
&sf.attrs, sf.span,
|
||||
"a struct field")
|
||||
}
|
||||
}
|
||||
|
@ -1751,9 +1751,9 @@ fn encode_struct_field_attrs(ecx: &EncodeContext,
|
||||
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for StructFieldVisitor<'a, 'b, 'c, 'tcx> {
|
||||
fn visit_struct_field(&mut self, field: &hir::StructField) {
|
||||
self.rbml_w.start_tag(tag_struct_field);
|
||||
let def_id = self.ecx.tcx.map.local_def_id(field.node.id);
|
||||
let def_id = self.ecx.tcx.map.local_def_id(field.id);
|
||||
encode_def_id(self.rbml_w, def_id);
|
||||
encode_attributes(self.rbml_w, &field.node.attrs);
|
||||
encode_attributes(self.rbml_w, &field.attrs);
|
||||
self.rbml_w.end_tag();
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ParentVisitor<'a, 'tcx> {
|
||||
// While we have the id of the struct definition, go ahead and parent
|
||||
// all the fields.
|
||||
for field in s.fields() {
|
||||
self.parents.insert(field.node.id, self.curparent);
|
||||
self.parents.insert(field.id, self.curparent);
|
||||
}
|
||||
intravisit::walk_struct_def(self, s)
|
||||
}
|
||||
@ -262,7 +262,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
for variant in &def.variants {
|
||||
let variant_level = self.update(variant.node.data.id(), item_level);
|
||||
for field in variant.node.data.fields() {
|
||||
self.update(field.node.id, variant_level);
|
||||
self.update(field.id, variant_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -288,8 +288,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
self.update(def.id(), item_level);
|
||||
}
|
||||
for field in def.fields() {
|
||||
if field.node.vis == hir::Public {
|
||||
self.update(field.node.id, item_level);
|
||||
if field.vis == hir::Public {
|
||||
self.update(field.id, item_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
if item_level.is_some() {
|
||||
self.reach().visit_generics(generics);
|
||||
for field in struct_def.fields() {
|
||||
if self.get(field.node.id).is_some() {
|
||||
if self.get(field.id).is_some() {
|
||||
self.reach().visit_struct_field(field);
|
||||
}
|
||||
}
|
||||
@ -1514,7 +1514,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx>
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &hir::StructField) {
|
||||
if s.node.vis == hir::Public || self.in_variant {
|
||||
if s.vis == hir::Public || self.in_variant {
|
||||
intravisit::walk_struct_field(self, s);
|
||||
}
|
||||
}
|
||||
@ -1725,7 +1725,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivateItemsInPublicInterfacesVisitor<'a, 'tc
|
||||
if item.vis == hir::Public {
|
||||
check.visit_generics(generics);
|
||||
for field in struct_def.fields() {
|
||||
if field.node.vis == hir::Public {
|
||||
if field.vis == hir::Public {
|
||||
check.visit_struct_field(field);
|
||||
}
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
// Record the def ID and fields of this struct.
|
||||
let field_names = struct_def.fields()
|
||||
.iter()
|
||||
.map(|f| f.node.name)
|
||||
.map(|f| f.name)
|
||||
.collect();
|
||||
let item_def_id = self.ast_map.local_def_id(item.id);
|
||||
self.structs.insert(item_def_id, field_names);
|
||||
|
@ -567,7 +567,7 @@ fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
let fields =
|
||||
struct_def.fields().iter()
|
||||
.map(|field| {
|
||||
let field_ty = fcx.tcx().node_id_to_type(field.node.id);
|
||||
let field_ty = fcx.tcx().node_id_to_type(field.id);
|
||||
let field_ty = fcx.instantiate_type_scheme(field.span,
|
||||
&fcx.inh
|
||||
.infcx
|
||||
|
@ -574,20 +574,20 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
||||
fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
||||
struct_generics: &ty::Generics<'tcx>,
|
||||
struct_predicates: &ty::GenericPredicates<'tcx>,
|
||||
v: &hir::StructField,
|
||||
field: &hir::StructField,
|
||||
ty_f: ty::FieldDefMaster<'tcx>)
|
||||
{
|
||||
let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &v.node.ty);
|
||||
let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &field.ty);
|
||||
ty_f.fulfill_ty(tt);
|
||||
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
|
||||
write_ty_to_tcx(ccx.tcx, field.id, tt);
|
||||
|
||||
/* add the field to the tcache */
|
||||
ccx.tcx.register_item_type(ccx.tcx.map.local_def_id(v.node.id),
|
||||
ccx.tcx.register_item_type(ccx.tcx.map.local_def_id(field.id),
|
||||
ty::TypeScheme {
|
||||
generics: struct_generics.clone(),
|
||||
ty: tt
|
||||
});
|
||||
ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(v.node.id),
|
||||
ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(field.id),
|
||||
struct_predicates.clone());
|
||||
}
|
||||
|
||||
@ -977,19 +977,19 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
def: &hir::VariantData) -> ty::VariantDefData<'tcx, 'tcx> {
|
||||
let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
|
||||
let fields = def.fields().iter().map(|f| {
|
||||
let fid = tcx.map.local_def_id(f.node.id);
|
||||
let dup_span = seen_fields.get(&f.node.name).cloned();
|
||||
let fid = tcx.map.local_def_id(f.id);
|
||||
let dup_span = seen_fields.get(&f.name).cloned();
|
||||
if let Some(prev_span) = dup_span {
|
||||
let mut err = struct_span_err!(tcx.sess, f.span, E0124,
|
||||
"field `{}` is already declared",
|
||||
f.node.name);
|
||||
f.name);
|
||||
span_note!(&mut err, prev_span, "previously declared here");
|
||||
err.emit();
|
||||
} else {
|
||||
seen_fields.insert(f.node.name, f.span);
|
||||
seen_fields.insert(f.name, f.span);
|
||||
}
|
||||
|
||||
ty::FieldDefData::new(fid, f.node.name, f.node.vis)
|
||||
ty::FieldDefData::new(fid, f.name, f.vis)
|
||||
}).collect();
|
||||
ty::VariantDefData {
|
||||
did: did,
|
||||
|
@ -1735,16 +1735,15 @@ pub enum StructField {
|
||||
|
||||
impl Clean<Item> for hir::StructField {
|
||||
fn clean(&self, cx: &DocContext) -> Item {
|
||||
let name = if self.node.is_positional() { None } else { Some(self.node.name) };
|
||||
Item {
|
||||
name: name.clean(cx),
|
||||
attrs: self.node.attrs.clean(cx),
|
||||
name: Some(self.name).clean(cx),
|
||||
attrs: self.attrs.clean(cx),
|
||||
source: self.span.clean(cx),
|
||||
visibility: Some(self.node.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))),
|
||||
visibility: Some(self.vis),
|
||||
stability: get_stability(cx, cx.map.local_def_id(self.id)),
|
||||
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
|
||||
def_id: cx.map.local_def_id(self.id),
|
||||
inner: StructFieldItem(TypedStructField(self.ty.clean(cx))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1752,22 +1751,10 @@ impl Clean<Item> for hir::StructField {
|
||||
impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
|
||||
fn clean(&self, cx: &DocContext) -> Item {
|
||||
// FIXME: possible O(n^2)-ness! Not my fault.
|
||||
let attr_map =
|
||||
cx.tcx().sess.cstore.crate_struct_field_attrs(self.did.krate);
|
||||
|
||||
let is_positional = {
|
||||
let first = self.name.as_str().as_bytes()[0];
|
||||
first >= b'0' && first <= b'9'
|
||||
};
|
||||
let (name, attrs) = if is_positional {
|
||||
(None, None)
|
||||
} else {
|
||||
(Some(self.name), Some(attr_map.get(&self.did).unwrap()))
|
||||
};
|
||||
|
||||
let attr_map = cx.tcx().sess.cstore.crate_struct_field_attrs(self.did.krate);
|
||||
Item {
|
||||
name: name.clean(cx),
|
||||
attrs: attrs.unwrap_or(&Vec::new()).clean(cx),
|
||||
name: Some(self.name).clean(cx),
|
||||
attrs: attr_map.get(&self.did).unwrap_or(&Vec::new()).clean(cx),
|
||||
source: Span::empty(),
|
||||
visibility: Some(self.vis),
|
||||
stability: get_stability(cx, self.did),
|
||||
@ -1945,7 +1932,7 @@ fn struct_def_to_variant_kind(struct_def: &hir::VariantData, cx: &DocContext) ->
|
||||
} else if struct_def.is_unit() {
|
||||
CLikeVariant
|
||||
} else {
|
||||
TupleVariant(struct_def.fields().iter().map(|x| x.node.ty.clean(cx)).collect())
|
||||
TupleVariant(struct_def.fields().iter().map(|x| x.ty.clean(cx)).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user