Skip to content

Commit 64fb709

Browse files
committed
Use Names in hir::{Field, ExprMethodCall, ExprField}
1 parent a4af958 commit 64fb709

File tree

19 files changed

+79
-91
lines changed

19 files changed

+79
-91
lines changed

src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
314314
let field_pats = fields.iter().map(|field| codemap::Spanned {
315315
span: codemap::DUMMY_SP,
316316
node: hir::FieldPat {
317-
ident: field.ident.node,
317+
ident: ast::Ident::new(field.name.node),
318318
pat: const_expr_to_pat(tcx, &*field.expr, span),
319319
is_shorthand: false,
320320
},
@@ -1040,8 +1040,8 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10401040
if let hir::ExprStruct(_, ref fields, _) = tcx.map.expect_expr(struct_id).node {
10411041
// Check that the given field exists and evaluate it
10421042
// if the idents are compared run-pass/issue-19244 fails
1043-
if let Some(f) = fields.iter().find(|f| f.ident.node.name
1044-
== field_name.node.name) {
1043+
if let Some(f) = fields.iter().find(|f| f.name.node
1044+
== field_name.node) {
10451045
return eval_const_expr_partial(tcx, &*f.expr, base_hint)
10461046
} else {
10471047
signal!(e, MissingStructField);

src/librustc/middle/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
227227
hir::ExprMethodCall(..) => {
228228
self.lookup_and_handle_method(expr.id);
229229
}
230-
hir::ExprField(ref lhs, ref ident) => {
231-
self.handle_field_access(&**lhs, ident.node.name);
230+
hir::ExprField(ref lhs, ref name) => {
231+
self.handle_field_access(&**lhs, name.node);
232232
}
233233
hir::ExprTupField(ref lhs, idx) => {
234234
self.handle_tup_field_access(&**lhs, idx.node);

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
710710
-> bool
711711
{
712712
fields.iter().any(
713-
|f| f.ident.node.name == field.name)
713+
|f| f.name.node == field.name)
714714
}
715715
}
716716

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
474474
expr.id,
475475
expr,
476476
base_cmt);
477-
Ok(self.cat_field(expr, base_cmt, f_name.node.name, expr_ty))
477+
Ok(self.cat_field(expr, base_cmt, f_name.node, expr_ty))
478478
}
479479

480480
hir::ExprTupField(ref base, idx) => {

src/librustc/middle/pat_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use util::nodemap::FnvHashMap;
1616
use syntax::ast;
1717
use rustc_front::hir;
1818
use rustc_front::util::walk_pat;
19-
use syntax::codemap::{Span, DUMMY_SP};
19+
use syntax::codemap::{Span, Spanned, DUMMY_SP};
2020

2121
pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
2222

@@ -109,7 +109,7 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
109109
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
110110
/// `match foo() { Some(a) => (), None => () }`
111111
pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
112-
I: FnMut(hir::BindingMode, ast::NodeId, Span, &hir::SpannedIdent),
112+
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
113113
{
114114
walk_pat(pat, |p| {
115115
match p.node {

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ pub fn check_expr(tcx: &ty::ctxt, e: &hir::Expr,
418418
hir::ExprField(ref base_e, ref field) => {
419419
span = field.span;
420420
match tcx.expr_ty_adjusted(base_e).sty {
421-
ty::TyStruct(def, _) => def.struct_variant().field_named(field.node.name).did,
421+
ty::TyStruct(def, _) => def.struct_variant().field_named(field.node).did,
422422
_ => tcx.sess.span_bug(e.span,
423423
"stability::check_expr: named field access on non-struct")
424424
}
@@ -441,7 +441,7 @@ pub fn check_expr(tcx: &ty::ctxt, e: &hir::Expr,
441441
// in the construction expression.
442442
for field in expr_fields {
443443
let did = def.struct_variant()
444-
.field_named(field.ident.node.name)
444+
.field_named(field.name.node)
445445
.did;
446446
maybe_do_stability_check(tcx, did, field.span, cb);
447447
}

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.node),
273-
ExprField(_, id) => SawExprField(id.node.name.as_str()),
273+
ExprField(_, name) => SawExprField(name.node.as_str()),
274274
ExprTupField(_, id) => SawExprTupField(id.node),
275275
ExprIndex(..) => SawExprIndex,
276276
ExprRange(..) => SawExprRange,

src/librustc_front/fold.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,9 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
721721
}
722722
}
723723

724-
pub fn noop_fold_field<T: Folder>(Field {ident, expr, span}: Field, folder: &mut T) -> Field {
724+
pub fn noop_fold_field<T: Folder>(Field {name, expr, span}: Field, folder: &mut T) -> Field {
725725
Field {
726-
ident: respan(ident.span, fold_ident(folder, ident.node)),
726+
name: respan(folder.new_span(name.span), folder.fold_name(name.node)),
727727
expr: folder.fold_expr(expr),
728728
span: folder.new_span(span)
729729
}
@@ -1050,9 +1050,9 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
10501050
ExprCall(folder.fold_expr(f),
10511051
args.move_map(|x| folder.fold_expr(x)))
10521052
}
1053-
ExprMethodCall(i, tps, args) => {
1053+
ExprMethodCall(name, tps, args) => {
10541054
ExprMethodCall(
1055-
respan(folder.new_span(i.span), fold_ident(folder, i.node)),
1055+
respan(folder.new_span(name.span), folder.fold_name(name.node)),
10561056
tps.move_map(|x| folder.fold_ty(x)),
10571057
args.move_map(|x| folder.fold_expr(x)))
10581058
}
@@ -1102,10 +1102,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
11021102
folder.fold_expr(el),
11031103
folder.fold_expr(er))
11041104
}
1105-
ExprField(el, ident) => {
1105+
ExprField(el, name) => {
11061106
ExprField(folder.fold_expr(el),
1107-
respan(folder.new_span(ident.span),
1108-
fold_ident(folder, ident.node)))
1107+
respan(folder.new_span(name.span),
1108+
folder.fold_name(name.node)))
11091109
}
11101110
ExprTupField(el, ident) => {
11111111
ExprTupField(folder.fold_expr(el),

src/librustc_front/hir.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ use util;
5252
use std::fmt;
5353
use serialize::{Encodable, Encoder, Decoder};
5454

55-
56-
/// Function name (not all functions have names)
57-
pub type FnIdent = Option<Ident>;
58-
5955
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
6056
pub struct Lifetime {
6157
pub id: NodeId,
@@ -416,7 +412,7 @@ pub enum Pat_ {
416412
/// which it is. The resolver determines this, and
417413
/// records this pattern's NodeId in an auxiliary
418414
/// set (of "PatIdents that refer to nullary enums")
419-
PatIdent(BindingMode, SpannedIdent, Option<P<Pat>>),
415+
PatIdent(BindingMode, Spanned<Ident>, Option<P<Pat>>),
420416

421417
/// "None" means a * pattern where we don't bind the fields to names.
422418
PatEnum(Path, Option<Vec<P<Pat>>>),
@@ -564,13 +560,11 @@ pub struct Arm {
564560

565561
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
566562
pub struct Field {
567-
pub ident: SpannedIdent,
563+
pub name: Spanned<Name>,
568564
pub expr: P<Expr>,
569565
pub span: Span,
570566
}
571567

572-
pub type SpannedIdent = Spanned<Ident>;
573-
574568
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
575569
pub enum BlockCheckMode {
576570
DefaultBlock,
@@ -612,7 +606,7 @@ pub enum Expr_ {
612606
ExprCall(P<Expr>, Vec<P<Expr>>),
613607
/// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
614608
///
615-
/// The `SpannedIdent` is the identifier for the method name.
609+
/// The `Spanned<Name>` is the identifier for the method name.
616610
/// The vector of `Ty`s are the ascripted type parameters for the method
617611
/// (within the angle brackets).
618612
///
@@ -622,7 +616,7 @@ pub enum Expr_ {
622616
///
623617
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
624618
/// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
625-
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
619+
ExprMethodCall(Spanned<Name>, Vec<P<Ty>>, Vec<P<Expr>>),
626620
/// A tuple (`(a, b, c ,d)`)
627621
ExprTup(Vec<P<Expr>>),
628622
/// A binary operation (For example: `a + b`, `a * b`)
@@ -662,7 +656,7 @@ pub enum Expr_ {
662656
/// For example, `a += 1`.
663657
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
664658
/// Access of a named struct field (`obj.foo`)
665-
ExprField(P<Expr>, SpannedIdent),
659+
ExprField(P<Expr>, Spanned<Name>),
666660
/// Access of an unnamed field of a struct or tuple-struct
667661
///
668662
/// For example, `foo.0`.
@@ -682,9 +676,9 @@ pub enum Expr_ {
682676
/// A referencing operation (`&a` or `&mut a`)
683677
ExprAddrOf(Mutability, P<Expr>),
684678
/// A `break`, with an optional label to break
685-
ExprBreak(Option<SpannedIdent>),
679+
ExprBreak(Option<Spanned<Ident>>),
686680
/// A `continue`, with an optional label
687-
ExprAgain(Option<SpannedIdent>),
681+
ExprAgain(Option<Spanned<Ident>>),
688682
/// A `return`, with an optional value to be returned
689683
ExprRet(Option<P<Expr>>),
690684

@@ -744,13 +738,6 @@ pub struct MutTy {
744738
pub mutbl: Mutability,
745739
}
746740

747-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
748-
pub struct TypeField {
749-
pub ident: Ident,
750-
pub mt: MutTy,
751-
pub span: Span,
752-
}
753-
754741
/// Represents a method's signature in a trait declaration,
755742
/// or in an implementation.
756743
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]

src/librustc_front/lowering.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use hir;
1414

1515
use syntax::ast::*;
1616
use syntax::ptr::P;
17-
use syntax::codemap::Spanned;
17+
use syntax::codemap::{respan, Spanned};
1818
use syntax::owned_slice::OwnedSlice;
1919

2020

@@ -370,7 +370,10 @@ pub fn lower_struct_field(f: &StructField) -> hir::StructField {
370370
}
371371

372372
pub fn lower_field(f: &Field) -> hir::Field {
373-
hir::Field { ident: f.ident, expr: lower_expr(&f.expr), span: f.span }
373+
hir::Field {
374+
name: respan(f.ident.span, f.ident.node.name),
375+
expr: lower_expr(&f.expr), span: f.span
376+
}
374377
}
375378

376379
pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
@@ -704,7 +707,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
704707
}
705708
ExprMethodCall(i, ref tps, ref args) => {
706709
hir::ExprMethodCall(
707-
i,
710+
respan(i.span, i.node.name),
708711
tps.iter().map(|x| lower_ty(x)).collect(),
709712
args.iter().map(|x| lower_expr(x)).collect())
710713
}
@@ -755,7 +758,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
755758
lower_expr(er))
756759
}
757760
ExprField(ref el, ident) => {
758-
hir::ExprField(lower_expr(el), ident)
761+
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
759762
}
760763
ExprTupField(ref el, ident) => {
761764
hir::ExprTupField(lower_expr(el), ident)

0 commit comments

Comments
 (0)