Use Names in hir::{Field, ExprMethodCall, ExprField}
This commit is contained in:
parent
a4af958786
commit
64fb709f99
@ -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,
|
||||
},
|
||||
@ -1040,8 +1040,8 @@ fn fromb(b: bool) -> ConstVal { Int(b as i64) }
|
||||
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);
|
||||
|
@ -227,8 +227,8 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
|
||||
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);
|
||||
|
@ -710,7 +710,7 @@ fn contains_field_named(field: ty::FieldDef,
|
||||
-> bool
|
||||
{
|
||||
fields.iter().any(
|
||||
|f| f.ident.node.name == field.name)
|
||||
|f| f.name.node == field.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,7 +474,7 @@ pub fn cat_expr_unadjusted(&self, expr: &hir::Expr) -> McResult<cmt<'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) => {
|
||||
|
@ -16,7 +16,7 @@
|
||||
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>;
|
||||
|
||||
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> {
|
||||
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,
|
||||
|
@ -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)
|
||||
}
|
||||
@ -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)))
|
||||
}
|
||||
@ -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),
|
||||
|
@ -52,10 +52,6 @@
|
||||
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,
|
||||
@ -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>>>),
|
||||
@ -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,
|
||||
@ -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).
|
||||
///
|
||||
@ -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`)
|
||||
@ -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`.
|
||||
@ -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>>),
|
||||
|
||||
@ -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)]
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
use syntax::ast::*;
|
||||
use syntax::ptr::P;
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::codemap::{respan, Spanned};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
|
||||
|
||||
@ -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 {
|
||||
@ -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())
|
||||
}
|
||||
@ -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)
|
||||
|
@ -13,7 +13,7 @@
|
||||
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;
|
||||
@ -1223,7 +1223,7 @@ fn print_expr_struct(&mut self,
|
||||
&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()
|
||||
@ -1265,13 +1265,13 @@ fn print_expr_call(&mut self,
|
||||
}
|
||||
|
||||
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,
|
||||
@ -1329,8 +1329,8 @@ pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
|
||||
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));
|
||||
@ -1435,10 +1435,10 @@ pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
|
||||
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));
|
||||
|
@ -288,9 +288,9 @@ fn make_mirror(self, cx: &mut Cx<'a,'tcx>) -> Expr<Cx<'a,'tcx>> {
|
||||
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) },
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -866,12 +866,12 @@ fn visit_item(&mut self, item: &hir::Item) {
|
||||
|
||||
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) => {
|
||||
@ -882,11 +882,11 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
|
||||
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();
|
||||
|
@ -3817,19 +3817,19 @@ fn resolve_expr(&mut self, expr: &Expr) {
|
||||
|
||||
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);
|
||||
}
|
||||
_ => {
|
||||
|
@ -1436,7 +1436,7 @@ fn is_discr_reassigned(bcx: Block, discr: &hir::Expr, body: &hir::Expr) -> bool
|
||||
Some(def::DefLocal(vid)) | Some(def::DefUpvar(vid, _, _)) => vid,
|
||||
_ => return false
|
||||
};
|
||||
(vid, Some(mc::NamedField(field.node.name)))
|
||||
(vid, Some(mc::NamedField(field.node)))
|
||||
},
|
||||
hir::ExprTupField(ref base, field) => {
|
||||
let vid = match bcx.tcx().def_map.borrow().get(&base.id).map(|d| d.full_def()) {
|
||||
|
@ -574,7 +574,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
let (bv, bt) = const_expr(cx, &**base, param_substs, fn_args);
|
||||
let brepr = adt::represent_type(cx, bt);
|
||||
let vinfo = VariantInfo::from_ty(cx.tcx(), bt, None);
|
||||
let ix = vinfo.field_index(field.node.name);
|
||||
let ix = vinfo.field_index(field.node);
|
||||
adt::const_get_field(cx, &*brepr, bv, vinfo.discr, ix)
|
||||
},
|
||||
hir::ExprTupField(ref base, idx) => {
|
||||
@ -742,7 +742,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
|
||||
let VariantInfo { discr, fields } = VariantInfo::of_node(cx.tcx(), ety, e.id);
|
||||
let cs = fields.iter().enumerate().map(|(ix, &Field(f_name, _))| {
|
||||
match (fs.iter().find(|f| f_name == f.ident.node.name), base_val) {
|
||||
match (fs.iter().find(|f| f_name == f.name.node), base_val) {
|
||||
(Some(ref f), _) => const_expr(cx, &*f.expr, param_substs, fn_args).0,
|
||||
(_, Some((bv, _))) => adt::const_get_field(cx, &*repr, bv, discr, ix),
|
||||
(_, None) => cx.sess().span_bug(e.span, "missing struct field"),
|
||||
|
@ -664,8 +664,8 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
hir::ExprPath(..) => {
|
||||
trans_def(bcx, expr, bcx.def(expr.id))
|
||||
}
|
||||
hir::ExprField(ref base, ident) => {
|
||||
trans_rec_field(bcx, &**base, ident.node.name)
|
||||
hir::ExprField(ref base, name) => {
|
||||
trans_rec_field(bcx, &**base, name.node)
|
||||
}
|
||||
hir::ExprTupField(ref base, idx) => {
|
||||
trans_rec_tup_field(bcx, &**base, idx.node)
|
||||
@ -1114,7 +1114,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
// trans. Shudder.
|
||||
fn make_field(field_name: &str, expr: P<hir::Expr>) -> hir::Field {
|
||||
hir::Field {
|
||||
ident: codemap::dummy_spanned(token::str_to_ident(field_name)),
|
||||
name: codemap::dummy_spanned(token::str_to_ident(field_name).name),
|
||||
expr: expr,
|
||||
span: codemap::DUMMY_SP,
|
||||
}
|
||||
@ -1408,7 +1408,7 @@ fn trans_struct<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
let mut need_base = vec![true; vinfo.fields.len()];
|
||||
|
||||
let numbered_fields = fields.iter().map(|field| {
|
||||
let pos = vinfo.field_index(field.ident.node.name);
|
||||
let pos = vinfo.field_index(field.name.node);
|
||||
need_base[pos] = false;
|
||||
(pos, &*field.expr)
|
||||
}).collect::<Vec<_>>();
|
||||
|
@ -119,7 +119,7 @@
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::codemap::{self, Span};
|
||||
use syntax::codemap::{self, Span, Spanned};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
use syntax::parse::token::{self, InternedString};
|
||||
use syntax::ptr::P;
|
||||
@ -2820,7 +2820,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
// Checks a method call.
|
||||
fn check_method_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
method_name: hir::SpannedIdent,
|
||||
method_name: Spanned<ast::Name>,
|
||||
args: &'tcx [P<hir::Expr>],
|
||||
tps: &[P<hir::Ty>],
|
||||
expected: Expectation<'tcx>,
|
||||
@ -2836,7 +2836,7 @@ fn check_method_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
let tps = tps.iter().map(|ast_ty| fcx.to_ty(&**ast_ty)).collect::<Vec<_>>();
|
||||
let fn_ty = match method::lookup(fcx,
|
||||
method_name.span,
|
||||
method_name.node.name,
|
||||
method_name.node,
|
||||
expr_t,
|
||||
tps,
|
||||
expr,
|
||||
@ -2849,7 +2849,7 @@ fn check_method_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
}
|
||||
Err(error) => {
|
||||
method::report_error(fcx, method_name.span, expr_t,
|
||||
method_name.node.name, Some(rcvr), error);
|
||||
method_name.node, Some(rcvr), error);
|
||||
fcx.write_error(expr.id);
|
||||
fcx.tcx().types.err
|
||||
}
|
||||
@ -2916,7 +2916,7 @@ fn check_field<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
lvalue_pref: LvaluePreference,
|
||||
base: &'tcx hir::Expr,
|
||||
field: &hir::SpannedIdent) {
|
||||
field: &Spanned<ast::Name>) {
|
||||
let tcx = fcx.ccx.tcx;
|
||||
check_expr_with_lvalue_pref(fcx, base, lvalue_pref);
|
||||
let expr_t = structurally_resolved_type(fcx, expr.span,
|
||||
@ -2933,7 +2933,7 @@ fn check_field<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
ty::TyStruct(base_def, substs) => {
|
||||
debug!("struct named {:?}", base_t);
|
||||
base_def.struct_variant()
|
||||
.find_field_named(field.node.name)
|
||||
.find_field_named(field.node)
|
||||
.map(|f| fcx.field_ty(expr.span, f, substs))
|
||||
}
|
||||
_ => None
|
||||
@ -2948,7 +2948,7 @@ fn check_field<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
None => {}
|
||||
}
|
||||
|
||||
if method::exists(fcx, field.span, field.node.name, expr_t, expr.id) {
|
||||
if method::exists(fcx, field.span, field.node, expr_t, expr.id) {
|
||||
fcx.type_error_message(
|
||||
field.span,
|
||||
|actual| {
|
||||
@ -2981,10 +2981,10 @@ fn check_field<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
|
||||
// displays hints about the closest matches in field names
|
||||
fn suggest_field_names<'tcx>(variant: ty::VariantDef<'tcx>,
|
||||
field: &hir::SpannedIdent,
|
||||
field: &Spanned<ast::Name>,
|
||||
tcx: &ty::ctxt<'tcx>,
|
||||
skip : Vec<InternedString>) {
|
||||
let name = field.node.name.as_str();
|
||||
let name = field.node.as_str();
|
||||
// only find fits with at least one matching letter
|
||||
let mut best_dist = name.len();
|
||||
let mut best = None;
|
||||
@ -3082,22 +3082,21 @@ fn report_unknown_field<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
field: &hir::Field,
|
||||
skip_fields: &[hir::Field]) {
|
||||
fcx.type_error_message(
|
||||
field.ident.span,
|
||||
field.name.span,
|
||||
|actual| if let ty::TyEnum(..) = ty.sty {
|
||||
format!("struct variant `{}::{}` has no field named `{}`",
|
||||
actual, variant.name.as_str(), field.ident.node)
|
||||
actual, variant.name.as_str(), field.name.node)
|
||||
} else {
|
||||
format!("structure `{}` has no field named `{}`",
|
||||
actual, field.ident.node)
|
||||
actual, field.name.node)
|
||||
},
|
||||
ty,
|
||||
None);
|
||||
// prevent all specified fields from being suggested
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.ident.node.name.as_str());
|
||||
suggest_field_names(variant, &field.ident, fcx.tcx(), skip_fields.collect());
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.name.node.as_str());
|
||||
suggest_field_names(variant, &field.name, fcx.tcx(), skip_fields.collect());
|
||||
}
|
||||
|
||||
|
||||
fn check_expr_struct_fields<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
adt_ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
@ -3121,15 +3120,15 @@ fn check_expr_struct_fields<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
for field in ast_fields {
|
||||
let expected_field_type;
|
||||
|
||||
if let Some(v_field) = remaining_fields.remove(&field.ident.node.name) {
|
||||
if let Some(v_field) = remaining_fields.remove(&field.name.node) {
|
||||
expected_field_type = fcx.field_ty(field.span, v_field, substs);
|
||||
} else {
|
||||
error_happened = true;
|
||||
expected_field_type = tcx.types.err;
|
||||
if let Some(_) = variant.find_field_named(field.ident.node.name) {
|
||||
span_err!(fcx.tcx().sess, field.ident.span, E0062,
|
||||
if let Some(_) = variant.find_field_named(field.name.node) {
|
||||
span_err!(fcx.tcx().sess, field.name.span, E0062,
|
||||
"field `{}` specified more than once",
|
||||
field.ident.node);
|
||||
field.name.node);
|
||||
} else {
|
||||
report_unknown_field(fcx, adt_ty, variant, field, ast_fields);
|
||||
}
|
||||
@ -3506,8 +3505,8 @@ fn check_expr_struct<'a, 'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
||||
let ret_ty = fcx.expr_ty(expr);
|
||||
fcx.register_wf_obligation(ret_ty, expr.span, traits::MiscObligation);
|
||||
}
|
||||
hir::ExprMethodCall(ident, ref tps, ref args) => {
|
||||
check_method_call(fcx, expr, ident, &args[..], &tps[..], expected, lvalue_pref);
|
||||
hir::ExprMethodCall(name, ref tps, ref args) => {
|
||||
check_method_call(fcx, expr, name, &args[..], &tps[..], expected, lvalue_pref);
|
||||
let arg_tys = args.iter().map(|a| fcx.expr_ty(&**a));
|
||||
let args_err = arg_tys.fold(false, |rest_err, a| rest_err || a.references_error());
|
||||
if args_err {
|
||||
|
Loading…
Reference in New Issue
Block a user