Skip to content

Commit

Permalink
Use Names in hir::{Field, ExprMethodCall, ExprField}
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 22, 2015
1 parent a4af958 commit 64fb709
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 91 deletions.
6 changes: 3 additions & 3 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -314,7 +314,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
let field_pats = fields.iter().map(|field| codemap::Spanned {
span: codemap::DUMMY_SP,
node: hir::FieldPat {
ident: field.ident.node,
ident: ast::Ident::new(field.name.node),
pat: const_expr_to_pat(tcx, &*field.expr, span),
is_shorthand: false,
},
Expand Down Expand Up @@ -1040,8 +1040,8 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
if let hir::ExprStruct(_, ref fields, _) = tcx.map.expect_expr(struct_id).node {
// Check that the given field exists and evaluate it
// if the idents are compared run-pass/issue-19244 fails
if let Some(f) = fields.iter().find(|f| f.ident.node.name
== field_name.node.name) {
if let Some(f) = fields.iter().find(|f| f.name.node
== field_name.node) {
return eval_const_expr_partial(tcx, &*f.expr, base_hint)
} else {
signal!(e, MissingStructField);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dead.rs
Expand Up @@ -227,8 +227,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
hir::ExprMethodCall(..) => {
self.lookup_and_handle_method(expr.id);
}
hir::ExprField(ref lhs, ref ident) => {
self.handle_field_access(&**lhs, ident.node.name);
hir::ExprField(ref lhs, ref name) => {
self.handle_field_access(&**lhs, name.node);
}
hir::ExprTupField(ref lhs, idx) => {
self.handle_tup_field_access(&**lhs, idx.node);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -710,7 +710,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
-> bool
{
fields.iter().any(
|f| f.ident.node.name == field.name)
|f| f.name.node == field.name)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -474,7 +474,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
expr.id,
expr,
base_cmt);
Ok(self.cat_field(expr, base_cmt, f_name.node.name, expr_ty))
Ok(self.cat_field(expr, base_cmt, f_name.node, expr_ty))
}

hir::ExprTupField(ref base, idx) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/pat_util.rs
Expand Up @@ -16,7 +16,7 @@ use util::nodemap::FnvHashMap;
use syntax::ast;
use rustc_front::hir;
use rustc_front::util::walk_pat;
use syntax::codemap::{Span, DUMMY_SP};
use syntax::codemap::{Span, Spanned, DUMMY_SP};

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

Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }`
pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
I: FnMut(hir::BindingMode, ast::NodeId, Span, &hir::SpannedIdent),
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
{
walk_pat(pat, |p| {
match p.node {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Expand Up @@ -418,7 +418,7 @@ pub fn check_expr(tcx: &ty::ctxt, e: &hir::Expr,
hir::ExprField(ref base_e, ref field) => {
span = field.span;
match tcx.expr_ty_adjusted(base_e).sty {
ty::TyStruct(def, _) => def.struct_variant().field_named(field.node.name).did,
ty::TyStruct(def, _) => def.struct_variant().field_named(field.node).did,
_ => tcx.sess.span_bug(e.span,
"stability::check_expr: named field access on non-struct")
}
Expand All @@ -441,7 +441,7 @@ pub fn check_expr(tcx: &ty::ctxt, e: &hir::Expr,
// in the construction expression.
for field in expr_fields {
let did = def.struct_variant()
.field_named(field.ident.node.name)
.field_named(field.name.node)
.did;
maybe_do_stability_check(tcx, did, field.span, cb);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/svh.rs
Expand Up @@ -270,7 +270,7 @@ mod svh_visitor {
ExprBlock(..) => SawExprBlock,
ExprAssign(..) => SawExprAssign,
ExprAssignOp(op, _, _) => SawExprAssignOp(op.node),
ExprField(_, id) => SawExprField(id.node.name.as_str()),
ExprField(_, name) => SawExprField(name.node.as_str()),
ExprTupField(_, id) => SawExprTupField(id.node),
ExprIndex(..) => SawExprIndex,
ExprRange(..) => SawExprRange,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_front/fold.rs
Expand Up @@ -721,9 +721,9 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
}
}

pub fn noop_fold_field<T: Folder>(Field {ident, expr, span}: Field, folder: &mut T) -> Field {
pub fn noop_fold_field<T: Folder>(Field {name, expr, span}: Field, folder: &mut T) -> Field {
Field {
ident: respan(ident.span, fold_ident(folder, ident.node)),
name: respan(folder.new_span(name.span), folder.fold_name(name.node)),
expr: folder.fold_expr(expr),
span: folder.new_span(span)
}
Expand Down Expand Up @@ -1050,9 +1050,9 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
ExprCall(folder.fold_expr(f),
args.move_map(|x| folder.fold_expr(x)))
}
ExprMethodCall(i, tps, args) => {
ExprMethodCall(name, tps, args) => {
ExprMethodCall(
respan(folder.new_span(i.span), fold_ident(folder, i.node)),
respan(folder.new_span(name.span), folder.fold_name(name.node)),
tps.move_map(|x| folder.fold_ty(x)),
args.move_map(|x| folder.fold_expr(x)))
}
Expand Down Expand Up @@ -1102,10 +1102,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
folder.fold_expr(el),
folder.fold_expr(er))
}
ExprField(el, ident) => {
ExprField(el, name) => {
ExprField(folder.fold_expr(el),
respan(folder.new_span(ident.span),
fold_ident(folder, ident.node)))
respan(folder.new_span(name.span),
folder.fold_name(name.node)))
}
ExprTupField(el, ident) => {
ExprTupField(folder.fold_expr(el),
Expand Down
27 changes: 7 additions & 20 deletions src/librustc_front/hir.rs
Expand Up @@ -52,10 +52,6 @@ use util;
use std::fmt;
use serialize::{Encodable, Encoder, Decoder};


/// Function name (not all functions have names)
pub type FnIdent = Option<Ident>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
pub struct Lifetime {
pub id: NodeId,
Expand Down Expand Up @@ -416,7 +412,7 @@ pub enum Pat_ {
/// which it is. The resolver determines this, and
/// records this pattern's NodeId in an auxiliary
/// set (of "PatIdents that refer to nullary enums")
PatIdent(BindingMode, SpannedIdent, Option<P<Pat>>),
PatIdent(BindingMode, Spanned<Ident>, Option<P<Pat>>),

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

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Field {
pub ident: SpannedIdent,
pub name: Spanned<Name>,
pub expr: P<Expr>,
pub span: Span,
}

pub type SpannedIdent = Spanned<Ident>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum BlockCheckMode {
DefaultBlock,
Expand Down Expand Up @@ -612,7 +606,7 @@ pub enum Expr_ {
ExprCall(P<Expr>, Vec<P<Expr>>),
/// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
///
/// The `SpannedIdent` is the identifier for the method name.
/// The `Spanned<Name>` is the identifier for the method name.
/// The vector of `Ty`s are the ascripted type parameters for the method
/// (within the angle brackets).
///
Expand All @@ -622,7 +616,7 @@ pub enum Expr_ {
///
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
/// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
ExprMethodCall(Spanned<Name>, Vec<P<Ty>>, Vec<P<Expr>>),
/// A tuple (`(a, b, c ,d)`)
ExprTup(Vec<P<Expr>>),
/// A binary operation (For example: `a + b`, `a * b`)
Expand Down Expand Up @@ -662,7 +656,7 @@ pub enum Expr_ {
/// For example, `a += 1`.
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
/// Access of a named struct field (`obj.foo`)
ExprField(P<Expr>, SpannedIdent),
ExprField(P<Expr>, Spanned<Name>),
/// Access of an unnamed field of a struct or tuple-struct
///
/// For example, `foo.0`.
Expand All @@ -682,9 +676,9 @@ pub enum Expr_ {
/// A referencing operation (`&a` or `&mut a`)
ExprAddrOf(Mutability, P<Expr>),
/// A `break`, with an optional label to break
ExprBreak(Option<SpannedIdent>),
ExprBreak(Option<Spanned<Ident>>),
/// A `continue`, with an optional label
ExprAgain(Option<SpannedIdent>),
ExprAgain(Option<Spanned<Ident>>),
/// A `return`, with an optional value to be returned
ExprRet(Option<P<Expr>>),

Expand Down Expand Up @@ -744,13 +738,6 @@ pub struct MutTy {
pub mutbl: Mutability,
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TypeField {
pub ident: Ident,
pub mt: MutTy,
pub span: Span,
}

/// Represents a method's signature in a trait declaration,
/// or in an implementation.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_front/lowering.rs
Expand Up @@ -14,7 +14,7 @@ use hir;

use syntax::ast::*;
use syntax::ptr::P;
use syntax::codemap::Spanned;
use syntax::codemap::{respan, Spanned};
use syntax::owned_slice::OwnedSlice;


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

pub fn lower_field(f: &Field) -> hir::Field {
hir::Field { ident: f.ident, expr: lower_expr(&f.expr), span: f.span }
hir::Field {
name: respan(f.ident.span, f.ident.node.name),
expr: lower_expr(&f.expr), span: f.span
}
}

pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
Expand Down Expand Up @@ -704,7 +707,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
}
ExprMethodCall(i, ref tps, ref args) => {
hir::ExprMethodCall(
i,
respan(i.span, i.node.name),
tps.iter().map(|x| lower_ty(x)).collect(),
args.iter().map(|x| lower_expr(x)).collect())
}
Expand Down Expand Up @@ -755,7 +758,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
lower_expr(er))
}
ExprField(ref el, ident) => {
hir::ExprField(lower_expr(el), ident)
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
}
ExprTupField(ref el, ident) => {
hir::ExprTupField(lower_expr(el), ident)
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_front/print/pprust.rs
Expand Up @@ -13,7 +13,7 @@ pub use self::AnnNode::*;
use syntax::abi;
use syntax::ast;
use syntax::owned_slice::OwnedSlice;
use syntax::codemap::{self, CodeMap, BytePos};
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
use syntax::diagnostic;
use syntax::parse::token::{self, BinOpToken};
use syntax::parse::lexer::comments;
Expand Down Expand Up @@ -1223,7 +1223,7 @@ impl<'a> State<'a> {
&fields[..],
|s, field| {
try!(s.ibox(indent_unit));
try!(s.print_ident(field.ident.node));
try!(s.print_name(field.name.node));
try!(s.word_space(":"));
try!(s.print_expr(&*field.expr));
s.end()
Expand Down Expand Up @@ -1265,13 +1265,13 @@ impl<'a> State<'a> {
}

fn print_expr_method_call(&mut self,
ident: hir::SpannedIdent,
name: Spanned<ast::Name>,
tys: &[P<hir::Ty>],
args: &[P<hir::Expr>]) -> io::Result<()> {
let base_args = &args[1..];
try!(self.print_expr(&*args[0]));
try!(word(&mut self.s, "."));
try!(self.print_ident(ident.node));
try!(self.print_name(name.node));
if !tys.is_empty() {
try!(word(&mut self.s, "::<"));
try!(self.commasep(Inconsistent, tys,
Expand Down Expand Up @@ -1329,8 +1329,8 @@ impl<'a> State<'a> {
hir::ExprCall(ref func, ref args) => {
try!(self.print_expr_call(&**func, &args[..]));
}
hir::ExprMethodCall(ident, ref tys, ref args) => {
try!(self.print_expr_method_call(ident, &tys[..], &args[..]));
hir::ExprMethodCall(name, ref tys, ref args) => {
try!(self.print_expr_method_call(name, &tys[..], &args[..]));
}
hir::ExprBinary(op, ref lhs, ref rhs) => {
try!(self.print_expr_binary(op, &**lhs, &**rhs));
Expand Down Expand Up @@ -1435,10 +1435,10 @@ impl<'a> State<'a> {
try!(self.word_space("="));
try!(self.print_expr(&**rhs));
}
hir::ExprField(ref expr, id) => {
hir::ExprField(ref expr, name) => {
try!(self.print_expr(&**expr));
try!(word(&mut self.s, "."));
try!(self.print_ident(id.node));
try!(self.print_name(name.node));
}
hir::ExprTupField(ref expr, id) => {
try!(self.print_expr(&**expr));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/tcx/expr.rs
Expand Up @@ -288,9 +288,9 @@ impl<'a,'tcx:'a> Mirror<Cx<'a,'tcx>> for &'tcx hir::Expr {
hir::ExprLoop(ref body, _) =>
ExprKind::Loop { condition: None,
body: block::to_expr_ref(cx, body) },
hir::ExprField(ref source, ident) =>
hir::ExprField(ref source, name) =>
ExprKind::Field { lhs: source.to_ref(),
name: Field::Named(ident.node.name) },
name: Field::Named(name.node) },
hir::ExprTupField(ref source, ident) =>
ExprKind::Field { lhs: source.to_ref(),
name: Field::Indexed(ident.node) },
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/tcx/to_ref.rs
Expand Up @@ -86,9 +86,8 @@ impl<'a,'tcx:'a> ToRef<Cx<'a,'tcx>> for &'tcx hir::Field {

fn to_ref(self) -> FieldExprRef<Cx<'a,'tcx>> {
FieldExprRef {
name: Field::Named(self.ident.node.name),
name: Field::Named(self.name.node),
expr: self.expr.to_ref()
}
}
}

8 changes: 4 additions & 4 deletions src/librustc_privacy/lib.rs
Expand Up @@ -866,12 +866,12 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {

fn visit_expr(&mut self, expr: &hir::Expr) {
match expr.node {
hir::ExprField(ref base, ident) => {
hir::ExprField(ref base, name) => {
if let ty::TyStruct(def, _) = self.tcx.expr_ty_adjusted(&**base).sty {
self.check_field(expr.span,
def,
def.struct_variant(),
NamedField(ident.node.name));
NamedField(name.node));
}
}
hir::ExprTupField(ref base, idx) => {
Expand All @@ -882,11 +882,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
UnnamedField(idx.node));
}
}
hir::ExprMethodCall(ident, _, _) => {
hir::ExprMethodCall(name, _, _) => {
let method_call = ty::MethodCall::expr(expr.id);
let method = self.tcx.tables.borrow().method_map[&method_call];
debug!("(privacy checking) checking impl method");
self.check_method(expr.span, method.def_id, ident.node.name);
self.check_method(expr.span, method.def_id, name.node);
}
hir::ExprStruct(..) => {
let adt = self.tcx.expr_ty(expr).ty_adt_def().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_resolve/lib.rs
Expand Up @@ -3817,19 +3817,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

fn record_candidate_traits_for_expr_if_necessary(&mut self, expr: &Expr) {
match expr.node {
ExprField(_, ident) => {
ExprField(_, name) => {
// FIXME(#6890): Even though you can't treat a method like a
// field, we need to add any trait methods we find that match
// the field name so that we can do some nice error reporting
// later on in typeck.
let traits = self.get_traits_containing_item(ident.node.name);
let traits = self.get_traits_containing_item(name.node);
self.trait_map.insert(expr.id, traits);
}
ExprMethodCall(ident, _, _) => {
ExprMethodCall(name, _, _) => {
debug!("(recording candidate traits for expr) recording \
traits for {}",
expr.id);
let traits = self.get_traits_containing_item(ident.node.name);
let traits = self.get_traits_containing_item(name.node);
self.trait_map.insert(expr.id, traits);
}
_ => {
Expand Down

0 comments on commit 64fb709

Please sign in to comment.