Skip to content

Commit

Permalink
Field identifiers now include specific spans (Closes #8263).
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonesque committed Oct 29, 2013
1 parent dba6070 commit 01ab854
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/moves.rs
Expand Up @@ -420,7 +420,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.ident.name == tf.ident.name) &&
!fields.iter().any(|f| f.ident.node.name == tf.ident.name) &&
ty::type_moves_by_default(self.tcx, tf.mt.ty)
});

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/privacy.rs
Expand Up @@ -716,15 +716,15 @@ impl<'self> Visitor<()> for PrivacyVisitor<'self> {
match ty::get(ty::expr_ty(self.tcx, expr)).sty {
ty::ty_struct(id, _) => {
for field in (*fields).iter() {
self.check_field(expr.span, id, field.ident);
self.check_field(expr.span, id, field.ident.node);
}
}
ty::ty_enum(_, _) => {
match self.tcx.def_map.get_copy(&expr.id) {
ast::DefVariant(_, variant_id, _) => {
for field in fields.iter() {
self.check_field(expr.span, variant_id,
field.ident);
field.ident.node);
}
}
_ => self.tcx.sess.span_bug(expr.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/consts.rs
Expand Up @@ -508,7 +508,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext,
|discr, field_tys| {
let cs = field_tys.iter().enumerate()
.map(|(ix, &field_ty)| {
match fs.iter().find(|f| field_ty.ident.name == f.ident.name) {
match fs.iter().find(|f| field_ty.ident.name == f.ident.node.name) {
Some(f) => const_expr(cx, (*f).expr),
None => {
match base_val {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/expr.rs
Expand Up @@ -1211,7 +1211,7 @@ fn trans_rec_or_struct(bcx: @mut Block,
let numbered_fields = do fields.map |field| {
let opt_pos =
field_tys.iter().position(|field_ty|
field_ty.ident.name == field.ident.name);
field_ty.ident.name == field.ident.node.name);
match opt_pos {
Some(i) => {
need_base[i] = false;
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -2030,28 +2030,28 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
for field in ast_fields.iter() {
let mut expected_field_type = ty::mk_err();

let pair = class_field_map.find(&field.ident.name).map(|x| *x);
let pair = class_field_map.find(&field.ident.node.name).map(|x| *x);
match pair {
None => {
tcx.sess.span_err(
field.span,
field.ident.span,
format!("structure has no field named `{}`",
tcx.sess.str_of(field.ident)));
tcx.sess.str_of(field.ident.node)));
error_happened = true;
}
Some((_, true)) => {
tcx.sess.span_err(
field.span,
field.ident.span,
format!("field `{}` specified more than once",
tcx.sess.str_of(field.ident)));
tcx.sess.str_of(field.ident.node)));
error_happened = true;
}
Some((field_id, false)) => {
expected_field_type =
ty::lookup_field_type(
tcx, class_id, field_id, &substitutions);
class_field_map.insert(
field.ident.name, (field_id, true));
field.ident.node.name, (field_id, true));
fields_found += 1;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -471,11 +471,13 @@ pub struct Arm {

#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct Field {
ident: Ident,
ident: SpannedIdent,
expr: @Expr,
span: Span,
}

pub type SpannedIdent = Spanned<Ident>;

#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum BlockCheckMode {
DefaultBlock,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Expand Up @@ -529,7 +529,7 @@ impl AstBuilder for @ExtCtxt {
self.expr(b.span, ast::ExprBlock(b))
}
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field {
ast::Field { ident: name, expr: e, span: span }
ast::Field { ident: respan(span, name), expr: e, span: span }
}
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr {
self.expr(span, ast::ExprStruct(path, fields, None))
Expand Down
7 changes: 4 additions & 3 deletions src/libsyntax/fold.rs
Expand Up @@ -10,7 +10,7 @@

use ast::*;
use ast;
use codemap::{Span, Spanned};
use codemap::{respan, Span, Spanned};
use parse::token;
use opt_vec::OptVec;

Expand Down Expand Up @@ -551,7 +551,7 @@ fn fold_struct_field<T:ast_fold>(f: @struct_field, fld: &T) -> @struct_field {

fn fold_field_<T:ast_fold>(field: Field, folder: &T) -> Field {
ast::Field {
ident: folder.fold_ident(field.ident),
ident: respan(field.ident.span, folder.fold_ident(field.ident.node)),
expr: folder.fold_expr(field.expr),
span: folder.new_span(field.span),
}
Expand Down Expand Up @@ -797,7 +797,8 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
folder.fold_expr(er))
}
ExprField(el, id, ref tys) => {
ExprField(folder.fold_expr(el), folder.fold_ident(id),
ExprField(folder.fold_expr(el),
folder.fold_ident(id),
tys.map(|x| folder.fold_ty(x)))
}
ExprIndex(callee_id, el, er) => {
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -1549,10 +1549,11 @@ impl Parser {
pub fn parse_field(&self) -> Field {
let lo = self.span.lo;
let i = self.parse_ident();
let hi = self.last_span.hi;
self.expect(&token::COLON);
let e = self.parse_expr();
ast::Field {
ident: i,
ident: spanned(lo, hi, i),
expr: e,
span: mk_sp(lo, e.span.hi),
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Expand Up @@ -1111,7 +1111,7 @@ pub fn print_call_post(s: @ps,
pub fn print_expr(s: @ps, expr: &ast::Expr) {
fn print_field(s: @ps, field: &ast::Field) {
ibox(s, indent_unit);
print_ident(s, field.ident);
print_ident(s, field.ident.node);
word_space(s, ":");
print_expr(s, field.expr);
end(s);
Expand Down

0 comments on commit 01ab854

Please sign in to comment.