Move span into StructField
This commit is contained in:
parent
7f3744f07f
commit
8fe4290f1c
13 changed files with 50 additions and 49 deletions
|
@ -978,7 +978,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
|
|||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &ast::StructField) {
|
||||
self.with_lint_attrs(&s.node.attrs, |cx| {
|
||||
self.with_lint_attrs(&s.attrs, |cx| {
|
||||
run_lints!(cx, check_struct_field, early_passes, s);
|
||||
ast_visit::walk_struct_field(cx, s);
|
||||
})
|
||||
|
|
|
@ -621,11 +621,11 @@ pub fn lower_struct_field(lctx: &LoweringContext,
|
|||
-> hir::StructField {
|
||||
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.vis),
|
||||
ty: lower_ty(lctx, &f.node.ty),
|
||||
attrs: lower_attrs(lctx, &f.node.attrs),
|
||||
id: f.id,
|
||||
name: f.ident.map(|ident| ident.name).unwrap_or(token::intern(&index.to_string())),
|
||||
vis: lower_visibility(lctx, &f.vis),
|
||||
ty: lower_ty(lctx, &f.ty),
|
||||
attrs: lower_attrs(lctx, &f.attrs),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -563,7 +563,7 @@ where D: Dump
|
|||
// fields
|
||||
for field in def.fields() {
|
||||
self.process_struct_field_def(field, item.id);
|
||||
self.visit_ty(&field.node.ty);
|
||||
self.visit_ty(&field.ty);
|
||||
}
|
||||
|
||||
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
||||
|
@ -624,7 +624,7 @@ where D: Dump
|
|||
|
||||
for field in variant.node.data.fields() {
|
||||
self.process_struct_field_def(field, variant.node.data.id());
|
||||
self.visit_ty(&field.node.ty);
|
||||
self.visit_ty(&field.ty);
|
||||
}
|
||||
}
|
||||
self.process_generic_params(ty_params, item.span, &enum_data.qualname, enum_data.id);
|
||||
|
|
|
@ -246,13 +246,13 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
|
||||
pub fn get_field_data(&self, field: &ast::StructField,
|
||||
scope: NodeId) -> Option<VariableData> {
|
||||
if let Some(ident) = field.node.ident {
|
||||
if let Some(ident) = field.ident {
|
||||
let qualname = format!("::{}::{}", self.tcx.map.path_to_string(scope), ident);
|
||||
let typ = self.tcx.node_types().get(&field.node.id).unwrap().to_string();
|
||||
let typ = self.tcx.node_types().get(&field.id).unwrap().to_string();
|
||||
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
|
||||
filter!(self.span_utils, sub_span, field.span, None);
|
||||
Some(VariableData {
|
||||
id: field.node.id,
|
||||
id: field.id,
|
||||
name: ident.to_string(),
|
||||
qualname: qualname,
|
||||
span: sub_span.unwrap(),
|
||||
|
|
|
@ -1876,7 +1876,8 @@ pub enum Visibility {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct StructField_ {
|
||||
pub struct StructField {
|
||||
pub span: Span,
|
||||
pub ident: Option<Ident>,
|
||||
pub vis: Visibility,
|
||||
pub id: NodeId,
|
||||
|
@ -1884,8 +1885,6 @@ pub struct StructField_ {
|
|||
pub attrs: Vec<Attribute>,
|
||||
}
|
||||
|
||||
pub type StructField = Spanned<StructField_>;
|
||||
|
||||
/// Fields and Ids of enum variants and structs
|
||||
///
|
||||
/// For enum variants: `NodeId` represents both an Id of the variant itself (relevant for all
|
||||
|
|
|
@ -263,7 +263,7 @@ impl<'a, 'v, O: 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);
|
||||
visit::walk_struct_field(self, struct_field)
|
||||
}
|
||||
|
||||
|
|
|
@ -180,12 +180,12 @@ fn fold_struct<F>(cx: &mut Context<F>, vdata: ast::VariantData) -> ast::VariantD
|
|||
match vdata {
|
||||
ast::VariantData::Struct(fields, id) => {
|
||||
ast::VariantData::Struct(fields.into_iter().filter(|m| {
|
||||
(cx.in_cfg)(&m.node.attrs)
|
||||
(cx.in_cfg)(&m.attrs)
|
||||
}).collect(), id)
|
||||
}
|
||||
ast::VariantData::Tuple(fields, id) => {
|
||||
ast::VariantData::Tuple(fields.into_iter().filter(|m| {
|
||||
(cx.in_cfg)(&m.node.attrs)
|
||||
(cx.in_cfg)(&m.attrs)
|
||||
}).collect(), id)
|
||||
}
|
||||
ast::VariantData::Unit(id) => ast::VariantData::Unit(id)
|
||||
|
@ -434,7 +434,7 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for StmtExprAttrFeatureVisitor<'a, 'b> {
|
|||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'v ast::StructField) {
|
||||
if node_survives_cfg(&s.node.attrs, self.config) {
|
||||
if node_survives_cfg(&s.attrs, self.config) {
|
||||
visit::walk_struct_field(self, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1007,13 +1007,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
|
||||
fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Variant {
|
||||
let fields: Vec<_> = tys.into_iter().map(|ty| {
|
||||
Spanned { span: ty.span, node: ast::StructField_ {
|
||||
ast::StructField {
|
||||
span: ty.span,
|
||||
ty: ty,
|
||||
ident: None,
|
||||
vis: ast::Visibility::Inherited,
|
||||
attrs: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
}}
|
||||
}
|
||||
}).collect();
|
||||
|
||||
let vdata = if fields.is_empty() {
|
||||
|
|
|
@ -847,15 +847,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 {
|
||||
Spanned {
|
||||
node: StructField_ {
|
||||
id: fld.new_id(f.node.id),
|
||||
ident: f.node.ident.map(|ident| fld.fold_ident(ident)),
|
||||
vis: f.node.vis,
|
||||
ty: fld.fold_ty(f.node.ty),
|
||||
attrs: fold_attrs(f.node.attrs, fld),
|
||||
},
|
||||
span: fld.new_span(f.span)
|
||||
StructField {
|
||||
span: fld.new_span(f.span),
|
||||
id: fld.new_id(f.id),
|
||||
ident: f.ident.map(|ident| fld.fold_ident(ident)),
|
||||
vis: f.vis,
|
||||
ty: fld.fold_ty(f.ty),
|
||||
attrs: fold_attrs(f.attrs, fld),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3845,13 +3845,14 @@ impl<'a> Parser<'a> {
|
|||
let name = self.parse_ident()?;
|
||||
self.expect(&token::Colon)?;
|
||||
let ty = self.parse_ty_sum()?;
|
||||
Ok(spanned(lo, self.last_span.hi, ast::StructField_ {
|
||||
Ok(StructField {
|
||||
span: mk_sp(lo, self.last_span.hi),
|
||||
ident: Some(name),
|
||||
vis: pr,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ty: ty,
|
||||
attrs: attrs,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
/// Emit an expected item after attributes error.
|
||||
|
@ -5245,14 +5246,16 @@ impl<'a> Parser<'a> {
|
|||
|p| {
|
||||
let attrs = p.parse_outer_attributes()?;
|
||||
let lo = p.span.lo;
|
||||
let struct_field_ = ast::StructField_ {
|
||||
vis: p.parse_visibility()?,
|
||||
let vis = p.parse_visibility()?;
|
||||
let ty = p.parse_ty_sum()?;
|
||||
Ok(StructField {
|
||||
span: mk_sp(lo, p.span.hi),
|
||||
vis: vis,
|
||||
ident: None,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ty: p.parse_ty_sum()?,
|
||||
ty: ty,
|
||||
attrs: attrs,
|
||||
};
|
||||
Ok(spanned(lo, p.span.hi, struct_field_))
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(fields)
|
||||
|
|
|
@ -1407,9 +1407,9 @@ impl<'a> State<'a> {
|
|||
self.commasep(
|
||||
Inconsistent, struct_def.fields(),
|
||||
|s, field| {
|
||||
s.print_visibility(field.node.vis)?;
|
||||
s.print_visibility(&field.vis)?;
|
||||
s.maybe_print_comment(field.span.lo)?;
|
||||
s.print_type(&field.node.ty)
|
||||
s.print_type(&field.ty)
|
||||
}
|
||||
)?;
|
||||
self.pclose()?;
|
||||
|
@ -1429,11 +1429,11 @@ impl<'a> State<'a> {
|
|||
for field in struct_def.fields() {
|
||||
self.hardbreak_if_not_bol()?;
|
||||
self.maybe_print_comment(field.span.lo)?;
|
||||
self.print_outer_attributes(&field.node.attrs)?;
|
||||
self.print_visibility(field.node.vis)?;
|
||||
self.print_ident(field.node.ident.unwrap())?;
|
||||
self.print_outer_attributes(&field.attrs)?;
|
||||
self.print_visibility(&field.vis)?;
|
||||
self.print_ident(field.ident.unwrap())?;
|
||||
self.word_nbsp(":")?;
|
||||
self.print_type(&field.node.ty)?;
|
||||
self.print_type(&field.ty)?;
|
||||
word(&mut self.s, ",")?;
|
||||
}
|
||||
|
||||
|
|
|
@ -619,9 +619,9 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
|||
|
||||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
struct_field: &'v StructField) {
|
||||
walk_opt_ident(visitor, struct_field.span, struct_field.node.ident);
|
||||
visitor.visit_ty(&struct_field.node.ty);
|
||||
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);
|
||||
walk_opt_ident(visitor, struct_field.span, struct_field.ident);
|
||||
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) {
|
||||
|
|
|
@ -653,7 +653,7 @@ impl<'a> TraitDef<'a> {
|
|||
type_ident: Ident,
|
||||
generics: &Generics) -> P<ast::Item> {
|
||||
let field_tys: Vec<P<ast::Ty>> = struct_def.fields().iter()
|
||||
.map(|field| field.node.ty.clone())
|
||||
.map(|field| field.ty.clone())
|
||||
.collect();
|
||||
|
||||
let methods = self.methods.iter().map(|method_def| {
|
||||
|
@ -701,7 +701,7 @@ impl<'a> TraitDef<'a> {
|
|||
|
||||
for variant in &enum_def.variants {
|
||||
field_tys.extend(variant.node.data.fields().iter()
|
||||
.map(|field| field.node.ty.clone()));
|
||||
.map(|field| field.ty.clone()));
|
||||
}
|
||||
|
||||
let methods = self.methods.iter().map(|method_def| {
|
||||
|
@ -1435,7 +1435,7 @@ impl<'a> TraitDef<'a> {
|
|||
let mut just_spans = Vec::new();
|
||||
for field in struct_def.fields(){
|
||||
let sp = self.set_expn_info(cx, field.span);
|
||||
match field.node.ident {
|
||||
match field.ident {
|
||||
Some(ident) => named_idents.push((ident, sp)),
|
||||
_ => just_spans.push(sp),
|
||||
}
|
||||
|
@ -1481,7 +1481,7 @@ impl<'a> TraitDef<'a> {
|
|||
paths.push(codemap::Spanned{span: sp, node: ident});
|
||||
let val = cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident)));
|
||||
let val = cx.expr(sp, ast::ExprKind::Paren(val));
|
||||
ident_exprs.push((sp, struct_field.node.ident, val, &struct_field.node.attrs[..]));
|
||||
ident_exprs.push((sp, struct_field.ident, val, &struct_field.attrs[..]));
|
||||
}
|
||||
|
||||
let subpats = self.create_subpatterns(cx, paths, mutbl);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue