Auto merge of #51072 - petrochenkov:ifield, r=eddyb
Use `Ident`s for fields in HIR Continuation of https://github.com/rust-lang/rust/pull/49718, part of https://github.com/rust-lang/rust/issues/49300
This commit is contained in:
commit
1e504d301c
51 changed files with 208 additions and 186 deletions
|
@ -208,7 +208,7 @@ impl LintPass for Pass {
|
||||||
|
|
||||||
impl EarlyLintPass for Pass {
|
impl EarlyLintPass for Pass {
|
||||||
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
|
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
|
||||||
if it.ident.name.as_str() == "lintme" {
|
if it.ident.as_str() == "lintme" {
|
||||||
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
|
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1214,14 +1214,14 @@ impl TokenTree {
|
||||||
SingleQuote => op!('\''),
|
SingleQuote => op!('\''),
|
||||||
|
|
||||||
Ident(ident, false) => {
|
Ident(ident, false) => {
|
||||||
tt!(self::Ident::new(&ident.name.as_str(), Span(span)))
|
tt!(self::Ident::new(&ident.as_str(), Span(span)))
|
||||||
}
|
}
|
||||||
Ident(ident, true) => {
|
Ident(ident, true) => {
|
||||||
tt!(self::Ident::new_raw(&ident.name.as_str(), Span(span)))
|
tt!(self::Ident::new_raw(&ident.as_str(), Span(span)))
|
||||||
}
|
}
|
||||||
Lifetime(ident) => {
|
Lifetime(ident) => {
|
||||||
let ident = ident.without_first_quote();
|
let ident = ident.without_first_quote();
|
||||||
stack.push(tt!(self::Ident::new(&ident.name.as_str(), Span(span))));
|
stack.push(tt!(self::Ident::new(&ident.as_str(), Span(span))));
|
||||||
tt!(Punct::new('\'', Spacing::Joint))
|
tt!(Punct::new('\'', Spacing::Joint))
|
||||||
}
|
}
|
||||||
Literal(lit, suffix) => tt!(self::Literal { lit, suffix, span: Span(span) }),
|
Literal(lit, suffix) => tt!(self::Literal { lit, suffix, span: Span(span) }),
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
//! example generator inference, and possibly also HIR borrowck.
|
//! example generator inference, and possibly also HIR borrowck.
|
||||||
|
|
||||||
use rustc_target::spec::abi::Abi;
|
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 syntax_pos::Span;
|
||||||
use hir::*;
|
use hir::*;
|
||||||
use hir::def::Def;
|
use hir::def::Def;
|
||||||
|
@ -248,6 +248,9 @@ pub trait Visitor<'v> : Sized {
|
||||||
fn visit_name(&mut self, _span: Span, _name: Name) {
|
fn visit_name(&mut self, _span: Span, _name: Name) {
|
||||||
// Nothing to do.
|
// 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) {
|
fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: NodeId) {
|
||||||
walk_mod(self, m, n)
|
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);
|
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) {
|
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
|
||||||
visitor.visit_name(label.span, label.name);
|
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);
|
visitor.visit_qpath(qpath, pattern.id, pattern.span);
|
||||||
for field in fields {
|
for field in fields {
|
||||||
visitor.visit_id(field.node.id);
|
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)
|
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) {
|
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) {
|
||||||
visitor.visit_id(struct_field.id);
|
visitor.visit_id(struct_field.id);
|
||||||
visitor.visit_vis(&struct_field.vis);
|
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);
|
visitor.visit_ty(&struct_field.ty);
|
||||||
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
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);
|
visitor.visit_qpath(qpath, expression.id, expression.span);
|
||||||
for field in fields {
|
for field in fields {
|
||||||
visitor.visit_id(field.id);
|
visitor.visit_id(field.id);
|
||||||
visitor.visit_name(field.name.span, field.name.node);
|
visitor.visit_ident(field.ident);
|
||||||
visitor.visit_expr(&field.expr)
|
visitor.visit_expr(&field.expr)
|
||||||
}
|
}
|
||||||
walk_list!(visitor, visit_expr, optional_base);
|
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(right_expression);
|
||||||
visitor.visit_expr(left_expression)
|
visitor.visit_expr(left_expression)
|
||||||
}
|
}
|
||||||
ExprField(ref subexpression, ref name) => {
|
ExprField(ref subexpression, ident) => {
|
||||||
visitor.visit_expr(subexpression);
|
visitor.visit_expr(subexpression);
|
||||||
visitor.visit_name(name.span, name.node);
|
visitor.visit_ident(ident);
|
||||||
}
|
}
|
||||||
ExprIndex(ref main_expression, ref index_expression) => {
|
ExprIndex(ref main_expression, ref index_expression) => {
|
||||||
visitor.visit_expr(main_expression);
|
visitor.visit_expr(main_expression);
|
||||||
|
|
|
@ -2072,11 +2072,11 @@ impl<'a> LoweringContext<'a> {
|
||||||
hir::StructField {
|
hir::StructField {
|
||||||
span: f.span,
|
span: f.span,
|
||||||
id: self.lower_node_id(f.id).node_id,
|
id: self.lower_node_id(f.id).node_id,
|
||||||
name: self.lower_ident(match f.ident {
|
ident: match f.ident {
|
||||||
Some(ident) => ident,
|
Some(ident) => ident,
|
||||||
// FIXME(jseyfried) positional field hygiene
|
// FIXME(jseyfried) positional field hygiene
|
||||||
None => Ident::new(Symbol::intern(&index.to_string()), f.span),
|
None => Ident::new(Symbol::intern(&index.to_string()), f.span),
|
||||||
}),
|
},
|
||||||
vis: self.lower_visibility(&f.vis, None),
|
vis: self.lower_visibility(&f.vis, None),
|
||||||
ty: self.lower_ty(&f.ty, ImplTraitContext::Disallowed),
|
ty: self.lower_ty(&f.ty, ImplTraitContext::Disallowed),
|
||||||
attrs: self.lower_attrs(&f.attrs),
|
attrs: self.lower_attrs(&f.attrs),
|
||||||
|
@ -2086,7 +2086,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
fn lower_field(&mut self, f: &Field) -> hir::Field {
|
fn lower_field(&mut self, f: &Field) -> hir::Field {
|
||||||
hir::Field {
|
hir::Field {
|
||||||
id: self.next_id().node_id,
|
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)),
|
expr: P(self.lower_expr(&f.expr)),
|
||||||
span: f.span,
|
span: f.span,
|
||||||
is_shorthand: f.is_shorthand,
|
is_shorthand: f.is_shorthand,
|
||||||
|
@ -2848,7 +2848,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
span: f.span,
|
span: f.span,
|
||||||
node: hir::FieldPat {
|
node: hir::FieldPat {
|
||||||
id: self.next_id().node_id,
|
id: self.next_id().node_id,
|
||||||
name: self.lower_ident(f.node.ident),
|
ident: f.node.ident,
|
||||||
pat: self.lower_pat(&f.node.pat),
|
pat: self.lower_pat(&f.node.pat),
|
||||||
is_shorthand: f.node.is_shorthand,
|
is_shorthand: f.node.is_shorthand,
|
||||||
},
|
},
|
||||||
|
@ -3091,10 +3091,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
P(self.lower_expr(el)),
|
P(self.lower_expr(el)),
|
||||||
P(self.lower_expr(er)),
|
P(self.lower_expr(er)),
|
||||||
),
|
),
|
||||||
ExprKind::Field(ref el, ident) => hir::ExprField(
|
ExprKind::Field(ref el, ident) => hir::ExprField(P(self.lower_expr(el)), ident),
|
||||||
P(self.lower_expr(el)),
|
|
||||||
respan(ident.span, self.lower_ident(ident)),
|
|
||||||
),
|
|
||||||
ExprKind::Index(ref el, ref er) => {
|
ExprKind::Index(ref el, ref er) => {
|
||||||
hir::ExprIndex(P(self.lower_expr(el)), P(self.lower_expr(er)))
|
hir::ExprIndex(P(self.lower_expr(el)), P(self.lower_expr(er)))
|
||||||
}
|
}
|
||||||
|
@ -3134,7 +3131,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
let expr = P(self.lower_expr(&e));
|
let expr = P(self.lower_expr(&e));
|
||||||
let unstable_span =
|
let unstable_span =
|
||||||
self.allow_internal_unstable(CompilerDesugaringKind::DotFill, e.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]>>();
|
.collect::<P<[hir::Field]>>();
|
||||||
|
|
||||||
|
@ -3749,10 +3747,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 {
|
hir::Field {
|
||||||
id: self.next_id().node_id,
|
id: self.next_id().node_id,
|
||||||
name: Spanned { node: name, span },
|
ident,
|
||||||
span,
|
span,
|
||||||
expr,
|
expr,
|
||||||
is_shorthand: false,
|
is_shorthand: false,
|
||||||
|
|
|
@ -909,7 +909,7 @@ impl<'hir> Map<'hir> {
|
||||||
NodeImplItem(ii) => ii.name,
|
NodeImplItem(ii) => ii.name,
|
||||||
NodeTraitItem(ti) => ti.name,
|
NodeTraitItem(ti) => ti.name,
|
||||||
NodeVariant(v) => v.node.name,
|
NodeVariant(v) => v.node.name,
|
||||||
NodeField(f) => f.name,
|
NodeField(f) => f.ident.name,
|
||||||
NodeLifetime(lt) => lt.name.name(),
|
NodeLifetime(lt) => lt.name.name(),
|
||||||
NodeTyParam(tp) => tp.name,
|
NodeTyParam(tp) => tp.name,
|
||||||
NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
|
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 Item { fn name(&self) -> Name { self.name } }
|
||||||
impl Named for ForeignItem { 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 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 TraitItem { fn name(&self) -> Name { self.name } }
|
||||||
impl Named for ImplItem { 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)) => {
|
Some(NodeField(ref field)) => {
|
||||||
format!("field {} in {}{}",
|
format!("field {} in {}{}",
|
||||||
field.name,
|
field.ident,
|
||||||
path_str(), id_str)
|
path_str(), id_str)
|
||||||
}
|
}
|
||||||
Some(NodeAnonConst(_)) => {
|
Some(NodeAnonConst(_)) => {
|
||||||
|
|
|
@ -35,7 +35,7 @@ use mir::mono::Linkage;
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use syntax::codemap::{self, Spanned};
|
use syntax::codemap::{self, Spanned};
|
||||||
use rustc_target::spec::abi::Abi;
|
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::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
|
||||||
use syntax::attr::InlineAttr;
|
use syntax::attr::InlineAttr;
|
||||||
use syntax::ext::hygiene::SyntaxContext;
|
use syntax::ext::hygiene::SyntaxContext;
|
||||||
|
@ -866,7 +866,7 @@ impl Pat {
|
||||||
pub struct FieldPat {
|
pub struct FieldPat {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
/// The identifier for the field
|
/// The identifier for the field
|
||||||
pub name: Name,
|
pub ident: Ident,
|
||||||
/// The pattern the field is destructured to
|
/// The pattern the field is destructured to
|
||||||
pub pat: P<Pat>,
|
pub pat: P<Pat>,
|
||||||
pub is_shorthand: bool,
|
pub is_shorthand: bool,
|
||||||
|
@ -1211,7 +1211,7 @@ pub struct Arm {
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub struct Field {
|
pub struct Field {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub name: Spanned<Name>,
|
pub ident: Ident,
|
||||||
pub expr: P<Expr>,
|
pub expr: P<Expr>,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub is_shorthand: bool,
|
pub is_shorthand: bool,
|
||||||
|
@ -1414,7 +1414,7 @@ pub enum Expr_ {
|
||||||
/// For example, `a += 1`.
|
/// For example, `a += 1`.
|
||||||
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
|
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
|
||||||
/// Access of a named (`obj.foo`) or unnamed (`obj.0`) struct or tuple field
|
/// 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]`)
|
/// An indexing operation (`foo[2]`)
|
||||||
ExprIndex(P<Expr>, P<Expr>),
|
ExprIndex(P<Expr>, P<Expr>),
|
||||||
|
|
||||||
|
@ -1973,7 +1973,7 @@ impl Visibility {
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub struct StructField {
|
pub struct StructField {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: Name,
|
pub ident: Ident,
|
||||||
pub vis: Visibility,
|
pub vis: Visibility,
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub ty: P<Ty>,
|
pub ty: P<Ty>,
|
||||||
|
@ -1983,7 +1983,7 @@ pub struct StructField {
|
||||||
impl StructField {
|
impl StructField {
|
||||||
// Still necessary in couple of places
|
// Still necessary in couple of places
|
||||||
pub fn is_positional(&self) -> bool {
|
pub fn is_positional(&self) -> bool {
|
||||||
let first = self.name.as_str().as_bytes()[0];
|
let first = self.ident.as_str().as_bytes()[0];
|
||||||
first >= b'0' && first <= b'9'
|
first >= b'0' && first <= b'9'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -857,7 +857,7 @@ impl<'a> State<'a> {
|
||||||
self.maybe_print_comment(field.span.lo())?;
|
self.maybe_print_comment(field.span.lo())?;
|
||||||
self.print_outer_attributes(&field.attrs)?;
|
self.print_outer_attributes(&field.attrs)?;
|
||||||
self.print_visibility(&field.vis)?;
|
self.print_visibility(&field.vis)?;
|
||||||
self.print_name(field.name)?;
|
self.print_ident(field.ident)?;
|
||||||
self.word_nbsp(":")?;
|
self.word_nbsp(":")?;
|
||||||
self.print_type(&field.ty)?;
|
self.print_type(&field.ty)?;
|
||||||
self.s.word(",")?;
|
self.s.word(",")?;
|
||||||
|
@ -1166,7 +1166,7 @@ impl<'a> State<'a> {
|
||||||
|s, field| {
|
|s, field| {
|
||||||
s.ibox(indent_unit)?;
|
s.ibox(indent_unit)?;
|
||||||
if !field.is_shorthand {
|
if !field.is_shorthand {
|
||||||
s.print_name(field.name.node)?;
|
s.print_ident(field.ident)?;
|
||||||
s.word_space(":")?;
|
s.word_space(":")?;
|
||||||
}
|
}
|
||||||
s.print_expr(&field.expr)?;
|
s.print_expr(&field.expr)?;
|
||||||
|
@ -1406,10 +1406,10 @@ impl<'a> State<'a> {
|
||||||
self.word_space("=")?;
|
self.word_space("=")?;
|
||||||
self.print_expr_maybe_paren(&rhs, prec)?;
|
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.print_expr_maybe_paren(expr, parser::PREC_POSTFIX)?;
|
||||||
self.s.word(".")?;
|
self.s.word(".")?;
|
||||||
self.print_name(name.node)?;
|
self.print_ident(ident)?;
|
||||||
}
|
}
|
||||||
hir::ExprIndex(ref expr, ref index) => {
|
hir::ExprIndex(ref expr, ref index) => {
|
||||||
self.print_expr_maybe_paren(&expr, parser::PREC_POSTFIX)?;
|
self.print_expr_maybe_paren(&expr, parser::PREC_POSTFIX)?;
|
||||||
|
@ -1561,13 +1561,17 @@ impl<'a> State<'a> {
|
||||||
self.s.word(&i.to_string())
|
self.s.word(&i.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
|
pub fn print_ident(&mut self, ident: ast::Ident) -> io::Result<()> {
|
||||||
if name.to_ident().is_raw_guess() {
|
if ident.is_raw_guess() {
|
||||||
self.s.word(&format!("r#{}", name))?;
|
self.s.word(&format!("r#{}", ident.name))?;
|
||||||
} else {
|
} else {
|
||||||
self.s.word(&name.as_str())?;
|
self.s.word(&ident.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<()> {
|
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, f| {
|
||||||
s.cbox(indent_unit)?;
|
s.cbox(indent_unit)?;
|
||||||
if !f.node.is_shorthand {
|
if !f.node.is_shorthand {
|
||||||
s.print_name(f.node.name)?;
|
s.print_ident(f.node.ident)?;
|
||||||
s.word_nbsp(":")?;
|
s.word_nbsp(":")?;
|
||||||
}
|
}
|
||||||
s.print_pat(&f.node.pat)?;
|
s.print_pat(&f.node.pat)?;
|
||||||
|
|
|
@ -427,12 +427,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::FieldPat {
|
||||||
hasher: &mut StableHasher<W>) {
|
hasher: &mut StableHasher<W>) {
|
||||||
let hir::FieldPat {
|
let hir::FieldPat {
|
||||||
id: _,
|
id: _,
|
||||||
name,
|
ident,
|
||||||
ref pat,
|
ref pat,
|
||||||
is_shorthand,
|
is_shorthand,
|
||||||
} = *self;
|
} = *self;
|
||||||
|
|
||||||
name.hash_stable(hcx, hasher);
|
ident.hash_stable(hcx, hasher);
|
||||||
pat.hash_stable(hcx, hasher);
|
pat.hash_stable(hcx, hasher);
|
||||||
is_shorthand.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>) {
|
hasher: &mut StableHasher<W>) {
|
||||||
let hir::Field {
|
let hir::Field {
|
||||||
id: _,
|
id: _,
|
||||||
name,
|
ident,
|
||||||
ref expr,
|
ref expr,
|
||||||
span,
|
span,
|
||||||
is_shorthand,
|
is_shorthand,
|
||||||
} = *self;
|
} = *self;
|
||||||
|
|
||||||
name.hash_stable(hcx, hasher);
|
ident.hash_stable(hcx, hasher);
|
||||||
expr.hash_stable(hcx, hasher);
|
expr.hash_stable(hcx, hasher);
|
||||||
span.hash_stable(hcx, hasher);
|
span.hash_stable(hcx, hasher);
|
||||||
is_shorthand.hash_stable(hcx, hasher);
|
is_shorthand.hash_stable(hcx, hasher);
|
||||||
|
@ -598,7 +598,7 @@ impl_stable_hash_for!(enum hir::Expr_ {
|
||||||
ExprBlock(blk, label),
|
ExprBlock(blk, label),
|
||||||
ExprAssign(lhs, rhs),
|
ExprAssign(lhs, rhs),
|
||||||
ExprAssignOp(op, lhs, rhs),
|
ExprAssignOp(op, lhs, rhs),
|
||||||
ExprField(owner, field_name),
|
ExprField(owner, ident),
|
||||||
ExprIndex(lhs, rhs),
|
ExprIndex(lhs, rhs),
|
||||||
ExprPath(path),
|
ExprPath(path),
|
||||||
ExprAddrOf(mutability, sub),
|
ExprAddrOf(mutability, sub),
|
||||||
|
@ -835,7 +835,7 @@ impl_stable_hash_for!(enum hir::UseKind {
|
||||||
|
|
||||||
impl_stable_hash_for!(struct hir::StructField {
|
impl_stable_hash_for!(struct hir::StructField {
|
||||||
span,
|
span,
|
||||||
name,
|
ident,
|
||||||
vis,
|
vis,
|
||||||
id,
|
id,
|
||||||
ty,
|
ty,
|
||||||
|
|
|
@ -357,11 +357,17 @@ impl_stable_hash_for!(enum ty::VariantDiscr {
|
||||||
Relative(distance)
|
Relative(distance)
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_stable_hash_for!(struct ty::FieldDef {
|
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::FieldDef {
|
||||||
did,
|
fn hash_stable<W: StableHasherResult>(&self,
|
||||||
name,
|
hcx: &mut StableHashingContext<'a>,
|
||||||
vis
|
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>>
|
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
|
||||||
for ::middle::const_val::ConstVal<'gcx> {
|
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) {
|
fn visit_struct_field(&mut self, field: &'tcx hir::StructField) {
|
||||||
if self.should_warn_about_field(&field) {
|
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);
|
intravisit::walk_struct_field(self, field);
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,7 +669,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||||
&*with_expr,
|
&*with_expr,
|
||||||
with_cmt.clone(),
|
with_cmt.clone(),
|
||||||
f_index,
|
f_index,
|
||||||
with_field.name,
|
with_field.ident,
|
||||||
with_field.ty(self.tcx(), substs)
|
with_field.ty(self.tcx(), substs)
|
||||||
);
|
);
|
||||||
self.delegate_consume(with_expr.id, with_expr.span, &cmt_field);
|
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)?);
|
let base_cmt = Rc::new(self.cat_expr(&base)?);
|
||||||
debug!("cat_expr(cat_field): id={} expr={:?} base={:?}",
|
debug!("cat_expr(cat_field): id={} expr={:?} base={:?}",
|
||||||
expr.id,
|
expr.id,
|
||||||
expr,
|
expr,
|
||||||
base_cmt);
|
base_cmt);
|
||||||
let f_index = self.tcx.field_index(expr.id, self.tables);
|
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, _) => {
|
hir::ExprIndex(ref base, _) => {
|
||||||
|
@ -983,14 +983,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
node: &N,
|
node: &N,
|
||||||
base_cmt: cmt<'tcx>,
|
base_cmt: cmt<'tcx>,
|
||||||
f_index: usize,
|
f_index: usize,
|
||||||
f_name: Name,
|
f_ident: ast::Ident,
|
||||||
f_ty: Ty<'tcx>)
|
f_ty: Ty<'tcx>)
|
||||||
-> cmt_<'tcx> {
|
-> cmt_<'tcx> {
|
||||||
let ret = cmt_ {
|
let ret = cmt_ {
|
||||||
id: node.id(),
|
id: node.id(),
|
||||||
span: node.span(),
|
span: node.span(),
|
||||||
mutbl: base_cmt.mutbl.inherit(),
|
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,
|
ty: f_ty,
|
||||||
note: NoteNone
|
note: NoteNone
|
||||||
};
|
};
|
||||||
|
@ -1301,8 +1302,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
for fp in field_pats {
|
for fp in field_pats {
|
||||||
let field_ty = self.pat_ty(&fp.node.pat)?; // see (*2)
|
let field_ty = self.pat_ty(&fp.node.pat)?; // see (*2)
|
||||||
let f_index = self.tcx.field_index(fp.node.id, self.tables);
|
let f_index = self.tcx.field_index(fp.node.id, self.tables);
|
||||||
let cmt_field =
|
let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index,
|
||||||
Rc::new(self.cat_field(pat, cmt.clone(), f_index, fp.node.name, field_ty));
|
fp.node.ident, field_ty));
|
||||||
self.cat_pattern_(cmt_field, &fp.node.pat, op)?;
|
self.cat_pattern_(cmt_field, &fp.node.pat, op)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1774,7 +1774,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
||||||
CtorKind::Fictive => {
|
CtorKind::Fictive => {
|
||||||
let mut struct_fmt = fmt.debug_struct("");
|
let mut struct_fmt = fmt.debug_struct("");
|
||||||
for (field, place) in variant_def.fields.iter().zip(places) {
|
for (field, place) in variant_def.fields.iter().zip(places) {
|
||||||
struct_fmt.field(&field.name.as_str(), place);
|
struct_fmt.field(&field.ident.as_str(), place);
|
||||||
}
|
}
|
||||||
struct_fmt.finish()
|
struct_fmt.finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -976,7 +976,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
}) => {
|
}) => {
|
||||||
(self.tcx.sess.codemap().def_span(span),
|
(self.tcx.sess.codemap().def_span(span),
|
||||||
fields.iter().map(|field| {
|
fields.iter().map(|field| {
|
||||||
ArgKind::Arg(format!("{}", field.name), "_".to_string())
|
ArgKind::Arg(format!("{}", field.ident), "_".to_string())
|
||||||
}).collect::<Vec<_>>())
|
}).collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
hir::map::NodeStructCtor(ref variant_data) => {
|
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() {
|
if !adt_def.variants.is_empty() {
|
||||||
let variant_def = &adt_def.variants[index];
|
let variant_def = &adt_def.variants[index];
|
||||||
let fields: Vec<_> =
|
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(),
|
record(adt_kind.into(),
|
||||||
adt_packed,
|
adt_packed,
|
||||||
None,
|
None,
|
||||||
|
@ -1248,7 +1248,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
||||||
let variant_infos: Vec<_> =
|
let variant_infos: Vec<_> =
|
||||||
adt_def.variants.iter().enumerate().map(|(i, variant_def)| {
|
adt_def.variants.iter().enumerate().map(|(i, variant_def)| {
|
||||||
let fields: Vec<_> =
|
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),
|
build_variant_info(Some(variant_def.name),
|
||||||
&fields,
|
&fields,
|
||||||
layout.for_variant(self, i))
|
layout.for_variant(self, i))
|
||||||
|
|
|
@ -1619,7 +1619,7 @@ pub enum VariantDiscr {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FieldDef {
|
pub struct FieldDef {
|
||||||
pub did: DefId,
|
pub did: DefId,
|
||||||
pub name: Name,
|
pub ident: Ident,
|
||||||
pub vis: Visibility,
|
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> {
|
pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<usize> {
|
||||||
variant.fields.iter().position(|field| {
|
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
|
// supposed definition name (`def_name`). The method also needs `DefId` of the supposed
|
||||||
// definition's parent/scope to perform comparison.
|
// definition's parent/scope to perform comparison.
|
||||||
pub fn hygienic_eq(self, use_name: Name, def_name: Name, def_parent_def_id: DefId) -> bool {
|
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()
|
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(self, name: Name, scope: DefId, block: NodeId) -> (Ident, DefId) {
|
|
||||||
self.adjust_ident(name.to_ident(), scope, block)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) {
|
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),
|
LOCAL_CRATE => self.hir.definitions().expansion(scope.index),
|
||||||
_ => Mark::root(),
|
_ => Mark::root(),
|
||||||
};
|
};
|
||||||
|
ident = ident.modern();
|
||||||
let scope = match ident.span.adjust(expansion) {
|
let scope = match ident.span.adjust(expansion) {
|
||||||
Some(macro_def) => self.hir.definitions().macro_def_scope(macro_def),
|
Some(macro_def) => self.hir.definitions().macro_def_scope(macro_def),
|
||||||
None if block == DUMMY_NODE_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId
|
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::Safe => RestrictionResult::Safe,
|
||||||
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
|
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
|
||||||
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
||||||
let field =
|
let field = InteriorKind::InteriorField(
|
||||||
InteriorKind::InteriorField(mc::FieldIndex(i, field.name));
|
mc::FieldIndex(i, field.ident.name)
|
||||||
|
);
|
||||||
let field_ty = if field == interior {
|
let field_ty = if field == interior {
|
||||||
cmt.ty
|
cmt.ty
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -343,7 +343,8 @@ impl<'a, 'tcx> MoveData<'tcx> {
|
||||||
= (&base_lp.ty.sty, lp_elem) {
|
= (&base_lp.ty.sty, lp_elem) {
|
||||||
if adt_def.is_union() {
|
if adt_def.is_union() {
|
||||||
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
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 {
|
if field != interior {
|
||||||
let sibling_lp_kind =
|
let sibling_lp_kind =
|
||||||
LpExtend(base_lp.clone(), mutbl, LpInterior(opt_variant_id, field));
|
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 let ty::TyAdt(adt_def, _) = base_lp.ty.sty {
|
||||||
if adt_def.is_union() {
|
if adt_def.is_union() {
|
||||||
for (i, field) in adt_def.non_enum_variant().fields.iter().enumerate() {
|
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 {
|
let field_ty = if field == interior {
|
||||||
lp.ty
|
lp.ty
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -951,7 +951,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
|
||||||
let name = if self.variant.ctor_kind == CtorKind::Fn {
|
let name = if self.variant.ctor_kind == CtorKind::Fn {
|
||||||
format!("__{}", i)
|
format!("__{}", i)
|
||||||
} else {
|
} else {
|
||||||
f.name.to_string()
|
f.ident.to_string()
|
||||||
};
|
};
|
||||||
let field = layout.field(cx, i);
|
let field = layout.field(cx, i);
|
||||||
let (size, align) = field.size_and_align();
|
let (size, align) = field.size_and_align();
|
||||||
|
@ -1072,7 +1072,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
|
||||||
let field = self.layout.field(cx, i);
|
let field = self.layout.field(cx, i);
|
||||||
let (size, align) = field.size_and_align();
|
let (size, align) = field.size_and_align();
|
||||||
MemberDescription {
|
MemberDescription {
|
||||||
name: f.name.to_string(),
|
name: f.ident.to_string(),
|
||||||
type_metadata: type_metadata(cx, field.ty, self.span),
|
type_metadata: type_metadata(cx, field.ty, self.span),
|
||||||
offset: Size::ZERO,
|
offset: Size::ZERO,
|
||||||
size,
|
size,
|
||||||
|
@ -1338,7 +1338,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||||
let name = if variant.ctor_kind == CtorKind::Fn {
|
let name = if variant.ctor_kind == CtorKind::Fn {
|
||||||
format!("__{}", i)
|
format!("__{}", i)
|
||||||
} else {
|
} else {
|
||||||
variant.fields[i].name.to_string()
|
variant.fields[i].ident.to_string()
|
||||||
};
|
};
|
||||||
(name, layout.field(cx, i).ty)
|
(name, layout.field(cx, i).ty)
|
||||||
})).collect();
|
})).collect();
|
||||||
|
|
|
@ -363,7 +363,7 @@ impl SymbolPathBuffer {
|
||||||
result: String::with_capacity(64),
|
result: String::with_capacity(64),
|
||||||
temp_buf: String::with_capacity(16),
|
temp_buf: String::with_capacity(16),
|
||||||
};
|
};
|
||||||
result.result.push_str(&symbol.name.as_str());
|
result.result.push_str(&symbol.as_str());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -324,7 +324,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
|
||||||
_: &hir::Generics,
|
_: &hir::Generics,
|
||||||
_: ast::NodeId) {
|
_: ast::NodeId) {
|
||||||
for sf in s.fields() {
|
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.as_str(), Some(sf.span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,7 +542,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
let f = self.entry(index);
|
let f = self.entry(index);
|
||||||
ty::FieldDef {
|
ty::FieldDef {
|
||||||
did: self.local_def_id(index),
|
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)
|
vis: f.visibility.decode(self)
|
||||||
}
|
}
|
||||||
}).collect(),
|
}).collect(),
|
||||||
|
|
|
@ -746,7 +746,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
||||||
Place::Projection(ref proj) => match proj.elem {
|
Place::Projection(ref proj) => match proj.elem {
|
||||||
ProjectionElem::Deref => self.describe_field(&proj.base, field),
|
ProjectionElem::Deref => self.describe_field(&proj.base, field),
|
||||||
ProjectionElem::Downcast(def, variant_index) => {
|
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) => {
|
ProjectionElem::Field(_, field_type) => {
|
||||||
self.describe_field_from_ty(&field_type, field)
|
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() {
|
ty::TyAdt(def, _) => if def.is_enum() {
|
||||||
format!("{}", field.index())
|
format!("{}", field.index())
|
||||||
} else {
|
} 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::TyTuple(_) => format!("{}", field.index()),
|
||||||
ty::TyRef(_, ty, _) | ty::TyRawPtr(ty::TypeAndMut { ty, .. }) => {
|
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 {
|
if let PatternKind::Wild = *p.pattern.kind {
|
||||||
continue;
|
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)?;
|
write!(f, "{}{}: {}", start_or_continue(), name, p.pattern)?;
|
||||||
printed += 1;
|
printed += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -772,7 +772,7 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
debug!("CodegenUnit {}:", cgu.name());
|
debug!("CodegenUnit {}:", cgu.name());
|
||||||
|
|
||||||
for (mono_item, linkage) in cgu.items() {
|
for (mono_item, linkage) in cgu.items() {
|
||||||
let symbol_name = mono_item.symbol_name(tcx).name.as_str();
|
let symbol_name = mono_item.symbol_name(tcx).as_str();
|
||||||
let symbol_hash_start = symbol_name.rfind('h');
|
let symbol_hash_start = symbol_name.rfind('h');
|
||||||
let symbol_hash = symbol_hash_start.map(|i| &symbol_name[i ..])
|
let symbol_hash = symbol_hash_start.map(|i| &symbol_name[i ..])
|
||||||
.unwrap_or("<no hash>");
|
.unwrap_or("<no hash>");
|
||||||
|
|
|
@ -504,12 +504,12 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
|
||||||
span: Span, // Span of the field pattern, e.g. `x: 0`
|
span: Span, // Span of the field pattern, e.g. `x: 0`
|
||||||
def: &'tcx ty::AdtDef, // Definition of the struct or enum
|
def: &'tcx ty::AdtDef, // Definition of the struct or enum
|
||||||
field: &'tcx ty::FieldDef) { // Definition of the field
|
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;
|
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) {
|
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",
|
struct_span_err!(self.tcx.sess, span, E0451, "field `{}` of {} `{}` is private",
|
||||||
field.name, def.variant_descr(), self.tcx.item_path_str(def.did))
|
field.ident, def.variant_descr(), self.tcx.item_path_str(def.did))
|
||||||
.span_label(span, format!("field `{}` is private", field.name))
|
.span_label(span, format!("field `{}` is private", field.ident))
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,14 +580,14 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
|
||||||
self.tcx.field_index(f.id, self.tables) == vf_index
|
self.tcx.field_index(f.id, self.tables) == vf_index
|
||||||
});
|
});
|
||||||
let (use_ctxt, span) = match field {
|
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),
|
None => (base.span, base.span),
|
||||||
};
|
};
|
||||||
self.check_field(use_ctxt, span, adt, variant_field);
|
self.check_field(use_ctxt, span, adt, variant_field);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for field in fields {
|
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);
|
let index = self.tcx.field_index(field.id, self.tables);
|
||||||
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
|
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 adt = self.tables.pat_ty(pat).ty_adt_def().unwrap();
|
||||||
let variant = adt.variant_of_def(def);
|
let variant = adt.variant_of_def(def);
|
||||||
for field in fields {
|
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);
|
let index = self.tcx.field_index(field.node.id, self.tables);
|
||||||
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
|
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1060,7 +1060,7 @@ impl<'a> ModuleData<'a> {
|
||||||
fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
|
fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
|
||||||
let resolutions = self.resolutions.borrow();
|
let resolutions = self.resolutions.borrow();
|
||||||
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
|
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
|
||||||
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.name.as_str(), ns));
|
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.as_str(), ns));
|
||||||
for &(&(ident, ns), &resolution) in resolutions.iter() {
|
for &(&(ident, ns), &resolution) in resolutions.iter() {
|
||||||
resolution.borrow().binding.map(|binding| f(ident, ns, binding));
|
resolution.borrow().binding.map(|binding| f(ident, ns, binding));
|
||||||
}
|
}
|
||||||
|
@ -2608,7 +2608,7 @@ impl<'a> Resolver<'a> {
|
||||||
self,
|
self,
|
||||||
ident.span,
|
ident.span,
|
||||||
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(
|
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(
|
||||||
&ident.name.as_str())
|
&ident.as_str())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Some(..) if pat_src == PatternSource::FnParam => {
|
Some(..) if pat_src == PatternSource::FnParam => {
|
||||||
|
@ -2617,7 +2617,7 @@ impl<'a> Resolver<'a> {
|
||||||
self,
|
self,
|
||||||
ident.span,
|
ident.span,
|
||||||
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(
|
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(
|
||||||
&ident.name.as_str())
|
&ident.as_str())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Some(..) if pat_src == PatternSource::Match ||
|
Some(..) if pat_src == PatternSource::Match ||
|
||||||
|
@ -3765,12 +3765,12 @@ impl<'a> Resolver<'a> {
|
||||||
// the closest match
|
// the closest match
|
||||||
let close_match = self.search_label(label.ident, |rib, ident| {
|
let close_match = self.search_label(label.ident, |rib, ident| {
|
||||||
let names = rib.bindings.iter().map(|(id, _)| &id.name);
|
let names = rib.bindings.iter().map(|(id, _)| &id.name);
|
||||||
find_best_match_for_name(names, &*ident.name.as_str(), None)
|
find_best_match_for_name(names, &*ident.as_str(), None)
|
||||||
});
|
});
|
||||||
self.record_def(expr.id, err_path_resolution());
|
self.record_def(expr.id, err_path_resolution());
|
||||||
resolve_error(self,
|
resolve_error(self,
|
||||||
label.ident.span,
|
label.ident.span,
|
||||||
ResolutionError::UndeclaredLabel(&label.ident.name.as_str(),
|
ResolutionError::UndeclaredLabel(&label.ident.as_str(),
|
||||||
close_match));
|
close_match));
|
||||||
}
|
}
|
||||||
Some(Def::Label(id)) => {
|
Some(Def::Label(id)) => {
|
||||||
|
@ -4380,7 +4380,7 @@ fn names_to_string(idents: &[Ident]) -> String {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
result.push_str("::");
|
result.push_str("::");
|
||||||
}
|
}
|
||||||
result.push_str(&ident.name.as_str());
|
result.push_str(&ident.as_str());
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -649,7 +649,7 @@ impl<'a> Resolver<'a> {
|
||||||
format!("cannot find derive macro `{}` in this scope", ident),
|
format!("cannot find derive macro `{}` in this scope", ident),
|
||||||
};
|
};
|
||||||
let mut err = self.session.struct_span_err(span, &msg);
|
let mut err = self.session.struct_span_err(span, &msg);
|
||||||
self.suggest_macro_name(&ident.name.as_str(), kind, &mut err, span);
|
self.suggest_macro_name(&ident.as_str(), kind, &mut err, span);
|
||||||
err.emit();
|
err.emit();
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
|
@ -831,7 +831,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let lev_suggestion =
|
let lev_suggestion =
|
||||||
match find_best_match_for_name(names, &ident.name.as_str(), None) {
|
match find_best_match_for_name(names, &ident.as_str(), None) {
|
||||||
Some(name) => format!(". Did you mean to use `{}`?", name),
|
Some(name) => format!(". Did you mean to use `{}`?", name),
|
||||||
None => "".to_owned(),
|
None => "".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -557,7 +557,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||||
binding.item_name, binding.span)
|
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| {
|
let assoc_ty = tcx.associated_items(candidate.def_id()).find(|i| {
|
||||||
i.kind == ty::AssociatedKind::Type && i.name.to_ident() == assoc_ident
|
i.kind == ty::AssociatedKind::Type && i.name.to_ident() == assoc_ident
|
||||||
}).expect("missing associated type");
|
}).expect("missing associated type");
|
||||||
|
@ -907,7 +908,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||||
};
|
};
|
||||||
|
|
||||||
let trait_did = bound.def_id();
|
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| {
|
let item = tcx.associated_items(trait_did).find(|i| {
|
||||||
Namespace::from(i.kind) == Namespace::Type &&
|
Namespace::from(i.kind) == Namespace::Type &&
|
||||||
i.name.to_ident() == assoc_ident
|
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
|
let field_map = variant.fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, field)| (field.name.to_ident(), (i, field)))
|
.map(|(i, field)| (field.ident.modern(), (i, field)))
|
||||||
.collect::<FxHashMap<_, _>>();
|
.collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
// Keep track of which fields have already appeared in the pattern.
|
// 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![];
|
let mut inexistent_fields = vec![];
|
||||||
// Typecheck each field.
|
// Typecheck each field.
|
||||||
for &Spanned { node: ref field, span } in fields {
|
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) {
|
let field_ty = match used_fields.entry(ident) {
|
||||||
Occupied(occupied) => {
|
Occupied(occupied) => {
|
||||||
struct_span_err!(tcx.sess, span, E0025,
|
struct_span_err!(tcx.sess, span, E0025,
|
||||||
"field `{}` bound multiple times \
|
"field `{}` bound multiple times \
|
||||||
in the pattern",
|
in the pattern",
|
||||||
field.name)
|
field.ident)
|
||||||
.span_label(span,
|
.span_label(span,
|
||||||
format!("multiple uses of `{}` in pattern", field.name))
|
format!("multiple uses of `{}` in pattern", field.ident))
|
||||||
.span_label(*occupied.get(), format!("first use of `{}`", field.name))
|
.span_label(*occupied.get(), format!("first use of `{}`", field.ident))
|
||||||
.emit();
|
.emit();
|
||||||
tcx.types.err
|
tcx.types.err
|
||||||
}
|
}
|
||||||
|
@ -890,7 +890,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||||
self.field_ty(span, f, substs)
|
self.field_ty(span, f, substs)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
inexistent_fields.push((span, field.name));
|
inexistent_fields.push((span, field.ident));
|
||||||
tcx.types.err
|
tcx.types.err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -958,7 +958,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
||||||
} else if !etc {
|
} else if !etc {
|
||||||
let unmentioned_fields = variant.fields
|
let unmentioned_fields = variant.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| field.name.to_ident())
|
.map(|field| field.ident.modern())
|
||||||
.filter(|ident| !used_fields.contains_key(&ident))
|
.filter(|ident| !used_fields.contains_key(&ident))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
if unmentioned_fields.len() > 0 {
|
if unmentioned_fields.len() > 0 {
|
||||||
|
|
|
@ -114,15 +114,15 @@ pub enum CandidateSource {
|
||||||
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
/// Determines whether the type `self_ty` supports a method name `method_name` or not.
|
/// Determines whether the type `self_ty` supports a method name `method_name` or not.
|
||||||
pub fn method_exists(&self,
|
pub fn method_exists(&self,
|
||||||
span: Span,
|
method_name: ast::Ident,
|
||||||
method_name: ast::Name,
|
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
call_expr_id: ast::NodeId,
|
call_expr_id: ast::NodeId,
|
||||||
allow_private: bool)
|
allow_private: bool)
|
||||||
-> bool {
|
-> bool {
|
||||||
let mode = probe::Mode::MethodCall;
|
let mode = probe::Mode::MethodCall;
|
||||||
match self.probe_for_name(span, mode, method_name, IsSuggestion(false),
|
match self.probe_for_name(method_name.span, mode, method_name.name,
|
||||||
self_ty, call_expr_id, ProbeScope::TraitsInScope) {
|
IsSuggestion(false), self_ty, call_expr_id,
|
||||||
|
ProbeScope::TraitsInScope) {
|
||||||
Ok(..) => true,
|
Ok(..) => true,
|
||||||
Err(NoMatch(..)) => false,
|
Err(NoMatch(..)) => false,
|
||||||
Err(Ambiguity(..)) => true,
|
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 is_accessible = if let Some(name) = self.method_name {
|
||||||
let item = candidate.item;
|
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)
|
item.vis.is_accessible_from(def_scope, self.tcx)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
|
|
@ -120,7 +120,7 @@ use std::ops::{self, Deref};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::codemap::{original_sp, Spanned};
|
use syntax::codemap::original_sp;
|
||||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{Symbol, LocalInternedString, keywords};
|
use syntax::symbol::{Symbol, LocalInternedString, keywords};
|
||||||
|
@ -3045,7 +3045,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
expr: &'gcx hir::Expr,
|
expr: &'gcx hir::Expr,
|
||||||
needs: Needs,
|
needs: Needs,
|
||||||
base: &'gcx hir::Expr,
|
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.check_expr_with_needs(base, needs);
|
||||||
let expr_t = self.structurally_resolved_type(base.span,
|
let expr_t = self.structurally_resolved_type(base.span,
|
||||||
expr_t);
|
expr_t);
|
||||||
|
@ -3056,9 +3056,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ty::TyAdt(base_def, substs) if !base_def.is_enum() => {
|
ty::TyAdt(base_def, substs) if !base_def.is_enum() => {
|
||||||
debug!("struct named {:?}", base_t);
|
debug!("struct named {:?}", base_t);
|
||||||
let (ident, def_scope) =
|
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;
|
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 = &fields[index];
|
||||||
let field_ty = self.field_ty(expr.span, field, substs);
|
let field_ty = self.field_ty(expr.span, field, substs);
|
||||||
// Save the index of all fields regardless of their visibility in case
|
// 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) => {
|
ty::TyTuple(ref tys) => {
|
||||||
let fstr = field.node.as_str();
|
let fstr = field.as_str();
|
||||||
if let Ok(index) = fstr.parse::<usize>() {
|
if let Ok(index) = fstr.parse::<usize>() {
|
||||||
if fstr == index.to_string() {
|
if fstr == index.to_string() {
|
||||||
if let Some(field_ty) = tys.get(index) {
|
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 struct_path = self.tcx().item_path_str(did);
|
||||||
let mut err = struct_span_err!(self.tcx().sess, expr.span, E0616,
|
let mut err = struct_span_err!(self.tcx().sess, expr.span, E0616,
|
||||||
"field `{}` of struct `{}` is private",
|
"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.
|
// 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) {
|
if self.method_exists(field, expr_t, expr.id, false) {
|
||||||
err.note(&format!("a method `{}` also exists, perhaps you wish to call it",
|
err.note(&format!("a method `{}` also exists, perhaps you wish to call it", field));
|
||||||
field.node));
|
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
field_ty
|
field_ty
|
||||||
} else if field.node == keywords::Invalid.name() {
|
} else if field.name == keywords::Invalid.name() {
|
||||||
self.tcx().types.err
|
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,
|
type_error_struct!(self.tcx().sess, field.span, expr_t, E0615,
|
||||||
"attempted to take value of method `{}` on type `{}`",
|
"attempted to take value of method `{}` on type `{}`",
|
||||||
field.node, expr_t)
|
field, expr_t)
|
||||||
.help("maybe a `()` to call it is missing?")
|
.help("maybe a `()` to call it is missing?")
|
||||||
.emit();
|
.emit();
|
||||||
self.tcx().types.err
|
self.tcx().types.err
|
||||||
} else {
|
} else {
|
||||||
if !expr_t.is_primitive_ty() {
|
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 {
|
match expr_t.sty {
|
||||||
ty::TyAdt(def, _) if !def.is_enum() => {
|
ty::TyAdt(def, _) if !def.is_enum() => {
|
||||||
if let Some(suggested_field_name) =
|
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.as_str(), vec![]) {
|
||||||
err.span_label(field.span,
|
err.span_label(field.span,
|
||||||
format!("did you mean `{}`?", suggested_field_name));
|
format!("did you mean `{}`?", suggested_field_name));
|
||||||
} else {
|
} else {
|
||||||
|
@ -3139,7 +3139,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ty::TyRawPtr(..) => {
|
ty::TyRawPtr(..) => {
|
||||||
let base = self.tcx.hir.node_to_pretty_string(base.id);
|
let base = self.tcx.hir.node_to_pretty_string(base.id);
|
||||||
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
|
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);
|
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
|
// Return an hint about the closest match in field names
|
||||||
fn suggest_field_name(variant: &'tcx ty::VariantDef,
|
fn suggest_field_name(variant: &'tcx ty::VariantDef,
|
||||||
field: &Spanned<ast::Name>,
|
field: &str,
|
||||||
skip: Vec<LocalInternedString>)
|
skip: Vec<LocalInternedString>)
|
||||||
-> Option<Symbol> {
|
-> Option<Symbol> {
|
||||||
let name = field.node.as_str();
|
|
||||||
let names = variant.fields.iter().filter_map(|field| {
|
let names = variant.fields.iter().filter_map(|field| {
|
||||||
// ignore already set fields and private fields from non-local crates
|
// 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.as_str()) ||
|
||||||
(variant.did.krate != LOCAL_CRATE && field.vis != Visibility::Public) {
|
(variant.did.krate != LOCAL_CRATE && field.vis != Visibility::Public) {
|
||||||
None
|
None
|
||||||
} else {
|
} 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> {
|
fn available_field_names(&self, variant: &'tcx ty::VariantDef) -> Vec<ast::Name> {
|
||||||
let mut available = Vec::new();
|
let mut available = Vec::new();
|
||||||
for field in variant.fields.iter() {
|
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) {
|
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
||||||
available.push(field.name);
|
available.push(field.ident.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
available
|
available
|
||||||
|
@ -3209,36 +3208,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
skip_fields: &[hir::Field],
|
skip_fields: &[hir::Field],
|
||||||
kind_name: &str) {
|
kind_name: &str) {
|
||||||
let mut err = self.type_error_struct_with_diag(
|
let mut err = self.type_error_struct_with_diag(
|
||||||
field.name.span,
|
field.ident.span,
|
||||||
|actual| match ty.sty {
|
|actual| match ty.sty {
|
||||||
ty::TyAdt(adt, ..) if adt.is_enum() => {
|
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 `{}`",
|
"{} `{}::{}` 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 `{}`",
|
"{} `{}` has no field named `{}`",
|
||||||
kind_name, actual, field.name.node)
|
kind_name, actual, field.ident)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ty);
|
ty);
|
||||||
// prevent all specified fields from being suggested
|
// 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.as_str());
|
||||||
if let Some(field_name) = Self::suggest_field_name(variant,
|
if let Some(field_name) = Self::suggest_field_name(variant,
|
||||||
&field.name,
|
&field.ident.as_str(),
|
||||||
skip_fields.collect()) {
|
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));
|
format!("field does not exist - did you mean `{}`?", field_name));
|
||||||
} else {
|
} else {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
ty::TyAdt(adt, ..) => {
|
ty::TyAdt(adt, ..) => {
|
||||||
if adt.is_enum() {
|
if adt.is_enum() {
|
||||||
err.span_label(field.name.span,
|
err.span_label(field.ident.span,
|
||||||
format!("`{}::{}` does not have this field",
|
format!("`{}::{}` does not have this field",
|
||||||
ty, variant.name));
|
ty, variant.name));
|
||||||
} else {
|
} else {
|
||||||
err.span_label(field.name.span,
|
err.span_label(field.ident.span,
|
||||||
format!("`{}` does not have this field", ty));
|
format!("`{}` does not have this field", ty));
|
||||||
}
|
}
|
||||||
let available_field_names = self.available_field_names(variant);
|
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();
|
let mut remaining_fields = FxHashMap();
|
||||||
for (i, field) in variant.fields.iter().enumerate() {
|
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();
|
let mut seen_fields = FxHashMap();
|
||||||
|
@ -3287,7 +3286,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
// Typecheck each field.
|
// Typecheck each field.
|
||||||
for field in ast_fields {
|
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) {
|
let field_type = if let Some((i, v_field)) = remaining_fields.remove(&ident) {
|
||||||
seen_fields.insert(ident, field.span);
|
seen_fields.insert(ident, field.span);
|
||||||
self.write_field_index(field.id, i);
|
self.write_field_index(field.id, i);
|
||||||
|
@ -3304,12 +3303,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
error_happened = true;
|
error_happened = true;
|
||||||
if let Some(prev_span) = seen_fields.get(&ident) {
|
if let Some(prev_span) = seen_fields.get(&ident) {
|
||||||
let mut err = struct_span_err!(self.tcx.sess,
|
let mut err = struct_span_err!(self.tcx.sess,
|
||||||
field.name.span,
|
field.ident.span,
|
||||||
E0062,
|
E0062,
|
||||||
"field `{}` specified more than once",
|
"field `{}` specified more than once",
|
||||||
ident);
|
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.span_label(*prev_span, format!("first use of `{}`", ident));
|
||||||
|
|
||||||
err.emit();
|
err.emit();
|
||||||
|
@ -3335,7 +3334,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
let mut displayable_field_names = remaining_fields
|
let mut displayable_field_names = remaining_fields
|
||||||
.keys()
|
.keys()
|
||||||
.map(|ident| ident.name.as_str())
|
.map(|ident| ident.as_str())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
displayable_field_names.sort();
|
displayable_field_names.sort();
|
||||||
|
@ -4057,7 +4056,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
hir::ExprStruct(ref qpath, ref fields, ref base_expr) => {
|
hir::ExprStruct(ref qpath, ref fields, ref base_expr) => {
|
||||||
self.check_expr_struct(expr, expected, qpath, fields, 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)
|
self.check_field(expr, needs, &base, field)
|
||||||
}
|
}
|
||||||
hir::ExprIndex(ref base, ref idx) => {
|
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.len(),
|
||||||
diff_fields.iter()
|
diff_fields.iter()
|
||||||
.map(|&(i, a, b)| {
|
.map(|&(i, a, b)| {
|
||||||
format!("{} ({} to {})", fields[i].name, a, b)
|
format!("{} ({} to {})", fields[i].ident, a, b)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ")));
|
.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 node_id = tcx.hir.as_local_node_id(did).unwrap();
|
||||||
let fields = def.fields().iter().map(|f| {
|
let fields = def.fields().iter().map(|f| {
|
||||||
let fid = tcx.hir.local_def_id(f.id);
|
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 {
|
if let Some(prev_span) = dup_span {
|
||||||
struct_span_err!(tcx.sess, f.span, E0124,
|
struct_span_err!(tcx.sess, f.span, E0124,
|
||||||
"field `{}` is already declared",
|
"field `{}` is already declared",
|
||||||
f.name)
|
f.ident)
|
||||||
.span_label(f.span, "field already declared")
|
.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();
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
seen_fields.insert(f.name.to_ident(), f.span);
|
seen_fields.insert(f.ident.modern(), f.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::FieldDef {
|
ty::FieldDef {
|
||||||
did: fid,
|
did: fid,
|
||||||
name: f.name,
|
ident: f.ident,
|
||||||
vis: ty::Visibility::from_hir(&f.vis, node_id, tcx)
|
vis: ty::Visibility::from_hir(&f.vis, node_id, tcx)
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
|
@ -1091,19 +1091,19 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
let elem = if is_enum {
|
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 {
|
} else {
|
||||||
cx.tcx.adt_def(did)
|
cx.tcx.adt_def(did)
|
||||||
.non_enum_variant()
|
.non_enum_variant()
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.find(|item| item.name == item_name)
|
.find(|item| item.ident.name == item_name)
|
||||||
};
|
};
|
||||||
if let Some(item) = elem {
|
if let Some(item) = elem {
|
||||||
Ok((ty.def,
|
Ok((ty.def,
|
||||||
Some(format!("{}.{}",
|
Some(format!("{}.{}",
|
||||||
if is_enum { "variant" } else { "structfield" },
|
if is_enum { "variant" } else { "structfield" },
|
||||||
item.name))))
|
item.ident))))
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
@ -2990,7 +2990,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||||
impl Clean<Item> for hir::StructField {
|
impl Clean<Item> for hir::StructField {
|
||||||
fn clean(&self, cx: &DocContext) -> Item {
|
fn clean(&self, cx: &DocContext) -> Item {
|
||||||
Item {
|
Item {
|
||||||
name: Some(self.name).clean(cx),
|
name: Some(self.ident.name).clean(cx),
|
||||||
attrs: self.attrs.clean(cx),
|
attrs: self.attrs.clean(cx),
|
||||||
source: self.span.clean(cx),
|
source: self.span.clean(cx),
|
||||||
visibility: self.vis.clean(cx),
|
visibility: self.vis.clean(cx),
|
||||||
|
@ -3005,7 +3005,7 @@ impl Clean<Item> for hir::StructField {
|
||||||
impl<'tcx> Clean<Item> for ty::FieldDef {
|
impl<'tcx> Clean<Item> for ty::FieldDef {
|
||||||
fn clean(&self, cx: &DocContext) -> Item {
|
fn clean(&self, cx: &DocContext) -> Item {
|
||||||
Item {
|
Item {
|
||||||
name: Some(self.name).clean(cx),
|
name: Some(self.ident.name).clean(cx),
|
||||||
attrs: cx.tcx.get_attrs(self.did).clean(cx),
|
attrs: cx.tcx.get_attrs(self.did).clean(cx),
|
||||||
source: cx.tcx.def_span(self.did).clean(cx),
|
source: cx.tcx.def_span(self.did).clean(cx),
|
||||||
visibility: self.vis.clean(cx),
|
visibility: self.vis.clean(cx),
|
||||||
|
@ -3201,7 +3201,7 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
|
||||||
fields: self.fields.iter().map(|field| {
|
fields: self.fields.iter().map(|field| {
|
||||||
Item {
|
Item {
|
||||||
source: cx.tcx.def_span(field.did).clean(cx),
|
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),
|
attrs: cx.tcx.get_attrs(field.did).clean(cx),
|
||||||
visibility: field.vis.clean(cx),
|
visibility: field.vis.clean(cx),
|
||||||
def_id: field.did,
|
def_id: field.did,
|
||||||
|
@ -3850,7 +3850,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
|
||||||
PatKind::Struct(ref name, ref fields, etc) => {
|
PatKind::Struct(ref name, ref fields, etc) => {
|
||||||
format!("{} {{ {}{} }}", qpath_to_string(name),
|
format!("{} {{ {}{} }}", qpath_to_string(name),
|
||||||
fields.iter().map(|&Spanned { node: ref fp, .. }|
|
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(", "),
|
.collect::<Vec<String>>().join(", "),
|
||||||
if etc { ", ..." } else { "" }
|
if etc { ", ..." } else { "" }
|
||||||
)
|
)
|
||||||
|
|
|
@ -324,7 +324,7 @@ impl<'a> Classifier<'a> {
|
||||||
|
|
||||||
// Keywords are also included in the identifier set.
|
// Keywords are also included in the identifier set.
|
||||||
token::Ident(ident, is_raw) => {
|
token::Ident(ident, is_raw) => {
|
||||||
match &*ident.name.as_str() {
|
match &*ident.as_str() {
|
||||||
"ref" | "mut" if !is_raw => Class::RefKeyWord,
|
"ref" | "mut" if !is_raw => Class::RefKeyWord,
|
||||||
|
|
||||||
"self" | "Self" => Class::Self_,
|
"self" | "Self" => Class::Self_,
|
||||||
|
|
|
@ -743,7 +743,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_struct_field(&mut self, f: &'hir hir::StructField) {
|
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);
|
intravisit::walk_struct_field(this, f);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
|
||||||
ecx.parse_sess.registered_diagnostics.with_lock(|diagnostics| {
|
ecx.parse_sess.registered_diagnostics.with_lock(|diagnostics| {
|
||||||
if let Err(e) = output_metadata(ecx,
|
if let Err(e) = output_metadata(ecx,
|
||||||
&target_triple,
|
&target_triple,
|
||||||
&crate_name.name.as_str(),
|
&crate_name.as_str(),
|
||||||
diagnostics) {
|
diagnostics) {
|
||||||
ecx.span_bug(span, &format!(
|
ecx.span_bug(span, &format!(
|
||||||
"error writing metadata for triple `{}` and crate `{}`, error: {}, \
|
"error writing metadata for triple `{}` and crate `{}`, error: {}, \
|
||||||
|
|
|
@ -178,7 +178,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat {
|
||||||
if segment.ident.name != keywords::CrateRoot.name() &&
|
if segment.ident.name != keywords::CrateRoot.name() &&
|
||||||
segment.ident.name != keywords::DollarCrate.name()
|
segment.ident.name != keywords::DollarCrate.name()
|
||||||
{
|
{
|
||||||
path_str.push_str(&segment.ident.name.as_str())
|
path_str.push_str(&segment.ident.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,7 +1266,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
|
||||||
DirectoryOwnership::Owned { relative: None };
|
DirectoryOwnership::Owned { relative: None };
|
||||||
module.directory.push(&*path.as_str());
|
module.directory.push(&*path.as_str());
|
||||||
} else {
|
} else {
|
||||||
module.directory.push(&*item.ident.name.as_str());
|
module.directory.push(&*item.ident.as_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let path = self.cx.parse_sess.codemap().span_to_unmapped_path(inner);
|
let path = self.cx.parse_sess.codemap().span_to_unmapped_path(inner);
|
||||||
|
|
|
@ -573,7 +573,7 @@ fn inner_parse_loop<'a>(
|
||||||
TokenTree::MetaVarDecl(_, _, id) => {
|
TokenTree::MetaVarDecl(_, _, id) => {
|
||||||
// Built-in nonterminals never start with these tokens,
|
// Built-in nonterminals never start with these tokens,
|
||||||
// so we can eliminate them from consideration.
|
// so we can eliminate them from consideration.
|
||||||
if may_begin_with(&*id.name.as_str(), token) {
|
if may_begin_with(&*id.as_str(), token) {
|
||||||
bb_items.push(item);
|
bb_items.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,7 +742,7 @@ pub fn parse(
|
||||||
let match_cur = item.match_cur;
|
let match_cur = item.match_cur;
|
||||||
item.push_match(
|
item.push_match(
|
||||||
match_cur,
|
match_cur,
|
||||||
MatchedNonterminal(Rc::new(parse_nt(&mut parser, span, &ident.name.as_str()))),
|
MatchedNonterminal(Rc::new(parse_nt(&mut parser, span, &ident.as_str()))),
|
||||||
);
|
);
|
||||||
item.idx += 1;
|
item.idx += 1;
|
||||||
item.match_cur += 1;
|
item.match_cur += 1;
|
||||||
|
|
|
@ -148,7 +148,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
};
|
};
|
||||||
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false);
|
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false);
|
||||||
p.root_module_name = cx.current_expansion.module.mod_path.last()
|
p.root_module_name = cx.current_expansion.module.mod_path.last()
|
||||||
.map(|id| id.name.as_str().to_string());
|
.map(|id| id.as_str().to_string());
|
||||||
|
|
||||||
p.process_potential_macro_variable();
|
p.process_potential_macro_variable();
|
||||||
// Let the context choose how to interpret the result.
|
// Let the context choose how to interpret the result.
|
||||||
|
@ -730,7 +730,7 @@ fn check_matcher_core(sess: &ParseSess,
|
||||||
'each_last: for token in &last.tokens {
|
'each_last: for token in &last.tokens {
|
||||||
if let TokenTree::MetaVarDecl(_, ref name, ref frag_spec) = *token {
|
if let TokenTree::MetaVarDecl(_, ref name, ref frag_spec) = *token {
|
||||||
for next_token in &suffix_first.tokens {
|
for next_token in &suffix_first.tokens {
|
||||||
match is_in_follow(next_token, &frag_spec.name.as_str()) {
|
match is_in_follow(next_token, &frag_spec.as_str()) {
|
||||||
Err((msg, help)) => {
|
Err((msg, help)) => {
|
||||||
sess.span_diagnostic.struct_span_err(next_token.span(), &msg)
|
sess.span_diagnostic.struct_span_err(next_token.span(), &msg)
|
||||||
.help(help).emit();
|
.help(help).emit();
|
||||||
|
@ -768,7 +768,7 @@ fn check_matcher_core(sess: &ParseSess,
|
||||||
|
|
||||||
fn token_can_be_followed_by_any(tok: "ed::TokenTree) -> bool {
|
fn token_can_be_followed_by_any(tok: "ed::TokenTree) -> bool {
|
||||||
if let quoted::TokenTree::MetaVarDecl(_, _, frag_spec) = *tok {
|
if let quoted::TokenTree::MetaVarDecl(_, _, frag_spec) = *tok {
|
||||||
frag_can_be_followed_by_any(&frag_spec.name.as_str())
|
frag_can_be_followed_by_any(&frag_spec.as_str())
|
||||||
} else {
|
} else {
|
||||||
// (Non NT's can always be followed by anthing in matchers.)
|
// (Non NT's can always be followed by anthing in matchers.)
|
||||||
true
|
true
|
||||||
|
@ -893,7 +893,7 @@ fn has_legal_fragment_specifier(sess: &ParseSess,
|
||||||
tok: "ed::TokenTree) -> Result<(), String> {
|
tok: "ed::TokenTree) -> Result<(), String> {
|
||||||
debug!("has_legal_fragment_specifier({:?})", tok);
|
debug!("has_legal_fragment_specifier({:?})", tok);
|
||||||
if let quoted::TokenTree::MetaVarDecl(_, _, ref frag_spec) = *tok {
|
if let quoted::TokenTree::MetaVarDecl(_, _, ref frag_spec) = *tok {
|
||||||
let frag_name = frag_spec.name.as_str();
|
let frag_name = frag_spec.as_str();
|
||||||
let frag_span = tok.span();
|
let frag_span = tok.span();
|
||||||
if !is_legal_fragment_specifier(sess, features, attrs, &frag_name, frag_span) {
|
if !is_legal_fragment_specifier(sess, features, attrs, &frag_name, frag_span) {
|
||||||
return Err(frag_name.to_string());
|
return Err(frag_name.to_string());
|
||||||
|
|
|
@ -6067,7 +6067,7 @@ impl<'a> Parser<'a> {
|
||||||
self.directory.path.to_mut().push(&path.as_str());
|
self.directory.path.to_mut().push(&path.as_str());
|
||||||
self.directory.ownership = DirectoryOwnership::Owned { relative: None };
|
self.directory.ownership = DirectoryOwnership::Owned { relative: None };
|
||||||
} else {
|
} else {
|
||||||
self.directory.path.to_mut().push(&id.name.as_str());
|
self.directory.path.to_mut().push(&id.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6088,7 +6088,7 @@ impl<'a> Parser<'a> {
|
||||||
// `./<id>.rs` and `./<id>/mod.rs`.
|
// `./<id>.rs` and `./<id>/mod.rs`.
|
||||||
let relative_prefix_string;
|
let relative_prefix_string;
|
||||||
let relative_prefix = if let Some(ident) = relative {
|
let relative_prefix = if let Some(ident) = relative {
|
||||||
relative_prefix_string = format!("{}{}", ident.name.as_str(), path::MAIN_SEPARATOR);
|
relative_prefix_string = format!("{}{}", ident.as_str(), path::MAIN_SEPARATOR);
|
||||||
&relative_prefix_string
|
&relative_prefix_string
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
|
|
@ -341,7 +341,7 @@ impl Token {
|
||||||
/// string slice.
|
/// string slice.
|
||||||
pub fn is_ident_named(&self, name: &str) -> bool {
|
pub fn is_ident_named(&self, name: &str) -> bool {
|
||||||
match self.ident() {
|
match self.ident() {
|
||||||
Some((ident, _)) => ident.name.as_str() == name,
|
Some((ident, _)) => ident.as_str() == name,
|
||||||
None => false
|
None => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -724,7 +724,7 @@ pub trait PrintState<'a> {
|
||||||
if segment.ident.name != keywords::CrateRoot.name() &&
|
if segment.ident.name != keywords::CrateRoot.name() &&
|
||||||
segment.ident.name != keywords::DollarCrate.name()
|
segment.ident.name != keywords::DollarCrate.name()
|
||||||
{
|
{
|
||||||
self.writer().word(&segment.ident.name.as_str())?;
|
self.writer().word(&segment.ident.as_str())?;
|
||||||
} else if segment.ident.name == keywords::DollarCrate.name() {
|
} else if segment.ident.name == keywords::DollarCrate.name() {
|
||||||
self.print_dollar_crate(segment.ident.span.ctxt())?;
|
self.print_dollar_crate(segment.ident.span.ctxt())?;
|
||||||
}
|
}
|
||||||
|
@ -2380,7 +2380,7 @@ impl<'a> State<'a> {
|
||||||
if ident.is_raw_guess() {
|
if ident.is_raw_guess() {
|
||||||
self.s.word(&format!("r#{}", ident))?;
|
self.s.word(&format!("r#{}", ident))?;
|
||||||
} else {
|
} else {
|
||||||
self.s.word(&ident.name.as_str())?;
|
self.s.word(&ident.as_str())?;
|
||||||
}
|
}
|
||||||
self.ann.post(self, NodeIdent(&ident))
|
self.ann.post(self, NodeIdent(&ident))
|
||||||
}
|
}
|
||||||
|
|
|
@ -647,7 +647,7 @@ fn path_name_i(idents: &[Ident]) -> String {
|
||||||
let mut path_name = "".to_string();
|
let mut path_name = "".to_string();
|
||||||
let mut idents_iter = idents.iter().peekable();
|
let mut idents_iter = idents.iter().peekable();
|
||||||
while let Some(ident) = idents_iter.next() {
|
while let Some(ident) = idents_iter.next() {
|
||||||
path_name.push_str(&ident.name.as_str());
|
path_name.push_str(&ident.as_str());
|
||||||
if let Some(_) = idents_iter.peek() {
|
if let Some(_) = idents_iter.peek() {
|
||||||
path_name.push_str("::")
|
path_name.push_str("::")
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
} else {
|
} else {
|
||||||
match *e {
|
match *e {
|
||||||
TokenTree::Token(_, token::Ident(ident, _)) =>
|
TokenTree::Token(_, token::Ident(ident, _)) =>
|
||||||
res_str.push_str(&ident.name.as_str()),
|
res_str.push_str(&ident.as_str()),
|
||||||
_ => {
|
_ => {
|
||||||
cx.span_err(sp, "concat_idents! requires ident args.");
|
cx.span_err(sp, "concat_idents! requires ident args.");
|
||||||
return DummyResult::expr(sp);
|
return DummyResult::expr(sp);
|
||||||
|
|
|
@ -136,7 +136,7 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String {
|
||||||
ast::ItemKind::Enum(_, ast::Generics { ref params, .. }) => {
|
ast::ItemKind::Enum(_, ast::Generics { ref params, .. }) => {
|
||||||
for param in params.iter() {
|
for param in params.iter() {
|
||||||
if let ast::GenericParam::Type(ref ty) = *param{
|
if let ast::GenericParam::Type(ref ty) = *param{
|
||||||
typaram.push_str(&ty.ident.name.as_str());
|
typaram.push_str(&ty.ident.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ fn parse_args(ecx: &mut ExtCtxt,
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let name: &str = &ident.name.as_str();
|
let name: &str = &ident.as_str();
|
||||||
|
|
||||||
panictry!(p.expect(&token::Eq));
|
panictry!(p.expect(&token::Eq));
|
||||||
let e = panictry!(p.parse_expr());
|
let e = panictry!(p.parse_expr());
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl Ident {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn without_first_quote(self) -> Ident {
|
pub fn without_first_quote(self) -> Ident {
|
||||||
Ident::new(Symbol::intern(self.name.as_str().trim_left_matches('\'')), self.span)
|
Ident::new(Symbol::intern(self.as_str().trim_left_matches('\'')), self.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn modern(self) -> Ident {
|
pub fn modern(self) -> Ident {
|
||||||
|
@ -66,6 +66,10 @@ impl Ident {
|
||||||
pub fn gensym(self) -> Ident {
|
pub fn gensym(self) -> Ident {
|
||||||
Ident::new(self.name.gensymed(), self.span)
|
Ident::new(self.name.gensymed(), self.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_str(self) -> LocalInternedString {
|
||||||
|
self.name.as_str()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Ident {
|
impl PartialEq for Ident {
|
||||||
|
@ -96,10 +100,10 @@ impl fmt::Display for Ident {
|
||||||
impl Encodable for Ident {
|
impl Encodable for Ident {
|
||||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||||
if self.span.ctxt().modern() == SyntaxContext::empty() {
|
if self.span.ctxt().modern() == SyntaxContext::empty() {
|
||||||
s.emit_str(&self.name.as_str())
|
s.emit_str(&self.as_str())
|
||||||
} else { // FIXME(jseyfried) intercrate hygiene
|
} else { // FIXME(jseyfried) intercrate hygiene
|
||||||
let mut string = "#".to_owned();
|
let mut string = "#".to_owned();
|
||||||
string.push_str(&self.name.as_str());
|
string.push_str(&self.as_str());
|
||||||
s.emit_str(&string)
|
s.emit_str(&string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue