Skip to content

Commit 9945052

Browse files
Rymanalexcrichton
authored andcommitted
rustc: Improve span for error about using a method as a field.
libsyntax: ExprField now contains a SpannedIdent rather than Ident. [breaking-change]
1 parent 051abae commit 9945052

File tree

15 files changed

+43
-25
lines changed

15 files changed

+43
-25
lines changed

src/librustc/back/svh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ mod svh_visitor {
270270
ExprBlock(..) => SawExprBlock,
271271
ExprAssign(..) => SawExprAssign,
272272
ExprAssignOp(op, _, _) => SawExprAssignOp(op),
273-
ExprField(_, id, _) => SawExprField(content(id)),
273+
ExprField(_, id, _) => SawExprField(content(id.node)),
274274
ExprIndex(..) => SawExprIndex,
275275
ExprPath(..) => SawExprPath,
276276
ExprAddrOf(m, _) => SawExprAddrOf(m),

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a> Visitor<MarkSymbolVisitorContext> for MarkSymbolVisitor<'a> {
235235
self.lookup_and_handle_method(expr.id, expr.span);
236236
}
237237
ast::ExprField(ref lhs, ref ident, _) => {
238-
self.handle_field_access(&**lhs, ident);
238+
self.handle_field_access(&**lhs, &ident.node);
239239
}
240240
_ => ()
241241
}

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
447447

448448
ast::ExprField(ref base, f_name, _) => {
449449
let base_cmt = if_ok!(self.cat_expr(&**base));
450-
Ok(self.cat_field(expr, base_cmt, f_name, expr_ty))
450+
Ok(self.cat_field(expr, base_cmt, f_name.node, expr_ty))
451451
}
452452

453453
ast::ExprIndex(ref base, _) => {

src/librustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
801801
ast::ExprField(ref base, ident, _) => {
802802
match ty::get(ty::expr_ty_adjusted(self.tcx, &**base)).sty {
803803
ty::ty_struct(id, _) => {
804-
self.check_field(expr.span, id, NamedField(ident));
804+
self.check_field(expr.span, id, NamedField(ident.node));
805805
}
806806
_ => {}
807807
}

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5241,7 +5241,7 @@ impl<'a> Resolver<'a> {
52415241
// field, we need to add any trait methods we find that match
52425242
// the field name so that we can do some nice error reporting
52435243
// later on in typeck.
5244-
let traits = self.search_for_traits_containing_method(ident.name);
5244+
let traits = self.search_for_traits_containing_method(ident.node.name);
52455245
self.trait_map.insert(expr.id, traits);
52465246
}
52475247
ExprMethodCall(ident, _, _) => {

src/librustc/middle/save/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ impl<'l> Visitor<DxrVisitorEnv> for DxrVisitor<'l> {
12101210
ty::ty_struct(def_id, _) => {
12111211
let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id);
12121212
for f in fields.iter() {
1213-
if f.name == ident.name {
1213+
if f.name == ident.node.name {
12141214
let sub_span = self.span.span_for_last_ident(ex.span);
12151215
self.fmt.ref_str(recorder::VarRef,
12161216
ex.span,

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
419419
let brepr = adt::represent_type(cx, bt);
420420
let (bv, inlineable) = const_expr(cx, &**base, is_local);
421421
expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| {
422-
let ix = ty::field_idx_strict(cx.tcx(), field.name, field_tys);
422+
let ix = ty::field_idx_strict(cx.tcx(), field.node.name, field_tys);
423423
(adt::const_get_field(cx, &*brepr, bv, discr, ix), inlineable)
424424
})
425425
}

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn trans_datum_unadjusted<'a>(bcx: &'a Block<'a>,
389389
trans_def(bcx, expr, bcx.def(expr.id))
390390
}
391391
ast::ExprField(ref base, ident, _) => {
392-
trans_rec_field(bcx, &**base, ident)
392+
trans_rec_field(bcx, &**base, ident.node)
393393
}
394394
ast::ExprIndex(ref base, ref idx) => {
395395
trans_index(bcx, expr, &**base, &**idx)

src/librustc/middle/typeck/check/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
23522352
expr: &ast::Expr,
23532353
lvalue_pref: LvaluePreference,
23542354
base: &ast::Expr,
2355-
field: ast::Name,
2355+
field: &ast::SpannedIdent,
23562356
tys: &[ast::P<ast::Ty>]) {
23572357
let tcx = fcx.ccx.tcx;
23582358
check_expr_with_lvalue_pref(fcx, base, lvalue_pref);
@@ -2365,7 +2365,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
23652365
ty::ty_struct(base_id, ref substs) => {
23662366
debug!("struct named {}", ppaux::ty_to_str(tcx, base_t));
23672367
let fields = ty::lookup_struct_fields(tcx, base_id);
2368-
lookup_field_ty(tcx, base_id, fields.as_slice(), field, &(*substs))
2368+
lookup_field_ty(tcx, base_id, fields.as_slice(), field.node.name, &(*substs))
23692369
}
23702370
_ => None
23712371
}
@@ -2383,7 +2383,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
23832383
match method::lookup(fcx,
23842384
expr,
23852385
base,
2386-
field,
2386+
field.node.name,
23872387
expr_t,
23882388
tps.as_slice(),
23892389
DontDerefArgs,
@@ -2392,14 +2392,14 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
23922392
IgnoreStaticMethods) {
23932393
Some(_) => {
23942394
fcx.type_error_message(
2395-
expr.span,
2395+
field.span,
23962396
|actual| {
23972397
format!("attempted to take value of method `{}` on type \
2398-
`{}`", token::get_name(field), actual)
2398+
`{}`", token::get_ident(field.node), actual)
23992399
},
24002400
expr_t, None);
24012401

2402-
tcx.sess.span_note(expr.span,
2402+
tcx.sess.span_note(field.span,
24032403
"maybe a missing `()` to call it? If not, try an anonymous function.");
24042404
}
24052405

@@ -2410,7 +2410,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
24102410
format!("attempted access of field `{}` on \
24112411
type `{}`, but no field with that \
24122412
name was found",
2413-
token::get_name(field),
2413+
token::get_ident(field.node),
24142414
actual)
24152415
},
24162416
expr_t, None);
@@ -3214,7 +3214,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
32143214
}
32153215
}
32163216
ast::ExprField(ref base, ref field, ref tys) => {
3217-
check_field(fcx, expr, lvalue_pref, &**base, field.name, tys.as_slice());
3217+
check_field(fcx, expr, lvalue_pref, &**base, field, tys.as_slice());
32183218
}
32193219
ast::ExprIndex(ref base, ref idx) => {
32203220
check_expr_with_lvalue_pref(fcx, &**base, lvalue_pref);

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub enum Expr_ {
464464

465465
ExprAssign(Gc<Expr>, Gc<Expr>),
466466
ExprAssignOp(BinOp, Gc<Expr>, Gc<Expr>),
467-
ExprField(Gc<Expr>, Ident, Vec<P<Ty>>),
467+
ExprField(Gc<Expr>, SpannedIdent, Vec<P<Ty>>),
468468
ExprIndex(Gc<Expr>, Gc<Expr>),
469469

470470
/// Expression that looks like a "name". For example,

0 commit comments

Comments
 (0)