Use Ident
s for fields in HIR
This commit is contained in:
parent
444a9c3f1a
commit
189c0a1297
@ -42,7 +42,7 @@
|
||||
//! example generator inference, and possibly also HIR borrowck.
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
|
||||
use syntax::ast::{NodeId, CRATE_NODE_ID, Ident, Name, Attribute};
|
||||
use syntax_pos::Span;
|
||||
use hir::*;
|
||||
use hir::def::Def;
|
||||
@ -248,6 +248,9 @@ pub trait Visitor<'v> : Sized {
|
||||
fn visit_name(&mut self, _span: Span, _name: Name) {
|
||||
// Nothing to do.
|
||||
}
|
||||
fn visit_ident(&mut self, ident: Ident) {
|
||||
walk_ident(self, ident)
|
||||
}
|
||||
fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: NodeId) {
|
||||
walk_mod(self, m, n)
|
||||
}
|
||||
@ -413,6 +416,10 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
|
||||
walk_list!(visitor, visit_ty, &local.ty);
|
||||
}
|
||||
|
||||
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
|
||||
visitor.visit_name(ident.span, ident.name);
|
||||
}
|
||||
|
||||
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
|
||||
visitor.visit_name(label.span, label.name);
|
||||
}
|
||||
@ -662,7 +669,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
||||
visitor.visit_qpath(qpath, pattern.id, pattern.span);
|
||||
for field in fields {
|
||||
visitor.visit_id(field.node.id);
|
||||
visitor.visit_name(field.span, field.node.name);
|
||||
visitor.visit_ident(field.node.ident);
|
||||
visitor.visit_pat(&field.node.pat)
|
||||
}
|
||||
}
|
||||
@ -915,7 +922,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &
|
||||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) {
|
||||
visitor.visit_id(struct_field.id);
|
||||
visitor.visit_vis(&struct_field.vis);
|
||||
visitor.visit_name(struct_field.span, struct_field.name);
|
||||
visitor.visit_ident(struct_field.ident);
|
||||
visitor.visit_ty(&struct_field.ty);
|
||||
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
||||
}
|
||||
@ -970,7 +977,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
||||
visitor.visit_qpath(qpath, expression.id, expression.span);
|
||||
for field in fields {
|
||||
visitor.visit_id(field.id);
|
||||
visitor.visit_name(field.name.span, field.name.node);
|
||||
visitor.visit_ident(field.ident);
|
||||
visitor.visit_expr(&field.expr)
|
||||
}
|
||||
walk_list!(visitor, visit_expr, optional_base);
|
||||
@ -1035,9 +1042,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
||||
visitor.visit_expr(right_expression);
|
||||
visitor.visit_expr(left_expression)
|
||||
}
|
||||
ExprField(ref subexpression, ref name) => {
|
||||
ExprField(ref subexpression, ident) => {
|
||||
visitor.visit_expr(subexpression);
|
||||
visitor.visit_name(name.span, name.node);
|
||||
visitor.visit_ident(ident);
|
||||
}
|
||||
ExprIndex(ref main_expression, ref index_expression) => {
|
||||
visitor.visit_expr(main_expression);
|
||||
|
@ -2093,11 +2093,11 @@ impl<'a> LoweringContext<'a> {
|
||||
hir::StructField {
|
||||
span: f.span,
|
||||
id: self.lower_node_id(f.id).node_id,
|
||||
name: self.lower_ident(match f.ident {
|
||||
ident: match f.ident {
|
||||
Some(ident) => ident,
|
||||
// FIXME(jseyfried) positional field hygiene
|
||||
None => Ident::new(Symbol::intern(&index.to_string()), f.span),
|
||||
}),
|
||||
},
|
||||
vis: self.lower_visibility(&f.vis, None),
|
||||
ty: self.lower_ty(&f.ty, ImplTraitContext::Disallowed),
|
||||
attrs: self.lower_attrs(&f.attrs),
|
||||
@ -2107,7 +2107,7 @@ impl<'a> LoweringContext<'a> {
|
||||
fn lower_field(&mut self, f: &Field) -> hir::Field {
|
||||
hir::Field {
|
||||
id: self.next_id().node_id,
|
||||
name: respan(f.ident.span, self.lower_ident(f.ident)),
|
||||
ident: f.ident,
|
||||
expr: P(self.lower_expr(&f.expr)),
|
||||
span: f.span,
|
||||
is_shorthand: f.is_shorthand,
|
||||
@ -2877,7 +2877,7 @@ impl<'a> LoweringContext<'a> {
|
||||
span: f.span,
|
||||
node: hir::FieldPat {
|
||||
id: self.next_id().node_id,
|
||||
name: self.lower_ident(f.node.ident),
|
||||
ident: f.node.ident,
|
||||
pat: self.lower_pat(&f.node.pat),
|
||||
is_shorthand: f.node.is_shorthand,
|
||||
},
|
||||
@ -3119,10 +3119,7 @@ impl<'a> LoweringContext<'a> {
|
||||
P(self.lower_expr(el)),
|
||||
P(self.lower_expr(er)),
|
||||
),
|
||||
ExprKind::Field(ref el, ident) => hir::ExprField(
|
||||
P(self.lower_expr(el)),
|
||||
respan(ident.span, self.lower_ident(ident)),
|
||||
),
|
||||
ExprKind::Field(ref el, ident) => hir::ExprField(P(self.lower_expr(el)), ident),
|
||||
ExprKind::Index(ref el, ref er) => {
|
||||
hir::ExprIndex(P(self.lower_expr(el)), P(self.lower_expr(er)))
|
||||
}
|
||||
@ -3162,7 +3159,8 @@ impl<'a> LoweringContext<'a> {
|
||||
let expr = P(self.lower_expr(&e));
|
||||
let unstable_span =
|
||||
self.allow_internal_unstable(CompilerDesugaringKind::DotFill, e.span);
|
||||
self.field(Symbol::intern(s), expr, unstable_span)
|
||||
let ident = Ident::new(Symbol::intern(s), unstable_span);
|
||||
self.field(ident, expr, unstable_span)
|
||||
})
|
||||
.collect::<P<[hir::Field]>>();
|
||||
|
||||
@ -3777,10 +3775,10 @@ impl<'a> LoweringContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn field(&mut self, name: Name, expr: P<hir::Expr>, span: Span) -> hir::Field {
|
||||
fn field(&mut self, ident: Ident, expr: P<hir::Expr>, span: Span) -> hir::Field {
|
||||
hir::Field {
|
||||
id: self.next_id().node_id,
|
||||
name: Spanned { node: name, span },
|
||||
ident,
|
||||
span,
|
||||
expr,
|
||||
is_shorthand: false,
|
||||
|
@ -909,7 +909,7 @@ impl<'hir> Map<'hir> {
|
||||
NodeImplItem(ii) => ii.name,
|
||||
NodeTraitItem(ti) => ti.name,
|
||||
NodeVariant(v) => v.node.name,
|
||||
NodeField(f) => f.name,
|
||||
NodeField(f) => f.ident.name,
|
||||
NodeLifetime(lt) => lt.name.name(),
|
||||
NodeTyParam(tp) => tp.name,
|
||||
NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
|
||||
@ -1105,7 +1105,7 @@ impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() }
|
||||
impl Named for Item { fn name(&self) -> Name { self.name } }
|
||||
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
|
||||
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
|
||||
impl Named for StructField { fn name(&self) -> Name { self.name } }
|
||||
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
|
||||
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
|
||||
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
|
||||
|
||||
@ -1291,7 +1291,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
||||
}
|
||||
Some(NodeField(ref field)) => {
|
||||
format!("field {} in {}{}",
|
||||
field.name,
|
||||
field.ident,
|
||||
path_str(), id_str)
|
||||
}
|
||||
Some(NodeAnonConst(_)) => {
|
||||
|
@ -35,7 +35,7 @@ use mir::mono::Linkage;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use syntax::codemap::{self, Spanned};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
|
||||
use syntax::ast::{self, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
|
||||
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
|
||||
use syntax::attr::InlineAttr;
|
||||
use syntax::ext::hygiene::SyntaxContext;
|
||||
@ -866,7 +866,7 @@ impl Pat {
|
||||
pub struct FieldPat {
|
||||
pub id: NodeId,
|
||||
/// The identifier for the field
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
/// The pattern the field is destructured to
|
||||
pub pat: P<Pat>,
|
||||
pub is_shorthand: bool,
|
||||
@ -1211,7 +1211,7 @@ pub struct Arm {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct Field {
|
||||
pub id: NodeId,
|
||||
pub name: Spanned<Name>,
|
||||
pub ident: Ident,
|
||||
pub expr: P<Expr>,
|
||||
pub span: Span,
|
||||
pub is_shorthand: bool,
|
||||
@ -1414,7 +1414,7 @@ pub enum Expr_ {
|
||||
/// For example, `a += 1`.
|
||||
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
|
||||
/// Access of a named (`obj.foo`) or unnamed (`obj.0`) struct or tuple field
|
||||
ExprField(P<Expr>, Spanned<Name>),
|
||||
ExprField(P<Expr>, Ident),
|
||||
/// An indexing operation (`foo[2]`)
|
||||
ExprIndex(P<Expr>, P<Expr>),
|
||||
|
||||
@ -1973,7 +1973,7 @@ impl Visibility {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct StructField {
|
||||
pub span: Span,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub vis: Visibility,
|
||||
pub id: NodeId,
|
||||
pub ty: P<Ty>,
|
||||
@ -1983,7 +1983,7 @@ pub struct StructField {
|
||||
impl StructField {
|
||||
// Still necessary in couple of places
|
||||
pub fn is_positional(&self) -> bool {
|
||||
let first = self.name.as_str().as_bytes()[0];
|
||||
let first = self.ident.name.as_str().as_bytes()[0];
|
||||
first >= b'0' && first <= b'9'
|
||||
}
|
||||
}
|
||||
|
@ -857,7 +857,7 @@ impl<'a> State<'a> {
|
||||
self.maybe_print_comment(field.span.lo())?;
|
||||
self.print_outer_attributes(&field.attrs)?;
|
||||
self.print_visibility(&field.vis)?;
|
||||
self.print_name(field.name)?;
|
||||
self.print_ident(field.ident)?;
|
||||
self.word_nbsp(":")?;
|
||||
self.print_type(&field.ty)?;
|
||||
self.s.word(",")?;
|
||||
@ -1166,7 +1166,7 @@ impl<'a> State<'a> {
|
||||
|s, field| {
|
||||
s.ibox(indent_unit)?;
|
||||
if !field.is_shorthand {
|
||||
s.print_name(field.name.node)?;
|
||||
s.print_ident(field.ident)?;
|
||||
s.word_space(":")?;
|
||||
}
|
||||
s.print_expr(&field.expr)?;
|
||||
@ -1406,10 +1406,10 @@ impl<'a> State<'a> {
|
||||
self.word_space("=")?;
|
||||
self.print_expr_maybe_paren(&rhs, prec)?;
|
||||
}
|
||||
hir::ExprField(ref expr, name) => {
|
||||
hir::ExprField(ref expr, ident) => {
|
||||
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX)?;
|
||||
self.s.word(".")?;
|
||||
self.print_name(name.node)?;
|
||||
self.print_ident(ident)?;
|
||||
}
|
||||
hir::ExprIndex(ref expr, ref index) => {
|
||||
self.print_expr_maybe_paren(&expr, parser::PREC_POSTFIX)?;
|
||||
@ -1561,13 +1561,17 @@ impl<'a> State<'a> {
|
||||
self.s.word(&i.to_string())
|
||||
}
|
||||
|
||||
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
|
||||
if name.to_ident().is_raw_guess() {
|
||||
self.s.word(&format!("r#{}", name))?;
|
||||
pub fn print_ident(&mut self, ident: ast::Ident) -> io::Result<()> {
|
||||
if ident.is_raw_guess() {
|
||||
self.s.word(&format!("r#{}", ident.name))?;
|
||||
} else {
|
||||
self.s.word(&name.as_str())?;
|
||||
self.s.word(&ident.name.as_str())?;
|
||||
}
|
||||
self.ann.post(self, NodeName(&name))
|
||||
self.ann.post(self, NodeName(&ident.name))
|
||||
}
|
||||
|
||||
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
|
||||
self.print_ident(name.to_ident())
|
||||
}
|
||||
|
||||
pub fn print_for_decl(&mut self, loc: &hir::Local, coll: &hir::Expr) -> io::Result<()> {
|
||||
@ -1773,7 +1777,7 @@ impl<'a> State<'a> {
|
||||
|s, f| {
|
||||
s.cbox(indent_unit)?;
|
||||
if !f.node.is_shorthand {
|
||||
s.print_name(f.node.name)?;
|
||||
s.print_ident(f.node.ident)?;
|
||||
s.word_nbsp(":")?;
|
||||
}
|
||||
s.print_pat(&f.node.pat)?;
|
||||
|
@ -427,12 +427,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::FieldPat {
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::FieldPat {
|
||||
id: _,
|
||||
name,
|
||||
ident,
|
||||
ref pat,
|
||||
is_shorthand,
|
||||
} = *self;
|
||||
|
||||
name.hash_stable(hcx, hasher);
|
||||
ident.hash_stable(hcx, hasher);
|
||||
pat.hash_stable(hcx, hasher);
|
||||
is_shorthand.hash_stable(hcx, hasher);
|
||||
}
|
||||
@ -525,13 +525,13 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Field {
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::Field {
|
||||
id: _,
|
||||
name,
|
||||
ident,
|
||||
ref expr,
|
||||
span,
|
||||
is_shorthand,
|
||||
} = *self;
|
||||
|
||||
name.hash_stable(hcx, hasher);
|
||||
ident.hash_stable(hcx, hasher);
|
||||
expr.hash_stable(hcx, hasher);
|
||||
span.hash_stable(hcx, hasher);
|
||||
is_shorthand.hash_stable(hcx, hasher);
|
||||
@ -598,7 +598,7 @@ impl_stable_hash_for!(enum hir::Expr_ {
|
||||
ExprBlock(blk, label),
|
||||
ExprAssign(lhs, rhs),
|
||||
ExprAssignOp(op, lhs, rhs),
|
||||
ExprField(owner, field_name),
|
||||
ExprField(owner, ident),
|
||||
ExprIndex(lhs, rhs),
|
||||
ExprPath(path),
|
||||
ExprAddrOf(mutability, sub),
|
||||
@ -835,7 +835,7 @@ impl_stable_hash_for!(enum hir::UseKind {
|
||||
|
||||
impl_stable_hash_for!(struct hir::StructField {
|
||||
span,
|
||||
name,
|
||||
ident,
|
||||
vis,
|
||||
id,
|
||||
ty,
|
||||
|
@ -357,11 +357,17 @@ impl_stable_hash_for!(enum ty::VariantDiscr {
|
||||
Relative(distance)
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ty::FieldDef {
|
||||
did,
|
||||
name,
|
||||
vis
|
||||
});
|
||||
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::FieldDef {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::FieldDef { did, ident, vis } = *self;
|
||||
|
||||
did.hash_stable(hcx, hasher);
|
||||
ident.name.hash_stable(hcx, hasher);
|
||||
vis.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
|
||||
for ::middle::const_val::ConstVal<'gcx> {
|
||||
|
@ -588,7 +588,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
||||
|
||||
fn visit_struct_field(&mut self, field: &'tcx hir::StructField) {
|
||||
if self.should_warn_about_field(&field) {
|
||||
self.warn_dead_code(field.id, field.span, field.name, "field", "used");
|
||||
self.warn_dead_code(field.id, field.span, field.ident.name, "field", "used");
|
||||
}
|
||||
intravisit::walk_struct_field(self, field);
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||
&*with_expr,
|
||||
with_cmt.clone(),
|
||||
f_index,
|
||||
with_field.name,
|
||||
with_field.ident,
|
||||
with_field.ty(self.tcx(), substs)
|
||||
);
|
||||
self.delegate_consume(with_expr.id, with_expr.span, &cmt_field);
|
||||
|
@ -647,14 +647,14 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
hir::ExprField(ref base, f_name) => {
|
||||
hir::ExprField(ref base, f_ident) => {
|
||||
let base_cmt = Rc::new(self.cat_expr(&base)?);
|
||||
debug!("cat_expr(cat_field): id={} expr={:?} base={:?}",
|
||||
expr.id,
|
||||
expr,
|
||||
base_cmt);
|
||||
let f_index = self.tcx.field_index(expr.id, self.tables);
|
||||
Ok(self.cat_field(expr, base_cmt, f_index, f_name.node, expr_ty))
|
||||
Ok(self.cat_field(expr, base_cmt, f_index, f_ident, expr_ty))
|
||||
}
|
||||
|
||||
hir::ExprIndex(ref base, _) => {
|
||||
@ -983,14 +983,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
node: &N,
|
||||
base_cmt: cmt<'tcx>,
|
||||
f_index: usize,
|
||||
f_name: Name,
|
||||
f_ident: ast::Ident,
|
||||
f_ty: Ty<'tcx>)
|
||||
-> cmt_<'tcx> {
|
||||
let ret = cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
mutbl: base_cmt.mutbl.inherit(),
|
||||
cat: Categorization::Interior(base_cmt, InteriorField(FieldIndex(f_index, f_name))),
|
||||
cat: Categorization::Interior(base_cmt,
|
||||
InteriorField(FieldIndex(f_index, f_ident.name))),
|
||||
ty: f_ty,
|
||||
note: NoteNone
|
||||
};
|
||||
@ -1301,8 +1302,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
for fp in field_pats {
|
||||
let field_ty = self.pat_ty(&fp.node.pat)?; // see (*2)
|
||||
let f_index = self.tcx.field_index(fp.node.id, self.tables);
|
||||
let cmt_field =
|
||||
Rc::new(self.cat_field(pat, cmt.clone(), f_index, fp.node.name, field_ty));
|
||||
let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index,
|
||||
fp.node.ident, field_ty));
|
||||
self.cat_pattern_(cmt_field, &fp.node.pat, op)?;
|
||||
}
|
||||
}
|
||||
|
@ -1774,7 +1774,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
||||
CtorKind::Fictive => {
|
||||
let mut struct_fmt = fmt.debug_struct("");
|
||||
for (field, place) in variant_def.fields.iter().zip(places) {
|
||||
struct_fmt.field(&field.name.as_str(), place);
|
||||
struct_fmt.field(&field.ident.name.as_str(), place);
|
||||
}
|
||||
struct_fmt.finish()
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
}) => {
|
||||
(self.tcx.sess.codemap().def_span(span),
|
||||
fields.iter().map(|field| {
|
||||
ArgKind::Arg(format!("{}", field.name), "_".to_string())
|
||||
ArgKind::Arg(format!("{}", field.ident), "_".to_string())
|
||||
}).collect::<Vec<_>>())
|
||||
}
|
||||
hir::map::NodeStructCtor(ref variant_data) => {
|
||||
|
@ -1227,7 +1227,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
||||
if !adt_def.variants.is_empty() {
|
||||
let variant_def = &adt_def.variants[index];
|
||||
let fields: Vec<_> =
|
||||
variant_def.fields.iter().map(|f| f.name).collect();
|
||||
variant_def.fields.iter().map(|f| f.ident.name).collect();
|
||||
record(adt_kind.into(),
|
||||
adt_packed,
|
||||
None,
|
||||
@ -1248,7 +1248,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
||||
let variant_infos: Vec<_> =
|
||||
adt_def.variants.iter().enumerate().map(|(i, variant_def)| {
|
||||
let fields: Vec<_> =
|
||||
variant_def.fields.iter().map(|f| f.name).collect();
|
||||
variant_def.fields.iter().map(|f| f.ident.name).collect();
|
||||
build_variant_info(Some(variant_def.name),
|
||||
&fields,
|
||||
layout.for_variant(self, i))
|
||||
|
@ -1619,7 +1619,7 @@ pub enum VariantDiscr {
|
||||
#[derive(Debug)]
|
||||
pub struct FieldDef {
|
||||
pub did: DefId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub vis: Visibility,
|
||||
}
|
||||
|
||||
@ -2454,7 +2454,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<usize> {
|
||||
variant.fields.iter().position(|field| {
|
||||
self.adjust_ident(ident.modern(), variant.did, DUMMY_NODE_ID).0 == field.name.to_ident()
|
||||
self.adjust_ident(ident, variant.did, DUMMY_NODE_ID).0 == field.ident.modern()
|
||||
})
|
||||
}
|
||||
|
||||
@ -2635,11 +2635,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
// supposed definition name (`def_name`). The method also needs `DefId` of the supposed
|
||||
// definition's parent/scope to perform comparison.
|
||||
pub fn hygienic_eq(self, use_name: Name, def_name: Name, def_parent_def_id: DefId) -> bool {
|
||||
self.adjust(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.to_ident()
|
||||
}
|
||||
|
||||
pub fn adjust(self, name: Name, scope: DefId, block: NodeId) -> (Ident, DefId) {
|
||||
self.adjust_ident(name.to_ident(), scope, block)
|
||||
let (use_ident, def_ident) = (use_name.to_ident(), def_name.to_ident());
|
||||
self.adjust_ident(use_ident, def_parent_def_id, DUMMY_NODE_ID).0 == def_ident
|
||||
}
|
||||
|
||||
pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) {
|
||||
@ -2647,6 +2644,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
LOCAL_CRATE => self.hir.definitions().expansion(scope.index),
|
||||
_ => Mark::root(),
|
||||
};
|
||||
ident = ident.modern();
|
||||
let scope = match ident.span.adjust(expansion) {
|
||||
Some(macro_def) => self.hir.definitions().macro_def_scope(macro_def),
|
||||
None if block == DUMMY_NODE_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId
|
||||
|
@ -108,8 +108,9 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
|
||||
RestrictionResult::Safe => RestrictionResult::Safe,
|
||||
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
|
||||
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
||||
let field =
|
||||
InteriorKind::InteriorField(mc::FieldIndex(i, field.name));
|
||||
let field = InteriorKind::InteriorField(
|
||||
mc::FieldIndex(i, field.ident.name)
|
||||
);
|
||||
let field_ty = if field == interior {
|
||||
cmt.ty
|
||||
} else {
|
||||
|
@ -343,7 +343,8 @@ impl<'a, 'tcx> MoveData<'tcx> {
|
||||
= (&base_lp.ty.sty, lp_elem) {
|
||||
if adt_def.is_union() {
|
||||
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
||||
let field = InteriorKind::InteriorField(mc::FieldIndex(i, field.name));
|
||||
let field =
|
||||
InteriorKind::InteriorField(mc::FieldIndex(i, field.ident.name));
|
||||
if field != interior {
|
||||
let sibling_lp_kind =
|
||||
LpExtend(base_lp.clone(), mutbl, LpInterior(opt_variant_id, field));
|
||||
@ -395,7 +396,8 @@ impl<'a, 'tcx> MoveData<'tcx> {
|
||||
if let ty::TyAdt(adt_def, _) = base_lp.ty.sty {
|
||||
if adt_def.is_union() {
|
||||
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
||||
let field = InteriorKind::InteriorField(mc::FieldIndex(i, field.name));
|
||||
let field =
|
||||
InteriorKind::InteriorField(mc::FieldIndex(i, field.ident.name));
|
||||
let field_ty = if field == interior {
|
||||
lp.ty
|
||||
} else {
|
||||
|
@ -951,7 +951,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
|
||||
let name = if self.variant.ctor_kind == CtorKind::Fn {
|
||||
format!("__{}", i)
|
||||
} else {
|
||||
f.name.to_string()
|
||||
f.ident.to_string()
|
||||
};
|
||||
let field = layout.field(cx, i);
|
||||
let (size, align) = field.size_and_align();
|
||||
@ -1072,7 +1072,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
|
||||
let field = self.layout.field(cx, i);
|
||||
let (size, align) = field.size_and_align();
|
||||
MemberDescription {
|
||||
name: f.name.to_string(),
|
||||
name: f.ident.to_string(),
|
||||
type_metadata: type_metadata(cx, field.ty, self.span),
|
||||
offset: Size::ZERO,
|
||||
size,
|
||||
@ -1338,7 +1338,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||
let name = if variant.ctor_kind == CtorKind::Fn {
|
||||
format!("__{}", i)
|
||||
} else {
|
||||
variant.fields[i].name.to_string()
|
||||
variant.fields[i].ident.to_string()
|
||||
};
|
||||
(name, layout.field(cx, i).ty)
|
||||
})).collect();
|
||||
|
@ -324,7 +324,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
|
||||
_: &hir::Generics,
|
||||
_: ast::NodeId) {
|
||||
for sf in s.fields() {
|
||||
self.check_snake_case(cx, "structure field", &sf.name.as_str(), Some(sf.span));
|
||||
self.check_snake_case(cx, "structure field", &sf.ident.name.as_str(), Some(sf.span));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
let f = self.entry(index);
|
||||
ty::FieldDef {
|
||||
did: self.local_def_id(index),
|
||||
name: self.item_name(index).as_symbol(),
|
||||
ident: Ident::from_interned_str(self.item_name(index)),
|
||||
vis: f.visibility.decode(self)
|
||||
}
|
||||
}).collect(),
|
||||
|
@ -746,7 +746,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
||||
Place::Projection(ref proj) => match proj.elem {
|
||||
ProjectionElem::Deref => self.describe_field(&proj.base, field),
|
||||
ProjectionElem::Downcast(def, variant_index) => {
|
||||
format!("{}", def.variants[variant_index].fields[field.index()].name)
|
||||
format!("{}", def.variants[variant_index].fields[field.index()].ident)
|
||||
}
|
||||
ProjectionElem::Field(_, field_type) => {
|
||||
self.describe_field_from_ty(&field_type, field)
|
||||
@ -770,7 +770,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
||||
ty::TyAdt(def, _) => if def.is_enum() {
|
||||
format!("{}", field.index())
|
||||
} else {
|
||||
format!("{}", def.non_enum_variant().fields[field.index()].name)
|
||||
format!("{}", def.non_enum_variant().fields[field.index()].ident)
|
||||
},
|
||||
ty::TyTuple(_) => format!("{}", field.index()),
|
||||
ty::TyRef(_, ty, _) | ty::TyRawPtr(ty::TypeAndMut { ty, .. }) => {
|
||||
|
@ -183,7 +183,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> {
|
||||
if let PatternKind::Wild = *p.pattern.kind {
|
||||
continue;
|
||||
}
|
||||
let name = variant.fields[p.field.index()].name;
|
||||
let name = variant.fields[p.field.index()].ident;
|
||||
write!(f, "{}{}: {}", start_or_continue(), name, p.pattern)?;
|
||||
printed += 1;
|
||||
}
|
||||
|
@ -504,12 +504,12 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
|
||||
span: Span, // Span of the field pattern, e.g. `x: 0`
|
||||
def: &'tcx ty::AdtDef, // Definition of the struct or enum
|
||||
field: &'tcx ty::FieldDef) { // Definition of the field
|
||||
let ident = Ident::new(keywords::Invalid.name(), use_ctxt.modern());
|
||||
let ident = Ident::new(keywords::Invalid.name(), use_ctxt);
|
||||
let def_id = self.tcx.adjust_ident(ident, def.did, self.current_item).1;
|
||||
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
|
||||
struct_span_err!(self.tcx.sess, span, E0451, "field `{}` of {} `{}` is private",
|
||||
field.name, def.variant_descr(), self.tcx.item_path_str(def.did))
|
||||
.span_label(span, format!("field `{}` is private", field.name))
|
||||
field.ident, def.variant_descr(), self.tcx.item_path_str(def.did))
|
||||
.span_label(span, format!("field `{}` is private", field.ident))
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
@ -580,14 +580,14 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
|
||||
self.tcx.field_index(f.id, self.tables) == vf_index
|
||||
});
|
||||
let (use_ctxt, span) = match field {
|
||||
Some(field) => (field.name.node.to_ident().span, field.span),
|
||||
Some(field) => (field.ident.span, field.span),
|
||||
None => (base.span, base.span),
|
||||
};
|
||||
self.check_field(use_ctxt, span, adt, variant_field);
|
||||
}
|
||||
} else {
|
||||
for field in fields {
|
||||
let use_ctxt = field.name.node.to_ident().span;
|
||||
let use_ctxt = field.ident.span;
|
||||
let index = self.tcx.field_index(field.id, self.tables);
|
||||
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
|
||||
}
|
||||
@ -606,7 +606,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
|
||||
let adt = self.tables.pat_ty(pat).ty_adt_def().unwrap();
|
||||
let variant = adt.variant_of_def(def);
|
||||
for field in fields {
|
||||
let use_ctxt = field.node.name.to_ident().span;
|
||||
let use_ctxt = field.node.ident.span;
|
||||
let index = self.tcx.field_index(field.node.id, self.tables);
|
||||
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
|
||||
}
|
||||
|
@ -557,7 +557,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
binding.item_name, binding.span)
|
||||
}?;
|
||||
|
||||
let (assoc_ident, def_scope) = tcx.adjust(binding.item_name, candidate.def_id(), ref_id);
|
||||
let (assoc_ident, def_scope) =
|
||||
tcx.adjust_ident(binding.item_name.to_ident(), candidate.def_id(), ref_id);
|
||||
let assoc_ty = tcx.associated_items(candidate.def_id()).find(|i| {
|
||||
i.kind == ty::AssociatedKind::Type && i.name.to_ident() == assoc_ident
|
||||
}).expect("missing associated type");
|
||||
@ -907,7 +908,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
};
|
||||
|
||||
let trait_did = bound.def_id();
|
||||
let (assoc_ident, def_scope) = tcx.adjust(assoc_name, trait_did, ref_id);
|
||||
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name.to_ident(), trait_did, ref_id);
|
||||
let item = tcx.associated_items(trait_did).find(|i| {
|
||||
Namespace::from(i.kind) == Namespace::Type &&
|
||||
i.name.to_ident() == assoc_ident
|
||||
|
@ -859,7 +859,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||
let field_map = variant.fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, field)| (field.name.to_ident(), (i, field)))
|
||||
.map(|(i, field)| (field.ident.modern(), (i, field)))
|
||||
.collect::<FxHashMap<_, _>>();
|
||||
|
||||
// Keep track of which fields have already appeared in the pattern.
|
||||
@ -868,16 +868,16 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||
let mut inexistent_fields = vec![];
|
||||
// Typecheck each field.
|
||||
for &Spanned { node: ref field, span } in fields {
|
||||
let ident = tcx.adjust(field.name, variant.did, self.body_id).0;
|
||||
let ident = tcx.adjust_ident(field.ident, variant.did, self.body_id).0;
|
||||
let field_ty = match used_fields.entry(ident) {
|
||||
Occupied(occupied) => {
|
||||
struct_span_err!(tcx.sess, span, E0025,
|
||||
"field `{}` bound multiple times \
|
||||
in the pattern",
|
||||
field.name)
|
||||
field.ident)
|
||||
.span_label(span,
|
||||
format!("multiple uses of `{}` in pattern", field.name))
|
||||
.span_label(*occupied.get(), format!("first use of `{}`", field.name))
|
||||
format!("multiple uses of `{}` in pattern", field.ident))
|
||||
.span_label(*occupied.get(), format!("first use of `{}`", field.ident))
|
||||
.emit();
|
||||
tcx.types.err
|
||||
}
|
||||
@ -890,7 +890,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||
self.field_ty(span, f, substs)
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
inexistent_fields.push((span, field.name));
|
||||
inexistent_fields.push((span, field.ident));
|
||||
tcx.types.err
|
||||
})
|
||||
}
|
||||
@ -958,7 +958,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||
} else if !etc {
|
||||
let unmentioned_fields = variant.fields
|
||||
.iter()
|
||||
.map(|field| field.name.to_ident())
|
||||
.map(|field| field.ident.modern())
|
||||
.filter(|ident| !used_fields.contains_key(&ident))
|
||||
.collect::<Vec<_>>();
|
||||
if unmentioned_fields.len() > 0 {
|
||||
|
@ -114,15 +114,15 @@ pub enum CandidateSource {
|
||||
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Determines whether the type `self_ty` supports a method name `method_name` or not.
|
||||
pub fn method_exists(&self,
|
||||
span: Span,
|
||||
method_name: ast::Name,
|
||||
method_name: ast::Ident,
|
||||
self_ty: Ty<'tcx>,
|
||||
call_expr_id: ast::NodeId,
|
||||
allow_private: bool)
|
||||
-> bool {
|
||||
let mode = probe::Mode::MethodCall;
|
||||
match self.probe_for_name(span, mode, method_name, IsSuggestion(false),
|
||||
self_ty, call_expr_id, ProbeScope::TraitsInScope) {
|
||||
match self.probe_for_name(method_name.span, mode, method_name.name,
|
||||
IsSuggestion(false), self_ty, call_expr_id,
|
||||
ProbeScope::TraitsInScope) {
|
||||
Ok(..) => true,
|
||||
Err(NoMatch(..)) => false,
|
||||
Err(Ambiguity(..)) => true,
|
||||
|
@ -422,7 +422,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
{
|
||||
let is_accessible = if let Some(name) = self.method_name {
|
||||
let item = candidate.item;
|
||||
let def_scope = self.tcx.adjust(name, item.container.id(), self.body_id).1;
|
||||
let def_scope =
|
||||
self.tcx.adjust_ident(name.to_ident(), item.container.id(), self.body_id).1;
|
||||
item.vis.is_accessible_from(def_scope, self.tcx)
|
||||
} else {
|
||||
true
|
||||
|
@ -120,7 +120,7 @@ use std::ops::{self, Deref};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::{original_sp, Spanned};
|
||||
use syntax::codemap::original_sp;
|
||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{Symbol, LocalInternedString, keywords};
|
||||
@ -3045,7 +3045,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
expr: &'gcx hir::Expr,
|
||||
needs: Needs,
|
||||
base: &'gcx hir::Expr,
|
||||
field: &Spanned<ast::Name>) -> Ty<'tcx> {
|
||||
field: ast::Ident) -> Ty<'tcx> {
|
||||
let expr_t = self.check_expr_with_needs(base, needs);
|
||||
let expr_t = self.structurally_resolved_type(base.span,
|
||||
expr_t);
|
||||
@ -3056,9 +3056,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
ty::TyAdt(base_def, substs) if !base_def.is_enum() => {
|
||||
debug!("struct named {:?}", base_t);
|
||||
let (ident, def_scope) =
|
||||
self.tcx.adjust(field.node, base_def.did, self.body_id);
|
||||
self.tcx.adjust_ident(field, base_def.did, self.body_id);
|
||||
let fields = &base_def.non_enum_variant().fields;
|
||||
if let Some(index) = fields.iter().position(|f| f.name.to_ident() == ident) {
|
||||
if let Some(index) = fields.iter().position(|f| f.ident.modern() == ident) {
|
||||
let field = &fields[index];
|
||||
let field_ty = self.field_ty(expr.span, field, substs);
|
||||
// Save the index of all fields regardless of their visibility in case
|
||||
@ -3076,7 +3076,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
ty::TyTuple(ref tys) => {
|
||||
let fstr = field.node.as_str();
|
||||
let fstr = field.name.as_str();
|
||||
if let Ok(index) = fstr.parse::<usize>() {
|
||||
if fstr == index.to_string() {
|
||||
if let Some(field_ty) = tys.get(index) {
|
||||
@ -3099,31 +3099,31 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
let struct_path = self.tcx().item_path_str(did);
|
||||
let mut err = struct_span_err!(self.tcx().sess, expr.span, E0616,
|
||||
"field `{}` of struct `{}` is private",
|
||||
field.node, struct_path);
|
||||
field, struct_path);
|
||||
// Also check if an accessible method exists, which is often what is meant.
|
||||
if self.method_exists(field.span, field.node, expr_t, expr.id, false) {
|
||||
err.note(&format!("a method `{}` also exists, perhaps you wish to call it",
|
||||
field.node));
|
||||
if self.method_exists(field, expr_t, expr.id, false) {
|
||||
err.note(&format!("a method `{}` also exists, perhaps you wish to call it", field));
|
||||
}
|
||||
err.emit();
|
||||
field_ty
|
||||
} else if field.node == keywords::Invalid.name() {
|
||||
} else if field.name == keywords::Invalid.name() {
|
||||
self.tcx().types.err
|
||||
} else if self.method_exists(field.span, field.node, expr_t, expr.id, true) {
|
||||
} else if self.method_exists(field, expr_t, expr.id, true) {
|
||||
type_error_struct!(self.tcx().sess, field.span, expr_t, E0615,
|
||||
"attempted to take value of method `{}` on type `{}`",
|
||||
field.node, expr_t)
|
||||
field, expr_t)
|
||||
.help("maybe a `()` to call it is missing?")
|
||||
.emit();
|
||||
self.tcx().types.err
|
||||
} else {
|
||||
if !expr_t.is_primitive_ty() {
|
||||
let mut err = self.no_such_field_err(field.span, &field.node, expr_t);
|
||||
let mut err = self.no_such_field_err(field.span, field, expr_t);
|
||||
|
||||
match expr_t.sty {
|
||||
ty::TyAdt(def, _) if !def.is_enum() => {
|
||||
if let Some(suggested_field_name) =
|
||||
Self::suggest_field_name(def.non_enum_variant(), field, vec![]) {
|
||||
Self::suggest_field_name(def.non_enum_variant(),
|
||||
&field.name.as_str(), vec![]) {
|
||||
err.span_label(field.span,
|
||||
format!("did you mean `{}`?", suggested_field_name));
|
||||
} else {
|
||||
@ -3139,7 +3139,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
ty::TyRawPtr(..) => {
|
||||
let base = self.tcx.hir.node_to_pretty_string(base.id);
|
||||
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
|
||||
let suggestion = format!("(*{}).{}", base, field.node);
|
||||
let suggestion = format!("(*{}).{}", base, field);
|
||||
err.span_suggestion(field.span, &msg, suggestion);
|
||||
}
|
||||
_ => {}
|
||||
@ -3156,29 +3156,28 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
// Return an hint about the closest match in field names
|
||||
fn suggest_field_name(variant: &'tcx ty::VariantDef,
|
||||
field: &Spanned<ast::Name>,
|
||||
field: &str,
|
||||
skip: Vec<LocalInternedString>)
|
||||
-> Option<Symbol> {
|
||||
let name = field.node.as_str();
|
||||
let names = variant.fields.iter().filter_map(|field| {
|
||||
// ignore already set fields and private fields from non-local crates
|
||||
if skip.iter().any(|x| *x == field.name.as_str()) ||
|
||||
if skip.iter().any(|x| *x == field.ident.name.as_str()) ||
|
||||
(variant.did.krate != LOCAL_CRATE && field.vis != Visibility::Public) {
|
||||
None
|
||||
} else {
|
||||
Some(&field.name)
|
||||
Some(&field.ident.name)
|
||||
}
|
||||
});
|
||||
|
||||
find_best_match_for_name(names, &name, None)
|
||||
find_best_match_for_name(names, field, None)
|
||||
}
|
||||
|
||||
fn available_field_names(&self, variant: &'tcx ty::VariantDef) -> Vec<ast::Name> {
|
||||
let mut available = Vec::new();
|
||||
for field in variant.fields.iter() {
|
||||
let (_, def_scope) = self.tcx.adjust(field.name, variant.did, self.body_id);
|
||||
let def_scope = self.tcx.adjust_ident(field.ident, variant.did, self.body_id).1;
|
||||
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
||||
available.push(field.name);
|
||||
available.push(field.ident.name);
|
||||
}
|
||||
}
|
||||
available
|
||||
@ -3209,36 +3208,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
skip_fields: &[hir::Field],
|
||||
kind_name: &str) {
|
||||
let mut err = self.type_error_struct_with_diag(
|
||||
field.name.span,
|
||||
field.ident.span,
|
||||
|actual| match ty.sty {
|
||||
ty::TyAdt(adt, ..) if adt.is_enum() => {
|
||||
struct_span_err!(self.tcx.sess, field.name.span, E0559,
|
||||
struct_span_err!(self.tcx.sess, field.ident.span, E0559,
|
||||
"{} `{}::{}` has no field named `{}`",
|
||||
kind_name, actual, variant.name, field.name.node)
|
||||
kind_name, actual, variant.name, field.ident)
|
||||
}
|
||||
_ => {
|
||||
struct_span_err!(self.tcx.sess, field.name.span, E0560,
|
||||
struct_span_err!(self.tcx.sess, field.ident.span, E0560,
|
||||
"{} `{}` has no field named `{}`",
|
||||
kind_name, actual, field.name.node)
|
||||
kind_name, actual, field.ident)
|
||||
}
|
||||
},
|
||||
ty);
|
||||
// prevent all specified fields from being suggested
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.name.node.as_str());
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.ident.name.as_str());
|
||||
if let Some(field_name) = Self::suggest_field_name(variant,
|
||||
&field.name,
|
||||
&field.ident.name.as_str(),
|
||||
skip_fields.collect()) {
|
||||
err.span_label(field.name.span,
|
||||
err.span_label(field.ident.span,
|
||||
format!("field does not exist - did you mean `{}`?", field_name));
|
||||
} else {
|
||||
match ty.sty {
|
||||
ty::TyAdt(adt, ..) => {
|
||||
if adt.is_enum() {
|
||||
err.span_label(field.name.span,
|
||||
err.span_label(field.ident.span,
|
||||
format!("`{}::{}` does not have this field",
|
||||
ty, variant.name));
|
||||
} else {
|
||||
err.span_label(field.name.span,
|
||||
err.span_label(field.ident.span,
|
||||
format!("`{}` does not have this field", ty));
|
||||
}
|
||||
let available_field_names = self.available_field_names(variant);
|
||||
@ -3278,7 +3277,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
let mut remaining_fields = FxHashMap();
|
||||
for (i, field) in variant.fields.iter().enumerate() {
|
||||
remaining_fields.insert(field.name.to_ident(), (i, field));
|
||||
remaining_fields.insert(field.ident.modern(), (i, field));
|
||||
}
|
||||
|
||||
let mut seen_fields = FxHashMap();
|
||||
@ -3287,7 +3286,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
// Typecheck each field.
|
||||
for field in ast_fields {
|
||||
let ident = tcx.adjust(field.name.node, variant.did, self.body_id).0;
|
||||
let ident = tcx.adjust_ident(field.ident, variant.did, self.body_id).0;
|
||||
let field_type = if let Some((i, v_field)) = remaining_fields.remove(&ident) {
|
||||
seen_fields.insert(ident, field.span);
|
||||
self.write_field_index(field.id, i);
|
||||
@ -3304,12 +3303,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
error_happened = true;
|
||||
if let Some(prev_span) = seen_fields.get(&ident) {
|
||||
let mut err = struct_span_err!(self.tcx.sess,
|
||||
field.name.span,
|
||||
field.ident.span,
|
||||
E0062,
|
||||
"field `{}` specified more than once",
|
||||
ident);
|
||||
|
||||
err.span_label(field.name.span, "used more than once");
|
||||
err.span_label(field.ident.span, "used more than once");
|
||||
err.span_label(*prev_span, format!("first use of `{}`", ident));
|
||||
|
||||
err.emit();
|
||||
@ -4054,7 +4053,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
hir::ExprStruct(ref qpath, ref fields, ref base_expr) => {
|
||||
self.check_expr_struct(expr, expected, qpath, fields, base_expr)
|
||||
}
|
||||
hir::ExprField(ref base, ref field) => {
|
||||
hir::ExprField(ref base, field) => {
|
||||
self.check_field(expr, needs, &base, field)
|
||||
}
|
||||
hir::ExprIndex(ref base, ref idx) => {
|
||||
|
@ -354,7 +354,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>,
|
||||
diff_fields.len(),
|
||||
diff_fields.iter()
|
||||
.map(|&(i, a, b)| {
|
||||
format!("{} ({} to {})", fields[i].name, a, b)
|
||||
format!("{} ({} to {})", fields[i].ident, a, b)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")));
|
||||
|
@ -520,21 +520,21 @@ fn convert_struct_variant<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
let node_id = tcx.hir.as_local_node_id(did).unwrap();
|
||||
let fields = def.fields().iter().map(|f| {
|
||||
let fid = tcx.hir.local_def_id(f.id);
|
||||
let dup_span = seen_fields.get(&f.name.to_ident()).cloned();
|
||||
let dup_span = seen_fields.get(&f.ident.modern()).cloned();
|
||||
if let Some(prev_span) = dup_span {
|
||||
struct_span_err!(tcx.sess, f.span, E0124,
|
||||
"field `{}` is already declared",
|
||||
f.name)
|
||||
f.ident)
|
||||
.span_label(f.span, "field already declared")
|
||||
.span_label(prev_span, format!("`{}` first declared here", f.name))
|
||||
.span_label(prev_span, format!("`{}` first declared here", f.ident))
|
||||
.emit();
|
||||
} else {
|
||||
seen_fields.insert(f.name.to_ident(), f.span);
|
||||
seen_fields.insert(f.ident.modern(), f.span);
|
||||
}
|
||||
|
||||
ty::FieldDef {
|
||||
did: fid,
|
||||
name: f.name,
|
||||
ident: f.ident,
|
||||
vis: ty::Visibility::from_hir(&f.vis, node_id, tcx)
|
||||
}
|
||||
}).collect();
|
||||
|
@ -1091,19 +1091,19 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
|
||||
_ => false,
|
||||
};
|
||||
let elem = if is_enum {
|
||||
cx.tcx.adt_def(did).all_fields().find(|item| item.name == item_name)
|
||||
cx.tcx.adt_def(did).all_fields().find(|item| item.ident.name == item_name)
|
||||
} else {
|
||||
cx.tcx.adt_def(did)
|
||||
.non_enum_variant()
|
||||
.fields
|
||||
.iter()
|
||||
.find(|item| item.name == item_name)
|
||||
.find(|item| item.ident.name == item_name)
|
||||
};
|
||||
if let Some(item) = elem {
|
||||
Ok((ty.def,
|
||||
Some(format!("{}.{}",
|
||||
if is_enum { "variant" } else { "structfield" },
|
||||
item.name))))
|
||||
item.ident))))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
@ -2990,7 +2990,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
impl Clean<Item> for hir::StructField {
|
||||
fn clean(&self, cx: &DocContext) -> Item {
|
||||
Item {
|
||||
name: Some(self.name).clean(cx),
|
||||
name: Some(self.ident.name).clean(cx),
|
||||
attrs: self.attrs.clean(cx),
|
||||
source: self.span.clean(cx),
|
||||
visibility: self.vis.clean(cx),
|
||||
@ -3005,7 +3005,7 @@ impl Clean<Item> for hir::StructField {
|
||||
impl<'tcx> Clean<Item> for ty::FieldDef {
|
||||
fn clean(&self, cx: &DocContext) -> Item {
|
||||
Item {
|
||||
name: Some(self.name).clean(cx),
|
||||
name: Some(self.ident.name).clean(cx),
|
||||
attrs: cx.tcx.get_attrs(self.did).clean(cx),
|
||||
source: cx.tcx.def_span(self.did).clean(cx),
|
||||
visibility: self.vis.clean(cx),
|
||||
@ -3201,7 +3201,7 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
|
||||
fields: self.fields.iter().map(|field| {
|
||||
Item {
|
||||
source: cx.tcx.def_span(field.did).clean(cx),
|
||||
name: Some(field.name.clean(cx)),
|
||||
name: Some(field.ident.name.clean(cx)),
|
||||
attrs: cx.tcx.get_attrs(field.did).clean(cx),
|
||||
visibility: field.vis.clean(cx),
|
||||
def_id: field.did,
|
||||
@ -3850,7 +3850,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
|
||||
PatKind::Struct(ref name, ref fields, etc) => {
|
||||
format!("{} {{ {}{} }}", qpath_to_string(name),
|
||||
fields.iter().map(|&Spanned { node: ref fp, .. }|
|
||||
format!("{}: {}", fp.name, name_from_pat(&*fp.pat)))
|
||||
format!("{}: {}", fp.ident, name_from_pat(&*fp.pat)))
|
||||
.collect::<Vec<String>>().join(", "),
|
||||
if etc { ", ..." } else { "" }
|
||||
)
|
||||
|
@ -743,7 +743,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, f: &'hir hir::StructField) {
|
||||
self.visit_testable(f.name.to_string(), &f.attrs, |this| {
|
||||
self.visit_testable(f.ident.to_string(), &f.attrs, |this| {
|
||||
intravisit::walk_struct_field(this, f);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user