From 5aee3e01a02e0b31ad225e70899a671937ab65ee Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 19 Jul 2013 16:24:22 +0200 Subject: [PATCH] De-spanned and renamed ast::field (now ast::Field) --- src/librustc/middle/cfg/construct.rs | 2 +- src/librustc/middle/const_eval.rs | 2 +- src/librustc/middle/dataflow.rs | 2 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/moves.rs | 4 ++-- src/librustc/middle/privacy.rs | 17 +++++------------ src/librustc/middle/trans/consts.rs | 4 ++-- src/librustc/middle/trans/expr.rs | 6 +++--- src/librustc/middle/typeck/check/mod.rs | 16 ++++++++-------- src/librustc/util/common.rs | 6 +++--- src/libsyntax/ast.rs | 7 +++---- src/libsyntax/ext/build.rs | 14 +++++++------- src/libsyntax/fold.rs | 10 ++++------ src/libsyntax/parse/parser.rs | 11 ++++++----- src/libsyntax/print/pprust.rs | 8 ++++---- src/libsyntax/visit.rs | 2 +- 16 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index e250a2231574..aee8ae32178d 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -374,7 +374,7 @@ impl CFGBuilder { ast::expr_struct(_, ref fields, base) => { let base_exit = self.opt_expr(base, pred); let field_exprs: ~[@ast::expr] = - fields.iter().transform(|f| f.node.expr).collect(); + fields.iter().transform(|f| f.expr).collect(); self.straightline(expr, base_exit, field_exprs) } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 01350869fc11..59dbc7251da7 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -117,7 +117,7 @@ pub fn classify(e: &expr, ast::expr_struct(_, ref fs, None) => { let cs = do fs.iter().transform |f| { - classify(f.node.expr, tcx) + classify(f.expr, tcx) }; join_all(cs) } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 53622b667ff1..2cdae04478ca 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -705,7 +705,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> { ast::expr_struct(_, ref fields, with_expr) => { for fields.iter().advance |field| { - self.walk_expr(field.node.expr, in_out, loop_scopes); + self.walk_expr(field.expr, in_out, loop_scopes); } self.walk_opt_expr(with_expr, in_out, loop_scopes); } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 20497755e176..f9b42d593c25 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1161,7 +1161,7 @@ impl Liveness { expr_struct(_, ref fields, with_expr) => { let succ = self.propagate_through_opt_expr(with_expr, succ); do fields.rev_iter().fold(succ) |succ, field| { - self.propagate_through_expr(field.node.expr, succ) + self.propagate_through_expr(field.expr, succ) } } diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 2e2178df66e4..d8ce0a966363 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -394,7 +394,7 @@ impl VisitContext { expr_struct(_, ref fields, opt_with) => { for fields.iter().advance |field| { - self.consume_expr(field.node.expr, visitor); + self.consume_expr(field.expr, visitor); } for opt_with.iter().advance |with_expr| { @@ -417,7 +417,7 @@ impl VisitContext { // specified and (2) have a type that // moves-by-default: let consume_with = with_fields.iter().any(|tf| { - !fields.iter().any(|f| f.node.ident == tf.ident) && + !fields.iter().any(|f| f.ident == tf.ident) && ty::type_moves_by_default(self.tcx, tf.mt.ty) }); diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 0b747caea811..1ea32b3f4046 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -413,9 +413,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, Some(ref entry) => { debug!("(privacy checking) checking \ impl method"); - check_method(expr.span, - &entry.origin, - ident); + check_method(expr.span, &entry.origin, ident); } } } @@ -433,8 +431,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, for (*fields).iter().advance |field| { debug!("(privacy checking) checking \ field in struct literal"); - check_field(expr.span, id, - field.node.ident); + check_field(expr.span, id, field.ident); } } } @@ -448,8 +445,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, checking field in \ struct variant \ literal"); - check_field(expr.span, variant_id, - field.node.ident); + check_field(expr.span, variant_id, field.ident); } } _ => { @@ -499,8 +495,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, for fields.iter().advance |field| { debug!("(privacy checking) checking \ struct pattern"); - check_field(pattern.span, id, - field.ident); + check_field(pattern.span, id, field.ident); } } } @@ -513,9 +508,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, debug!("(privacy checking) \ checking field in \ struct variant pattern"); - check_field(pattern.span, - variant_id, - field.ident); + check_field(pattern.span, variant_id, field.ident); } } _ => { diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 69c8331bc9fb..9246ca1f6410 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -488,8 +488,8 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef { do expr::with_field_tys(tcx, ety, Some(e.id)) |discr, field_tys| { let cs = field_tys.map(|field_ty| { - match fs.iter().find_(|f| field_ty.ident == f.node.ident) { - Some(f) => const_expr(cx, (*f).node.expr), + match fs.iter().find_(|f| field_ty.ident == f.ident) { + Some(f) => const_expr(cx, (*f).expr), None => { cx.tcx.sess.span_bug(e.span, "missing struct field"); } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index adfc0b584856..d9fdf8d52c7d 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1124,7 +1124,7 @@ pub fn with_field_tys(tcx: ty::ctxt, } fn trans_rec_or_struct(bcx: block, - fields: &[ast::field], + fields: &[ast::Field], base: Option<@ast::expr>, expr_span: codemap::span, id: ast::node_id, @@ -1139,11 +1139,11 @@ fn trans_rec_or_struct(bcx: block, let mut need_base = vec::from_elem(field_tys.len(), true); let numbered_fields = do fields.map |field| { - let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.node.ident); + let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.ident); match opt_pos { Some(i) => { need_base[i] = false; - (i, field.node.expr) + (i, field.expr) } None => { tcx.sess.span_bug(field.span, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index d4066767ab8c..c04e1c2515cc 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1872,7 +1872,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, node_id: ast::node_id, substitutions: ty::substs, field_types: &[ty::field_ty], - ast_fields: &[ast::field], + ast_fields: &[ast::Field], check_completeness: bool) { let tcx = fcx.ccx.tcx; @@ -1888,21 +1888,21 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, for ast_fields.iter().advance |field| { let mut expected_field_type = ty::mk_err(); - let pair = class_field_map.find(&field.node.ident). + let pair = class_field_map.find(&field.ident). map_consume(|x| *x); match pair { None => { tcx.sess.span_err( field.span, fmt!("structure has no field named `%s`", - tcx.sess.str_of(field.node.ident))); + tcx.sess.str_of(field.ident))); error_happened = true; } Some((_, true)) => { tcx.sess.span_err( field.span, fmt!("field `%s` specified more than once", - tcx.sess.str_of(field.node.ident))); + tcx.sess.str_of(field.ident))); error_happened = true; } Some((field_id, false)) => { @@ -1910,7 +1910,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::lookup_field_type( tcx, class_id, field_id, &substitutions); class_field_map.insert( - field.node.ident, (field_id, true)); + field.ident, (field_id, true)); fields_found += 1; } } @@ -1918,7 +1918,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // an error, so we can continue typechecking check_expr_coercable_to_type( fcx, - field.node.expr, + field.expr, expected_field_type); } @@ -1961,7 +1961,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, id: ast::node_id, span: codemap::span, class_id: ast::def_id, - fields: &[ast::field], + fields: &[ast::Field], base_expr: Option<@ast::expr>) { let tcx = fcx.ccx.tcx; @@ -2051,7 +2051,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, span: codemap::span, enum_id: ast::def_id, variant_id: ast::def_id, - fields: &[ast::field]) { + fields: &[ast::Field]) { let tcx = fcx.ccx.tcx; // Look up the number of type parameters and the raw type, and diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index d15e47e61b5e..733e8093a9d7 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -54,10 +54,10 @@ pub fn indenter() -> _indenter { _indenter(()) } -pub fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; } +pub fn field_expr(f: ast::Field) -> @ast::expr { return f.expr; } -pub fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] { - fields.map(|f| f.node.expr) +pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::expr] { + fields.map(|f| f.expr) } // Takes a predicate p, returns true iff p is true for any subexpressions diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0874163118ab..95691c334b13 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -409,13 +409,12 @@ pub struct arm { } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct field_ { +pub struct Field { ident: ident, expr: @expr, + span: span, } -pub type field = spanned; - #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum blk_check_mode { default_blk, @@ -495,7 +494,7 @@ pub enum expr_ { expr_mac(mac), // A struct literal expression. - expr_struct(Path, ~[field], Option<@expr>), + expr_struct(Path, ~[Field], Option<@expr>), // A vector literal constructed from one repeated element. expr_repeat(@expr /* element */, @expr /* count */, mutability), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 3b32173dfb56..b3d65dfa9e2f 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -107,9 +107,9 @@ pub trait AstBuilder { args: ~[@ast::expr]) -> @ast::expr; fn expr_blk(&self, b: ast::Block) -> @ast::expr; - fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field; - fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr; - fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::field]) -> @ast::expr; + fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field; + fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::Field]) -> @ast::expr; + fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::Field]) -> @ast::expr; fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; @@ -477,14 +477,14 @@ impl AstBuilder for @ExtCtxt { fn expr_blk(&self, b: ast::Block) -> @ast::expr { self.expr(b.span, ast::expr_block(b)) } - fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field { - respan(span, ast::field_ { ident: name, expr: e }) + fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field { + ast::Field { ident: name, expr: e, span: span } } - fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr { + fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::Field]) -> @ast::expr { self.expr(span, ast::expr_struct(path, fields, None)) } fn expr_struct_ident(&self, span: span, - id: ast::ident, fields: ~[ast::field]) -> @ast::expr { + id: ast::ident, fields: ~[ast::Field]) -> @ast::expr { self.expr_struct(span, self.path_ident(span, id), fields) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6af08d0a8d52..f27e68641e3a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -488,12 +488,10 @@ pub fn wrap(f: @fn(&T, @ast_fold) -> T) } pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { - fn fold_field_(field: field, fld: @ast_fold) -> field { - spanned { - node: ast::field_ { - ident: fld.fold_ident(field.node.ident), - expr: fld.fold_expr(field.node.expr), - }, + fn fold_field_(field: Field, fld: @ast_fold) -> Field { + ast::Field { + ident: fld.fold_ident(field.ident), + expr: fld.fold_expr(field.expr), span: fld.new_span(field.span), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2e8e69561e8a..a4fd4929400a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -29,7 +29,7 @@ use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_self, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; use ast::{expr_vstore_slice, expr_vstore_box}; -use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; +use ast::{expr_vstore_mut_slice, expr_while, extern_fn, Field, fn_decl}; use ast::{expr_vstore_uniq, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod}; use ast::{ident, impure_fn, inherited, item, item_, item_static}; @@ -1498,15 +1498,16 @@ impl Parser { } // parse ident COLON expr - pub fn parse_field(&self) -> field { + pub fn parse_field(&self) -> Field { let lo = self.span.lo; let i = self.parse_ident(); self.expect(&token::COLON); let e = self.parse_expr(); - spanned(lo, e.span.hi, ast::field_ { + ast::Field { ident: i, - expr: e - }) + expr: e, + span: mk_sp(lo, e.span.hi), + } } pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7918e503957f..8e2c24cacfed 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1103,14 +1103,14 @@ pub fn print_call_post(s: @ps, } pub fn print_expr(s: @ps, expr: &ast::expr) { - fn print_field(s: @ps, field: &ast::field) { + fn print_field(s: @ps, field: &ast::Field) { ibox(s, indent_unit); - print_ident(s, field.node.ident); + print_ident(s, field.ident); word_space(s, ":"); - print_expr(s, field.node.expr); + print_expr(s, field.expr); end(s); } - fn get_span(field: &ast::field) -> codemap::span { return field.span; } + fn get_span(field: &ast::Field) -> codemap::span { return field.span; } maybe_print_comment(s, expr.span.lo); ibox(s, indent_unit); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ce707979c06f..7e86adfcb630 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -474,7 +474,7 @@ pub fn visit_expr(ex: @expr, (e, v): (E, vt)) { expr_struct(ref p, ref flds, base) => { visit_path(p, (e.clone(), v)); for flds.iter().advance |f| { - (v.visit_expr)(f.node.expr, (e.clone(), v)); + (v.visit_expr)(f.expr, (e.clone(), v)); } visit_expr_opt(base, (e.clone(), v)); }