Use Idents for associated item definitions in HIR

Remove emulation of hygiene with gensyms
This commit is contained in:
Vadim Petrochenkov 2018-06-10 22:24:24 +03:00
parent c6ca1e4abd
commit f0622dfe5d
45 changed files with 176 additions and 207 deletions

View File

@ -57,7 +57,7 @@ pub enum FnKind<'a> {
ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]), ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
/// fn foo(&self) /// fn foo(&self)
Method(Name, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]), Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
/// |x, y| {} /// |x, y| {}
Closure(&'a [Attribute]), Closure(&'a [Attribute]),
@ -823,7 +823,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
} }
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) { pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) {
visitor.visit_name(trait_item.span, trait_item.name); visitor.visit_ident(trait_item.ident);
walk_list!(visitor, visit_attribute, &trait_item.attrs); walk_list!(visitor, visit_attribute, &trait_item.attrs);
visitor.visit_generics(&trait_item.generics); visitor.visit_generics(&trait_item.generics);
match trait_item.node { match trait_item.node {
@ -840,7 +840,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
} }
} }
TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => { TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => {
visitor.visit_fn(FnKind::Method(trait_item.name, visitor.visit_fn(FnKind::Method(trait_item.ident,
sig, sig,
None, None,
&trait_item.attrs), &trait_item.attrs),
@ -859,9 +859,9 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) { pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) {
// NB: Deliberately force a compilation error if/when new fields are added. // NB: Deliberately force a compilation error if/when new fields are added.
let TraitItemRef { id, name, ref kind, span, ref defaultness } = *trait_item_ref; let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref;
visitor.visit_nested_trait_item(id); visitor.visit_nested_trait_item(id);
visitor.visit_name(span, name); visitor.visit_ident(ident);
visitor.visit_associated_item_kind(kind); visitor.visit_associated_item_kind(kind);
visitor.visit_defaultness(defaultness); visitor.visit_defaultness(defaultness);
} }
@ -871,16 +871,16 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
let ImplItem { let ImplItem {
id: _, id: _,
hir_id: _, hir_id: _,
name, ident,
ref vis, ref vis,
ref defaultness, ref defaultness,
ref attrs, ref attrs,
ref generics, ref generics,
ref node, ref node,
span span: _,
} = *impl_item; } = *impl_item;
visitor.visit_name(span, name); visitor.visit_ident(ident);
visitor.visit_vis(vis); visitor.visit_vis(vis);
visitor.visit_defaultness(defaultness); visitor.visit_defaultness(defaultness);
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
@ -892,7 +892,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_nested_body(body); visitor.visit_nested_body(body);
} }
ImplItemKind::Method(ref sig, body_id) => { ImplItemKind::Method(ref sig, body_id) => {
visitor.visit_fn(FnKind::Method(impl_item.name, visitor.visit_fn(FnKind::Method(impl_item.ident,
sig, sig,
Some(&impl_item.vis), Some(&impl_item.vis),
&impl_item.attrs), &impl_item.attrs),
@ -910,9 +910,9 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) { pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
// NB: Deliberately force a compilation error if/when new fields are added. // NB: Deliberately force a compilation error if/when new fields are added.
let ImplItemRef { id, name, ref kind, span, ref vis, ref defaultness } = *impl_item_ref; let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref;
visitor.visit_nested_impl_item(id); visitor.visit_nested_impl_item(id);
visitor.visit_name(span, name); visitor.visit_ident(ident);
visitor.visit_associated_item_kind(kind); visitor.visit_associated_item_kind(kind);
visitor.visit_vis(vis); visitor.visit_vis(vis);
visitor.visit_defaultness(defaultness); visitor.visit_defaultness(defaultness);

View File

@ -52,7 +52,7 @@ use middle::cstore::CrateStore;
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
use session::Session; use session::Session;
use util::common::FN_OUTPUT_NAME; use util::common::FN_OUTPUT_NAME;
use util::nodemap::{DefIdMap, FxHashMap, NodeMap}; use util::nodemap::{DefIdMap, NodeMap};
use std::collections::{BTreeMap, HashSet}; use std::collections::{BTreeMap, HashSet};
use std::fmt::Debug; use std::fmt::Debug;
@ -85,7 +85,6 @@ pub struct LoweringContext<'a> {
cstore: &'a CrateStore, cstore: &'a CrateStore,
resolver: &'a mut Resolver, resolver: &'a mut Resolver,
name_map: FxHashMap<Ident, Name>,
/// The items being lowered are collected here. /// The items being lowered are collected here.
items: BTreeMap<NodeId, hir::Item>, items: BTreeMap<NodeId, hir::Item>,
@ -210,7 +209,6 @@ pub fn lower_crate(
sess, sess,
cstore, cstore,
resolver, resolver,
name_map: FxHashMap(),
items: BTreeMap::new(), items: BTreeMap::new(),
trait_items: BTreeMap::new(), trait_items: BTreeMap::new(),
impl_items: BTreeMap::new(), impl_items: BTreeMap::new(),
@ -957,16 +955,6 @@ impl<'a> LoweringContext<'a> {
} }
} }
fn lower_ident(&mut self, ident: Ident) -> Name {
let ident = ident.modern();
if ident.span.ctxt() == SyntaxContext::empty() {
return ident.name;
}
*self.name_map
.entry(ident)
.or_insert_with(|| Symbol::from_ident(ident))
}
fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> { fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
label.map(|label| hir::Label { label.map(|label| hir::Label {
ident: label.ident, ident: label.ident,
@ -2962,7 +2950,7 @@ impl<'a> LoweringContext<'a> {
hir::TraitItem { hir::TraitItem {
id: node_id, id: node_id,
hir_id, hir_id,
name: self.lower_ident(i.ident), ident: i.ident,
attrs: self.lower_attrs(&i.attrs), attrs: self.lower_attrs(&i.attrs),
generics, generics,
node, node,
@ -2988,7 +2976,7 @@ impl<'a> LoweringContext<'a> {
}; };
hir::TraitItemRef { hir::TraitItemRef {
id: hir::TraitItemId { node_id: i.id }, id: hir::TraitItemId { node_id: i.id },
name: self.lower_ident(i.ident), ident: i.ident,
span: i.span, span: i.span,
defaultness: self.lower_defaultness(Defaultness::Default, has_default), defaultness: self.lower_defaultness(Defaultness::Default, has_default),
kind, kind,
@ -3054,7 +3042,7 @@ impl<'a> LoweringContext<'a> {
hir::ImplItem { hir::ImplItem {
id: node_id, id: node_id,
hir_id, hir_id,
name: self.lower_ident(i.ident), ident: i.ident,
attrs: self.lower_attrs(&i.attrs), attrs: self.lower_attrs(&i.attrs),
generics, generics,
vis: self.lower_visibility(&i.vis, None), vis: self.lower_visibility(&i.vis, None),
@ -3069,7 +3057,7 @@ impl<'a> LoweringContext<'a> {
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef { fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
hir::ImplItemRef { hir::ImplItemRef {
id: hir::ImplItemId { node_id: i.id }, id: hir::ImplItemId { node_id: i.id },
name: self.lower_ident(i.ident), ident: i.ident,
span: i.span, span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)), vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */), defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),

View File

@ -25,7 +25,7 @@ use hir as ast;
use hir::map::{self, Node}; use hir::map::{self, Node};
use hir::{Expr, FnDecl}; use hir::{Expr, FnDecl};
use hir::intravisit::FnKind; use hir::intravisit::FnKind;
use syntax::ast::{Attribute, Name, NodeId}; use syntax::ast::{Attribute, Ident, Name, NodeId};
use syntax_pos::Span; use syntax_pos::Span;
/// An FnLikeNode is a Node that is like a fn, in that it has a decl /// An FnLikeNode is a Node that is like a fn, in that it has a decl
@ -209,8 +209,8 @@ impl<'a> FnLikeNode<'a> {
let closure = |c: ClosureParts<'a>| { let closure = |c: ClosureParts<'a>| {
FnKind::Closure(c.attrs) FnKind::Closure(c.attrs)
}; };
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _, attrs| { let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
FnKind::Method(name, sig, vis, attrs) FnKind::Method(ident, sig, vis, attrs)
}; };
self.handle(item, method, closure) self.handle(item, method, closure)
} }
@ -218,7 +218,7 @@ impl<'a> FnLikeNode<'a> {
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
I: FnOnce(ItemFnParts<'a>) -> A, I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(NodeId, M: FnOnce(NodeId,
Name, Ident,
&'a ast::MethodSig, &'a ast::MethodSig,
Option<&'a ast::Visibility>, Option<&'a ast::Visibility>,
ast::BodyId, ast::BodyId,
@ -245,14 +245,14 @@ impl<'a> FnLikeNode<'a> {
}, },
map::NodeTraitItem(ti) => match ti.node { map::NodeTraitItem(ti) => match ti.node {
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => { ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
method(ti.id, ti.name, sig, None, body, ti.span, &ti.attrs) method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
} }
_ => bug!("trait method FnLikeNode that is not fn-like"), _ => bug!("trait method FnLikeNode that is not fn-like"),
}, },
map::NodeImplItem(ii) => { map::NodeImplItem(ii) => {
match ii.node { match ii.node {
ast::ImplItemKind::Method(ref sig, body) => { ast::ImplItemKind::Method(ref sig, body) => {
method(ii.id, ii.name, sig, Some(&ii.vis), body, ii.span, &ii.attrs) method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
} }
_ => { _ => {
bug!("impl method FnLikeNode that is not fn-like") bug!("impl method FnLikeNode that is not fn-like")

View File

@ -495,7 +495,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
// map the actual nodes, not the duplicate ones in the *Ref. // map the actual nodes, not the duplicate ones in the *Ref.
let TraitItemRef { let TraitItemRef {
id, id,
name: _, ident: _,
kind: _, kind: _,
span: _, span: _,
defaultness: _, defaultness: _,
@ -509,7 +509,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
// map the actual nodes, not the duplicate ones in the *Ref. // map the actual nodes, not the duplicate ones in the *Ref.
let ImplItemRef { let ImplItemRef {
id, id,
name: _, ident: _,
kind: _, kind: _,
span: _, span: _,
vis: _, vis: _,

View File

@ -949,8 +949,8 @@ impl<'hir> Map<'hir> {
match self.get(id) { match self.get(id) {
NodeItem(i) => i.name, NodeItem(i) => i.name,
NodeForeignItem(i) => i.name, NodeForeignItem(i) => i.name,
NodeImplItem(ii) => ii.name, NodeImplItem(ii) => ii.ident.name,
NodeTraitItem(ti) => ti.name, NodeTraitItem(ti) => ti.ident.name,
NodeVariant(v) => v.node.name, NodeVariant(v) => v.node.name,
NodeField(f) => f.ident.name, NodeField(f) => f.ident.name,
NodeLifetime(lt) => lt.name.ident().name, NodeLifetime(lt) => lt.name.ident().name,
@ -1149,8 +1149,8 @@ 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.ident.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.ident.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.name } } impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
pub fn map_crate<'hir>(sess: &::session::Session, pub fn map_crate<'hir>(sess: &::session::Session,
@ -1309,13 +1309,13 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
Some(NodeImplItem(ii)) => { Some(NodeImplItem(ii)) => {
match ii.node { match ii.node {
ImplItemKind::Const(..) => { ImplItemKind::Const(..) => {
format!("assoc const {} in {}{}", ii.name, path_str(), id_str) format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
} }
ImplItemKind::Method(..) => { ImplItemKind::Method(..) => {
format!("method {} in {}{}", ii.name, path_str(), id_str) format!("method {} in {}{}", ii.ident, path_str(), id_str)
} }
ImplItemKind::Type(_) => { ImplItemKind::Type(_) => {
format!("assoc type {} in {}{}", ii.name, path_str(), id_str) format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
} }
} }
} }
@ -1326,7 +1326,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
TraitItemKind::Type(..) => "assoc type", TraitItemKind::Type(..) => "assoc type",
}; };
format!("{} {} in {}{}", kind, ti.name, path_str(), id_str) format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str)
} }
Some(NodeVariant(ref variant)) => { Some(NodeVariant(ref variant)) => {
format!("variant {} in {}{}", format!("variant {} in {}{}",

View File

@ -1536,7 +1536,7 @@ pub struct TraitItemId {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TraitItem { pub struct TraitItem {
pub id: NodeId, pub id: NodeId,
pub name: Name, pub ident: Ident,
pub hir_id: HirId, pub hir_id: HirId,
pub attrs: HirVec<Attribute>, pub attrs: HirVec<Attribute>,
pub generics: Generics, pub generics: Generics,
@ -1579,7 +1579,7 @@ pub struct ImplItemId {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ImplItem { pub struct ImplItem {
pub id: NodeId, pub id: NodeId,
pub name: Name, pub ident: Ident,
pub hir_id: HirId, pub hir_id: HirId,
pub vis: Visibility, pub vis: Visibility,
pub defaultness: Defaultness, pub defaultness: Defaultness,
@ -2140,7 +2140,7 @@ impl Item_ {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TraitItemRef { pub struct TraitItemRef {
pub id: TraitItemId, pub id: TraitItemId,
pub name: Name, pub ident: Ident,
pub kind: AssociatedItemKind, pub kind: AssociatedItemKind,
pub span: Span, pub span: Span,
pub defaultness: Defaultness, pub defaultness: Defaultness,
@ -2155,7 +2155,7 @@ pub struct TraitItemRef {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ImplItemRef { pub struct ImplItemRef {
pub id: ImplItemId, pub id: ImplItemId,
pub name: Name, pub ident: Ident,
pub kind: AssociatedItemKind, pub kind: AssociatedItemKind,
pub span: Span, pub span: Span,
pub vis: Visibility, pub vis: Visibility,

View File

@ -497,14 +497,14 @@ impl<'a> State<'a> {
} }
fn print_associated_const(&mut self, fn print_associated_const(&mut self,
name: ast::Name, ident: ast::Ident,
ty: &hir::Ty, ty: &hir::Ty,
default: Option<hir::BodyId>, default: Option<hir::BodyId>,
vis: &hir::Visibility) vis: &hir::Visibility)
-> io::Result<()> { -> io::Result<()> {
self.s.word(&visibility_qualified(vis, ""))?; self.s.word(&visibility_qualified(vis, ""))?;
self.word_space("const")?; self.word_space("const")?;
self.print_name(name)?; self.print_ident(ident)?;
self.word_space(":")?; self.word_space(":")?;
self.print_type(ty)?; self.print_type(ty)?;
if let Some(expr) = default { if let Some(expr) = default {
@ -516,12 +516,12 @@ impl<'a> State<'a> {
} }
fn print_associated_type(&mut self, fn print_associated_type(&mut self,
name: ast::Name, ident: ast::Ident,
bounds: Option<&hir::GenericBounds>, bounds: Option<&hir::GenericBounds>,
ty: Option<&hir::Ty>) ty: Option<&hir::Ty>)
-> io::Result<()> { -> io::Result<()> {
self.word_space("type")?; self.word_space("type")?;
self.print_name(name)?; self.print_ident(ident)?;
if let Some(bounds) = bounds { if let Some(bounds) = bounds {
self.print_bounds(":", bounds)?; self.print_bounds(":", bounds)?;
} }
@ -929,7 +929,7 @@ impl<'a> State<'a> {
Ok(()) Ok(())
} }
pub fn print_method_sig(&mut self, pub fn print_method_sig(&mut self,
name: ast::Name, ident: ast::Ident,
m: &hir::MethodSig, m: &hir::MethodSig,
generics: &hir::Generics, generics: &hir::Generics,
vis: &hir::Visibility, vis: &hir::Visibility,
@ -938,7 +938,7 @@ impl<'a> State<'a> {
-> io::Result<()> { -> io::Result<()> {
self.print_fn(&m.decl, self.print_fn(&m.decl,
m.header, m.header,
Some(name), Some(ident.name),
generics, generics,
vis, vis,
arg_names, arg_names,
@ -952,16 +952,16 @@ impl<'a> State<'a> {
self.print_outer_attributes(&ti.attrs)?; self.print_outer_attributes(&ti.attrs)?;
match ti.node { match ti.node {
hir::TraitItemKind::Const(ref ty, default) => { hir::TraitItemKind::Const(ref ty, default) => {
self.print_associated_const(ti.name, &ty, default, &hir::Inherited)?; self.print_associated_const(ti.ident, &ty, default, &hir::Inherited)?;
} }
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => { hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, arg_names, self.print_method_sig(ti.ident, sig, &ti.generics, &hir::Inherited, arg_names,
None)?; None)?;
self.s.word(";")?; self.s.word(";")?;
} }
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
self.head("")?; self.head("")?;
self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, &[], self.print_method_sig(ti.ident, sig, &ti.generics, &hir::Inherited, &[],
Some(body))?; Some(body))?;
self.nbsp()?; self.nbsp()?;
self.end()?; // need to close a box self.end()?; // need to close a box
@ -969,7 +969,7 @@ impl<'a> State<'a> {
self.ann.nested(self, Nested::Body(body))?; self.ann.nested(self, Nested::Body(body))?;
} }
hir::TraitItemKind::Type(ref bounds, ref default) => { hir::TraitItemKind::Type(ref bounds, ref default) => {
self.print_associated_type(ti.name, self.print_associated_type(ti.ident,
Some(bounds), Some(bounds),
default.as_ref().map(|ty| &**ty))?; default.as_ref().map(|ty| &**ty))?;
} }
@ -986,18 +986,18 @@ impl<'a> State<'a> {
match ii.node { match ii.node {
hir::ImplItemKind::Const(ref ty, expr) => { hir::ImplItemKind::Const(ref ty, expr) => {
self.print_associated_const(ii.name, &ty, Some(expr), &ii.vis)?; self.print_associated_const(ii.ident, &ty, Some(expr), &ii.vis)?;
} }
hir::ImplItemKind::Method(ref sig, body) => { hir::ImplItemKind::Method(ref sig, body) => {
self.head("")?; self.head("")?;
self.print_method_sig(ii.name, sig, &ii.generics, &ii.vis, &[], Some(body))?; self.print_method_sig(ii.ident, sig, &ii.generics, &ii.vis, &[], Some(body))?;
self.nbsp()?; self.nbsp()?;
self.end()?; // need to close a box self.end()?; // need to close a box
self.end()?; // need to close a box self.end()?; // need to close a box
self.ann.nested(self, Nested::Body(body))?; self.ann.nested(self, Nested::Body(body))?;
} }
hir::ImplItemKind::Type(ref ty) => { hir::ImplItemKind::Type(ref ty) => {
self.print_associated_type(ii.name, None, Some(ty))?; self.print_associated_type(ii.ident, None, Some(ty))?;
} }
} }
self.ann.post(self, NodeSubItem(ii.id)) self.ann.post(self, NodeSubItem(ii.id))
@ -1615,7 +1615,7 @@ impl<'a> State<'a> {
} }
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> { pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
self.print_ident(name.to_ident()) self.print_ident(ast::Ident::with_empty_ctxt(name))
} }
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<()> {

View File

@ -705,7 +705,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
let hir::TraitItem { let hir::TraitItem {
id: _, id: _,
hir_id: _, hir_id: _,
name, ident,
ref attrs, ref attrs,
ref generics, ref generics,
ref node, ref node,
@ -713,7 +713,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
} = *self; } = *self;
hcx.hash_hir_item_like(|hcx| { hcx.hash_hir_item_like(|hcx| {
name.hash_stable(hcx, hasher); ident.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher);
generics.hash_stable(hcx, hasher); generics.hash_stable(hcx, hasher);
node.hash_stable(hcx, hasher); node.hash_stable(hcx, hasher);
@ -740,7 +740,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
let hir::ImplItem { let hir::ImplItem {
id: _, id: _,
hir_id: _, hir_id: _,
name, ident,
ref vis, ref vis,
defaultness, defaultness,
ref attrs, ref attrs,
@ -750,7 +750,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
} = *self; } = *self;
hcx.hash_hir_item_like(|hcx| { hcx.hash_hir_item_like(|hcx| {
name.hash_stable(hcx, hasher); ident.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher); vis.hash_stable(hcx, hasher);
defaultness.hash_stable(hcx, hasher); defaultness.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher);
@ -916,7 +916,7 @@ impl_stable_hash_for!(enum hir::Item_ {
impl_stable_hash_for!(struct hir::TraitItemRef { impl_stable_hash_for!(struct hir::TraitItemRef {
id, id,
name, ident,
kind, kind,
span, span,
defaultness defaultness
@ -924,7 +924,7 @@ impl_stable_hash_for!(struct hir::TraitItemRef {
impl_stable_hash_for!(struct hir::ImplItemRef { impl_stable_hash_for!(struct hir::ImplItemRef {
id, id,
name, ident,
kind, kind,
span, span,
vis, vis,

View File

@ -1133,7 +1133,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::CratePredicatesMap<'
impl_stable_hash_for!(struct ty::AssociatedItem { impl_stable_hash_for!(struct ty::AssociatedItem {
def_id, def_id,
name, ident,
kind, kind,
vis, vis,
defaultness, defaultness,

View File

@ -1255,7 +1255,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!( infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!(
" for lifetime parameter {}in trait containing associated type `{}`", " for lifetime parameter {}in trait containing associated type `{}`",
br_string(br), br_string(br),
self.tcx.associated_item(def_id).name self.tcx.associated_item(def_id).ident
), ),
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name), infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name),
infer::BoundRegionInCoherence(name) => { infer::BoundRegionInCoherence(name) => {

View File

@ -599,7 +599,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
if !self.symbol_is_live(impl_item.id, None) { if !self.symbol_is_live(impl_item.id, None) {
self.warn_dead_code(impl_item.id, self.warn_dead_code(impl_item.id,
impl_item.span, impl_item.span,
impl_item.name, impl_item.ident.name,
"associated const", "associated const",
"used"); "used");
} }
@ -608,7 +608,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
hir::ImplItemKind::Method(_, body_id) => { hir::ImplItemKind::Method(_, body_id) => {
if !self.symbol_is_live(impl_item.id, None) { if !self.symbol_is_live(impl_item.id, None) {
let span = self.tcx.sess.codemap().def_span(impl_item.span); let span = self.tcx.sess.codemap().def_span(impl_item.span);
self.warn_dead_code(impl_item.id, span, impl_item.name, "method", "used"); self.warn_dead_code(impl_item.id, span, impl_item.ident.name, "method", "used");
} }
self.visit_nested_body(body_id) self.visit_nested_body(body_id)
} }

View File

@ -744,7 +744,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
for impl_item_ref in impl_item_refs { for impl_item_ref in impl_item_refs {
let impl_item = self.tcx.hir.impl_item(impl_item_ref.id); let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
let trait_item_def_id = self.tcx.associated_items(trait_did) let trait_item_def_id = self.tcx.associated_items(trait_did)
.find(|item| item.name == impl_item.name).map(|item| item.def_id); .find(|item| item.ident.name == impl_item.ident.name)
.map(|item| item.def_id);
if let Some(def_id) = trait_item_def_id { if let Some(def_id) = trait_item_def_id {
// Pass `None` to skip deprecation warnings. // Pass `None` to skip deprecation warnings.
self.tcx.check_stability(def_id, None, impl_item.span); self.tcx.check_stability(def_id, None, impl_item.span);

View File

@ -130,7 +130,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
.filter(|item| item.kind == ty::AssociatedKind::Method) .filter(|item| item.kind == ty::AssociatedKind::Method)
.filter_map(|item| { .filter_map(|item| {
self.object_safety_violation_for_method(trait_def_id, &item) self.object_safety_violation_for_method(trait_def_id, &item)
.map(|code| ObjectSafetyViolation::Method(item.name, code)) .map(|code| ObjectSafetyViolation::Method(item.ident.name, code))
}).filter(|violation| { }).filter(|violation| {
if let ObjectSafetyViolation::Method(_, if let ObjectSafetyViolation::Method(_,
MethodViolationCode::WhereClauseReferencesSelf(span)) = violation { MethodViolationCode::WhereClauseReferencesSelf(span)) = violation {
@ -159,7 +159,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
violations.extend(self.associated_items(trait_def_id) violations.extend(self.associated_items(trait_def_id)
.filter(|item| item.kind == ty::AssociatedKind::Const) .filter(|item| item.kind == ty::AssociatedKind::Const)
.map(|item| ObjectSafetyViolation::AssociatedConst(item.name))); .map(|item| ObjectSafetyViolation::AssociatedConst(item.ident.name)));
debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}", debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
trait_def_id, trait_def_id,

View File

@ -32,7 +32,6 @@ use middle::const_val::ConstVal;
use mir::interpret::{GlobalId}; use mir::interpret::{GlobalId};
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap}; use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
use syntax::ast::Ident; use syntax::ast::Ident;
use syntax::symbol::Symbol;
use ty::subst::{Subst, Substs}; use ty::subst::{Subst, Substs};
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt}; use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder}; use ty::fold::{TypeFoldable, TypeFolder};
@ -1350,10 +1349,10 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(
obligation.predicate.self_ty(), obligation.predicate.self_ty(),
gen_sig) gen_sig)
.map_bound(|(trait_ref, yield_ty, return_ty)| { .map_bound(|(trait_ref, yield_ty, return_ty)| {
let name = tcx.associated_item(obligation.predicate.item_def_id).name; let name = tcx.associated_item(obligation.predicate.item_def_id).ident.name;
let ty = if name == Symbol::intern("Return") { let ty = if name == "Return" {
return_ty return_ty
} else if name == Symbol::intern("Yield") { } else if name == "Yield" {
yield_ty yield_ty
} else { } else {
bug!() bug!()
@ -1509,7 +1508,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
// checker method `check_impl_items_against_trait`, so here we // checker method `check_impl_items_against_trait`, so here we
// just return TyError. // just return TyError.
debug!("confirm_impl_candidate: no associated type {:?} for {:?}", debug!("confirm_impl_candidate: no associated type {:?} for {:?}",
assoc_ty.item.name, assoc_ty.item.ident,
obligation.predicate); obligation.predicate);
tcx.types.err tcx.types.err
} else { } else {
@ -1534,7 +1533,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
-> specialization_graph::NodeItem<ty::AssociatedItem> -> specialization_graph::NodeItem<ty::AssociatedItem>
{ {
let tcx = selcx.tcx(); let tcx = selcx.tcx();
let assoc_ty_name = tcx.associated_item(assoc_ty_def_id).name; let assoc_ty_name = tcx.associated_item(assoc_ty_def_id).ident;
let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().def_id; let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().def_id;
let trait_def = tcx.trait_def(trait_def_id); let trait_def = tcx.trait_def(trait_def_id);
@ -1547,7 +1546,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
let impl_node = specialization_graph::Node::Impl(impl_def_id); let impl_node = specialization_graph::Node::Impl(impl_def_id);
for item in impl_node.items(tcx) { for item in impl_node.items(tcx) {
if item.kind == ty::AssociatedKind::Type && if item.kind == ty::AssociatedKind::Type &&
tcx.hygienic_eq(item.name.to_ident(), assoc_ty_name.to_ident(), trait_def_id) { tcx.hygienic_eq(item.ident, assoc_ty_name, trait_def_id) {
return specialization_graph::NodeItem { return specialization_graph::NodeItem {
node: specialization_graph::Node::Impl(impl_def_id), node: specialization_graph::Node::Impl(impl_def_id),
item, item,

View File

@ -129,7 +129,7 @@ pub fn find_associated_item<'a, 'tcx>(
let trait_def = tcx.trait_def(trait_def_id); let trait_def = tcx.trait_def(trait_def_id);
let ancestors = trait_def.ancestors(tcx, impl_data.impl_def_id); let ancestors = trait_def.ancestors(tcx, impl_data.impl_def_id);
match ancestors.defs(tcx, item.name, item.kind, trait_def_id).next() { match ancestors.defs(tcx, item.ident, item.kind, trait_def_id).next() {
Some(node_item) => { Some(node_item) => {
let substs = tcx.infer_ctxt().enter(|infcx| { let substs = tcx.infer_ctxt().enter(|infcx| {
let param_env = ty::ParamEnv::reveal_all(); let param_env = ty::ParamEnv::reveal_all();

View File

@ -18,7 +18,7 @@ use traits;
use ty::{self, TyCtxt, TypeFoldable}; use ty::{self, TyCtxt, TypeFoldable};
use ty::fast_reject::{self, SimplifiedType}; use ty::fast_reject::{self, SimplifiedType};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use syntax::ast::Name; use syntax::ast::Ident;
use util::captures::Captures; use util::captures::Captures;
use util::nodemap::{DefIdMap, FxHashMap}; use util::nodemap::{DefIdMap, FxHashMap};
@ -372,14 +372,14 @@ impl<'a, 'gcx, 'tcx> Ancestors {
pub fn defs( pub fn defs(
self, self,
tcx: TyCtxt<'a, 'gcx, 'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>,
trait_item_name: Name, trait_item_name: Ident,
trait_item_kind: ty::AssociatedKind, trait_item_kind: ty::AssociatedKind,
trait_def_id: DefId, trait_def_id: DefId,
) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a { ) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a {
self.flat_map(move |node| { self.flat_map(move |node| {
node.items(tcx).filter(move |impl_item| { node.items(tcx).filter(move |impl_item| {
impl_item.kind == trait_item_kind && impl_item.kind == trait_item_kind &&
tcx.hygienic_eq(impl_item.name.to_ident(), trait_item_name.to_ident(), trait_def_id) tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id)
}).map(move |item| NodeItem { node: node, item: item }) }).map(move |item| NodeItem { node: node, item: item })
}) })
} }

View File

@ -177,7 +177,7 @@ pub struct ImplHeader<'tcx> {
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AssociatedItem { pub struct AssociatedItem {
pub def_id: DefId, pub def_id: DefId,
pub name: Name, pub ident: Ident,
pub kind: AssociatedKind, pub kind: AssociatedKind,
pub vis: Visibility, pub vis: Visibility,
pub defaultness: hir::Defaultness, pub defaultness: hir::Defaultness,
@ -224,9 +224,9 @@ impl AssociatedItem {
// regions just fine, showing `fn(&MyType)`. // regions just fine, showing `fn(&MyType)`.
format!("{}", tcx.fn_sig(self.def_id).skip_binder()) format!("{}", tcx.fn_sig(self.def_id).skip_binder())
} }
ty::AssociatedKind::Type => format!("type {};", self.name.to_string()), ty::AssociatedKind::Type => format!("type {};", self.ident),
ty::AssociatedKind::Const => { ty::AssociatedKind::Const => {
format!("const {}: {:?};", self.name.to_string(), tcx.type_of(self.def_id)) format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id))
} }
} }
} }
@ -2494,7 +2494,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}; };
AssociatedItem { AssociatedItem {
name: trait_item_ref.name, ident: trait_item_ref.ident,
kind, kind,
// Visibility of trait items is inherited from their traits. // Visibility of trait items is inherited from their traits.
vis: Visibility::from_hir(parent_vis, trait_item_ref.id.node_id, self), vis: Visibility::from_hir(parent_vis, trait_item_ref.id.node_id, self),
@ -2518,8 +2518,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
hir::AssociatedItemKind::Type => (ty::AssociatedKind::Type, false), hir::AssociatedItemKind::Type => (ty::AssociatedKind::Type, false),
}; };
ty::AssociatedItem { AssociatedItem {
name: impl_item_ref.name, ident: impl_item_ref.ident,
kind, kind,
// Visibility of trait impl items doesn't matter. // Visibility of trait impl items doesn't matter.
vis: ty::Visibility::from_hir(&impl_item_ref.vis, impl_item_ref.id.node_id, self), vis: ty::Visibility::from_hir(&impl_item_ref.vis, impl_item_ref.id.node_id, self),
@ -2544,10 +2544,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn associated_items( pub fn associated_items(
self, self,
def_id: DefId, def_id: DefId,
) -> impl Iterator<Item = ty::AssociatedItem> + 'a { ) -> impl Iterator<Item = AssociatedItem> + 'a {
let def_ids = self.associated_item_def_ids(def_id); let def_ids = self.associated_item_def_ids(def_id);
Box::new((0..def_ids.len()).map(move |i| self.associated_item(def_ids[i]))) Box::new((0..def_ids.len()).map(move |i| self.associated_item(def_ids[i])))
as Box<dyn Iterator<Item = ty::AssociatedItem> + 'a> as Box<dyn Iterator<Item = AssociatedItem> + 'a>
} }
/// Returns true if the impls are the same polarity and are implementing /// Returns true if the impls are the same polarity and are implementing

View File

@ -857,7 +857,7 @@ impl<'a, 'tcx> ProjectionTy<'tcx> {
) -> ProjectionTy<'tcx> { ) -> ProjectionTy<'tcx> {
let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| { let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| {
item.kind == ty::AssociatedKind::Type && item.kind == ty::AssociatedKind::Type &&
tcx.hygienic_eq(item_name, item.name.to_ident(), trait_ref.def_id) tcx.hygienic_eq(item_name, item.ident, trait_ref.def_id)
}).unwrap().def_id; }).unwrap().def_id;
ProjectionTy { ProjectionTy {

View File

@ -429,7 +429,7 @@ impl PrintContext {
ty::tls::with(|tcx| ty::tls::with(|tcx|
print!(f, self, print!(f, self,
write("{}=", write("{}=",
tcx.associated_item(projection.projection_ty.item_def_id).name), tcx.associated_item(projection.projection_ty.item_def_id).ident),
print_display(projection.ty)) print_display(projection.ty))
)?; )?;
} }
@ -1286,7 +1286,7 @@ define_print! {
// parameterized(f, self.substs, self.item_def_id, &[]) // parameterized(f, self.substs, self.item_def_id, &[])
// (which currently ICEs). // (which currently ICEs).
let (trait_ref, item_name) = ty::tls::with(|tcx| let (trait_ref, item_name) = ty::tls::with(|tcx|
(self.trait_ref(tcx), tcx.associated_item(self.item_def_id).name) (self.trait_ref(tcx), tcx.associated_item(self.item_def_id).ident)
); );
print!(f, cx, print_debug(trait_ref), write("::{}", item_name)) print!(f, cx, print_debug(trait_ref), write("::{}", item_name))
} }

View File

@ -1075,7 +1075,7 @@ impl RustcDefaultCalls {
let mut cfgs = Vec::new(); let mut cfgs = Vec::new();
for &(name, ref value) in sess.parse_sess.config.iter() { for &(name, ref value) in sess.parse_sess.config.iter() {
let gated_cfg = GatedCfg::gate(&ast::MetaItem { let gated_cfg = GatedCfg::gate(&ast::MetaItem {
ident: ast::Path::from_ident(name.to_ident()), ident: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)),
node: ast::MetaItemKind::Word, node: ast::MetaItemKind::Word,
span: DUMMY_SP, span: DUMMY_SP,
}); });

View File

@ -305,7 +305,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(ref pnames)) = item.node { if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(ref pnames)) = item.node {
self.check_snake_case(cx, self.check_snake_case(cx,
"trait method", "trait method",
&item.name.as_str(), &item.ident.as_str(),
Some(item.span)); Some(item.span));
for param_name in pnames { for param_name in pnames {
self.check_snake_case(cx, "variable", &param_name.as_str(), Some(param_name.span)); self.check_snake_case(cx, "variable", &param_name.as_str(), Some(param_name.span));
@ -385,7 +385,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) { fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) {
match ti.node { match ti.node {
hir::TraitItemKind::Const(..) => { hir::TraitItemKind::Const(..) => {
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ti.name, ti.span); NonUpperCaseGlobals::check_upper_case(cx, "associated constant",
ti.ident.name, ti.span);
} }
_ => {} _ => {}
} }
@ -394,7 +395,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) { fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) {
match ii.node { match ii.node {
hir::ImplItemKind::Const(..) => { hir::ImplItemKind::Const(..) => {
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ii.name, ii.span); NonUpperCaseGlobals::check_upper_case(cx, "associated constant",
ii.ident.name, ii.span);
} }
_ => {} _ => {}
} }

View File

@ -1078,7 +1078,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
let container = ty::ImplContainer(vtable_impl.impl_def_id); let container = ty::ImplContainer(vtable_impl.impl_def_id);
// It matches if it comes from the same impl, // It matches if it comes from the same impl,
// and has the same method name. // and has the same method name.
container == method.container && callee_item.name == method.name container == method.container &&
callee_item.ident.name == method.ident.name
} }
// There's no way to know if this call is // There's no way to know if this call is

View File

@ -817,7 +817,7 @@ impl<'a, 'tcx> CrateMetadata {
}; };
ty::AssociatedItem { ty::AssociatedItem {
name: name.as_symbol(), ident: Ident::from_interned_str(name),
kind, kind,
vis: item.visibility.decode(self), vis: item.visibility.decode(self),
defaultness: container.defaultness(), defaultness: container.defaultness(),

View File

@ -235,7 +235,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
let method_name = Symbol::intern(method_name); let method_name = Symbol::intern(method_name);
let substs = self.tcx.mk_substs_trait(self_ty, params); let substs = self.tcx.mk_substs_trait(self_ty, params);
for item in self.tcx.associated_items(trait_def_id) { for item in self.tcx.associated_items(trait_def_id) {
if item.kind == ty::AssociatedKind::Method && item.name == method_name { if item.kind == ty::AssociatedKind::Method && item.ident.name == method_name {
let method_ty = self.tcx.type_of(item.def_id); let method_ty = self.tcx.type_of(item.def_id);
let method_ty = method_ty.subst(self.tcx, substs); let method_ty = method_ty.subst(self.tcx, substs);
return (method_ty, return (method_ty,

View File

@ -1115,10 +1115,10 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) { if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
let overridden_methods: FxHashSet<_> = let overridden_methods: FxHashSet<_> =
impl_item_refs.iter() impl_item_refs.iter()
.map(|iiref| iiref.name) .map(|iiref| iiref.ident.modern())
.collect(); .collect();
for method in tcx.provided_trait_methods(trait_ref.def_id) { for method in tcx.provided_trait_methods(trait_ref.def_id) {
if overridden_methods.contains(&method.name) { if overridden_methods.contains(&method.ident.modern()) {
continue; continue;
} }

View File

@ -441,7 +441,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
for projection in projections { for projection in projections {
let projection = projection.skip_binder(); let projection = projection.skip_binder();
let name = &self.tcx.associated_item(projection.item_def_id).name.as_str(); let name = &self.tcx.associated_item(projection.item_def_id).ident.as_str();
output.push_str(name); output.push_str(name);
output.push_str("="); output.push_str("=");
self.push_type_name(projection.ty, output); self.push_type_name(projection.ty, output);

View File

@ -3505,7 +3505,7 @@ impl<'a> Resolver<'a> {
match path.get(1) { match path.get(1) {
// If this import looks like `crate::...` it's already good // If this import looks like `crate::...` it's already good
Some(name) if name.name == keywords::Crate.name() => return, Some(ident) if ident.name == keywords::Crate.name() => return,
// Otherwise go below to see if it's an extern crate // Otherwise go below to see if it's an extern crate
Some(_) => {} Some(_) => {}
// If the path has length one (and it's `CrateRoot` most likely) // If the path has length one (and it's `CrateRoot` most likely)

View File

@ -316,14 +316,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
sig: &'l ast::MethodSig, sig: &'l ast::MethodSig,
body: Option<&'l ast::Block>, body: Option<&'l ast::Block>,
id: ast::NodeId, id: ast::NodeId,
name: ast::Ident, ident: ast::Ident,
generics: &'l ast::Generics, generics: &'l ast::Generics,
vis: ast::Visibility, vis: ast::Visibility,
span: Span, span: Span,
) { ) {
debug!("process_method: {}:{}", id, name); debug!("process_method: {}:{}", id, ident);
if let Some(mut method_data) = self.save_ctxt.get_method_data(id, name.name, span) { if let Some(mut method_data) = self.save_ctxt.get_method_data(id, ident.name, span) {
let sig_str = ::make_signature(&sig.decl, &generics); let sig_str = ::make_signature(&sig.decl, &generics);
if body.is_some() { if body.is_some() {
self.nest_tables( self.nest_tables(
@ -335,7 +335,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
self.process_generic_params(&generics, span, &method_data.qualname, id); self.process_generic_params(&generics, span, &method_data.qualname, id);
method_data.value = sig_str; method_data.value = sig_str;
method_data.sig = sig::method_signature(id, name, generics, sig, &self.save_ctxt); method_data.sig = sig::method_signature(id, ident, generics, sig, &self.save_ctxt);
self.dumper.dump_def(&access_from!(self.save_ctxt, vis, id), method_data); self.dumper.dump_def(&access_from!(self.save_ctxt, vis, id), method_data);
} }

View File

@ -438,7 +438,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
qualname.push_str(&self.tcx.item_path_str(def_id)); qualname.push_str(&self.tcx.item_path_str(def_id));
self.tcx self.tcx
.associated_items(def_id) .associated_items(def_id)
.find(|item| item.name == name) .find(|item| item.ident.name == name)
.map(|item| decl_id = Some(item.def_id)); .map(|item| decl_id = Some(item.def_id));
} }
qualname.push_str(">"); qualname.push_str(">");
@ -775,7 +775,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let ti = self.tcx.associated_item(decl_id); let ti = self.tcx.associated_item(decl_id);
self.tcx self.tcx
.associated_items(ti.container.id()) .associated_items(ti.container.id())
.find(|item| item.name == ti.name && item.defaultness.has_value()) .find(|item| item.ident.name == ti.ident.name &&
item.defaultness.has_value())
.map(|item| item.def_id) .map(|item| item.def_id)
} else { } else {
None None

View File

@ -417,7 +417,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
let hypotheses = vec![trait_implemented]; let hypotheses = vec![trait_implemented];
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>` // `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name.to_ident()); let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.ident);
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)` // `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty }); let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });

View File

@ -490,7 +490,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
{ {
self.tcx().associated_items(trait_def_id).any(|item| { self.tcx().associated_items(trait_def_id).any(|item| {
item.kind == ty::AssociatedKind::Type && item.kind == ty::AssociatedKind::Type &&
self.tcx().hygienic_eq(assoc_name, item.name.to_ident(), trait_def_id) self.tcx().hygienic_eq(assoc_name, item.ident, trait_def_id)
}) })
} }
@ -571,7 +571,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let (assoc_ident, def_scope) = let (assoc_ident, def_scope) =
tcx.adjust_ident(binding.item_name, candidate.def_id(), ref_id); tcx.adjust_ident(binding.item_name, 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.ident.modern() == assoc_ident
}).expect("missing associated type"); }).expect("missing associated type");
if !assoc_ty.vis.is_accessible_from(def_scope, tcx) { if !assoc_ty.vis.is_accessible_from(def_scope, tcx) {
@ -711,10 +711,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let trait_def_id = assoc_item.container.id(); let trait_def_id = assoc_item.container.id();
struct_span_err!(tcx.sess, span, E0191, struct_span_err!(tcx.sess, span, E0191,
"the value of the associated type `{}` (from the trait `{}`) must be specified", "the value of the associated type `{}` (from the trait `{}`) must be specified",
assoc_item.name, assoc_item.ident,
tcx.item_path_str(trait_def_id)) tcx.item_path_str(trait_def_id))
.span_label(span, format!( .span_label(span, format!(
"missing associated type `{}` value", assoc_item.name)) "missing associated type `{}` value", assoc_item.ident))
.emit(); .emit();
} }
@ -837,7 +837,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
for bound in bounds { for bound in bounds {
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| { let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
item.kind == ty::AssociatedKind::Type && item.kind == ty::AssociatedKind::Type &&
self.tcx().hygienic_eq(assoc_name, item.name.to_ident(), bound.def_id()) self.tcx().hygienic_eq(assoc_name, item.ident, bound.def_id())
}) })
.and_then(|item| self.tcx().hir.span_if_local(item.def_id)); .and_then(|item| self.tcx().hir.span_if_local(item.def_id));
@ -925,7 +925,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name, trait_did, ref_id); let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name, 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.ident.modern() == assoc_ident
}) })
.expect("missing associated type"); .expect("missing associated type");

View File

@ -18,7 +18,7 @@ use rustc::{infer, traits};
use rustc::ty::{self, TyCtxt, TypeFoldable, Ty}; use rustc::ty::{self, TyCtxt, TypeFoldable, Ty};
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc_target::spec::abi; use rustc_target::spec::abi;
use syntax::symbol::Symbol; use syntax::ast::Ident;
use syntax_pos::Span; use syntax_pos::Span;
use rustc::hir; use rustc::hir;
@ -157,9 +157,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
MethodCallee<'tcx>)> { MethodCallee<'tcx>)> {
// Try the options that are least restrictive on the caller first. // Try the options that are least restrictive on the caller first.
for &(opt_trait_def_id, method_name, borrow) in for &(opt_trait_def_id, method_name, borrow) in
&[(self.tcx.lang_items().fn_trait(), Symbol::intern("call"), true), &[(self.tcx.lang_items().fn_trait(), Ident::from_str("call"), true),
(self.tcx.lang_items().fn_mut_trait(), Symbol::intern("call_mut"), true), (self.tcx.lang_items().fn_mut_trait(), Ident::from_str("call_mut"), true),
(self.tcx.lang_items().fn_once_trait(), Symbol::intern("call_once"), false)] { (self.tcx.lang_items().fn_once_trait(), Ident::from_str("call_once"), false)] {
let trait_def_id = match opt_trait_def_id { let trait_def_id = match opt_trait_def_id {
Some(def_id) => def_id, Some(def_id) => def_id,
None => continue, None => continue,

View File

@ -100,7 +100,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
span: impl_m_span, span: impl_m_span,
body_id: impl_m_node_id, body_id: impl_m_node_id,
code: ObligationCauseCode::CompareImplMethodObligation { code: ObligationCauseCode::CompareImplMethodObligation {
item_name: impl_m.name, item_name: impl_m.ident.name,
impl_item_def_id: impl_m.def_id, impl_item_def_id: impl_m.def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
}, },
@ -318,7 +318,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
cause.span(&tcx), cause.span(&tcx),
E0053, E0053,
"method `{}` has an incompatible type for trait", "method `{}` has an incompatible type for trait",
trait_m.name); trait_m.ident);
infcx.note_type_err(&mut diag, infcx.note_type_err(&mut diag,
&cause, &cause,
@ -383,7 +383,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0195, E0195,
"lifetime parameters or bounds on method `{}` do not match \ "lifetime parameters or bounds on method `{}` do not match \
the trait declaration", the trait declaration",
impl_m.name); impl_m.ident);
err.span_label(span, "lifetimes do not match method in trait"); err.span_label(span, "lifetimes do not match method in trait");
if let Some(sp) = tcx.hir.span_if_local(trait_m.def_id) { if let Some(sp) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(tcx.sess.codemap().def_span(sp), err.span_label(tcx.sess.codemap().def_span(sp),
@ -529,13 +529,13 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0185, E0185,
"method `{}` has a `{}` declaration in the impl, but \ "method `{}` has a `{}` declaration in the impl, but \
not in the trait", not in the trait",
trait_m.name, trait_m.ident,
self_descr); self_descr);
err.span_label(impl_m_span, format!("`{}` used in impl", self_descr)); err.span_label(impl_m_span, format!("`{}` used in impl", self_descr));
if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) { if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(span, format!("trait method declared without `{}`", self_descr)); err.span_label(span, format!("trait method declared without `{}`", self_descr));
} else { } else {
err.note_trait_signature(trait_m.name.to_string(), err.note_trait_signature(trait_m.ident.to_string(),
trait_m.signature(&tcx)); trait_m.signature(&tcx));
} }
err.emit(); err.emit();
@ -549,13 +549,13 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0186, E0186,
"method `{}` has a `{}` declaration in the trait, but \ "method `{}` has a `{}` declaration in the trait, but \
not in the impl", not in the impl",
trait_m.name, trait_m.ident,
self_descr); self_descr);
err.span_label(impl_m_span, format!("expected `{}` in impl", self_descr)); err.span_label(impl_m_span, format!("expected `{}` in impl", self_descr));
if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) { if let Some(span) = tcx.hir.span_if_local(trait_m.def_id) {
err.span_label(span, format!("`{}` used in trait", self_descr)); err.span_label(span, format!("`{}` used in trait", self_descr));
} else { } else {
err.note_trait_signature(trait_m.name.to_string(), err.note_trait_signature(trait_m.ident.to_string(),
trait_m.signature(&tcx)); trait_m.signature(&tcx));
} }
err.emit(); err.emit();
@ -590,7 +590,7 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0049, E0049,
"method `{}` has {} type parameter{} but its trait \ "method `{}` has {} type parameter{} but its trait \
declaration has {} type parameter{}", declaration has {} type parameter{}",
trait_m.name, trait_m.ident,
num_impl_m_type_params, num_impl_m_type_params,
if num_impl_m_type_params == 1 { "" } else { "s" }, if num_impl_m_type_params == 1 { "" } else { "s" },
num_trait_m_type_params, num_trait_m_type_params,
@ -681,7 +681,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0050, E0050,
"method `{}` has {} parameter{} but the declaration in \ "method `{}` has {} parameter{} but the declaration in \
trait `{}` has {}", trait `{}` has {}",
trait_m.name, trait_m.ident,
impl_number_args, impl_number_args,
if impl_number_args == 1 { "" } else { "s" }, if impl_number_args == 1 { "" } else { "s" },
tcx.item_path_str(trait_m.def_id), tcx.item_path_str(trait_m.def_id),
@ -695,7 +695,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
format!("{} parameter", trait_number_args) format!("{} parameter", trait_number_args)
})); }));
} else { } else {
err.note_trait_signature(trait_m.name.to_string(), err.note_trait_signature(trait_m.ident.to_string(),
trait_m.signature(&tcx)); trait_m.signature(&tcx));
} }
err.span_label(impl_span, err.span_label(impl_span,
@ -748,7 +748,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
impl_span, impl_span,
E0643, E0643,
"method `{}` has incompatible signature for trait", "method `{}` has incompatible signature for trait",
trait_m.name); trait_m.ident);
err.span_label(trait_span, "declaration in trait here"); err.span_label(trait_span, "declaration in trait here");
match (impl_synthetic, trait_synthetic) { match (impl_synthetic, trait_synthetic) {
// The case where the impl method uses `impl Trait` but the trait method uses // The case where the impl method uses `impl Trait` but the trait method uses
@ -948,7 +948,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
E0326, E0326,
"implemented const `{}` has an incompatible type for \ "implemented const `{}` has an incompatible type for \
trait", trait",
trait_c.name); trait_c.ident);
let trait_c_node_id = tcx.hir.as_local_node_id(trait_c.def_id); let trait_c_node_id = tcx.hir.as_local_node_id(trait_c.def_id);
let trait_c_span = trait_c_node_id.map(|trait_c_node_id| { let trait_c_span = trait_c_node_id.map(|trait_c_node_id| {

View File

@ -146,7 +146,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let methods = self.get_conversion_methods(expr.span, expected, checked_ty); let methods = self.get_conversion_methods(expr.span, expected, checked_ty);
if let Ok(expr_text) = self.tcx.sess.codemap().span_to_snippet(expr.span) { if let Ok(expr_text) = self.tcx.sess.codemap().span_to_snippet(expr.span) {
let suggestions = iter::repeat(expr_text).zip(methods.iter()) let suggestions = iter::repeat(expr_text).zip(methods.iter())
.map(|(receiver, method)| format!("{}.{}()", receiver, method.name)) .map(|(receiver, method)| format!("{}.{}()", receiver, method.ident))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if !suggestions.is_empty() { if !suggestions.is_empty() {
err.span_suggestions(expr.span, err.span_suggestions(expr.span,

View File

@ -244,7 +244,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
/// of this method is basically the same as confirmation. /// of this method is basically the same as confirmation.
pub fn lookup_method_in_trait(&self, pub fn lookup_method_in_trait(&self,
span: Span, span: Span,
m_name: ast::Name, m_name: ast::Ident,
trait_def_id: DefId, trait_def_id: DefId,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
opt_input_types: Option<&[Ty<'tcx>]>) opt_input_types: Option<&[Ty<'tcx>]>)
@ -290,7 +290,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// type parameters or early-bound regions. // type parameters or early-bound regions.
let tcx = self.tcx; let tcx = self.tcx;
let method_item = let method_item =
self.associated_item(trait_def_id, m_name.to_ident(), Namespace::Value).unwrap(); self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap();
let def_id = method_item.def_id; let def_id = method_item.def_id;
let generics = tcx.generics_of(def_id); let generics = tcx.generics_of(def_id);
assert_eq!(generics.params.len(), 0); assert_eq!(generics.params.len(), 0);
@ -390,7 +390,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
-> Option<ty::AssociatedItem> { -> Option<ty::AssociatedItem> {
self.tcx.associated_items(def_id).find(|item| { self.tcx.associated_items(def_id).find(|item| {
Namespace::from(item.kind) == ns && Namespace::from(item.kind) == ns &&
self.tcx.hygienic_eq(item_name, item.name.to_ident(), def_id) self.tcx.hygienic_eq(item_name, item.ident, def_id)
}) })
} }
} }

View File

@ -810,7 +810,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
true true
} }
}) })
.map(|candidate| candidate.item.name.to_ident()) .map(|candidate| candidate.item.ident)
.filter(|&name| set.insert(name)) .filter(|&name| set.insert(name))
.collect(); .collect();
@ -1309,14 +1309,14 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
Ok(None) Ok(None)
} else { } else {
let best_name = { let best_name = {
let names = applicable_close_candidates.iter().map(|cand| &cand.name); let names = applicable_close_candidates.iter().map(|cand| &cand.ident.name);
find_best_match_for_name(names, find_best_match_for_name(names,
&self.method_name.unwrap().as_str(), &self.method_name.unwrap().as_str(),
None) None)
}.unwrap(); }.unwrap();
Ok(applicable_close_candidates Ok(applicable_close_candidates
.into_iter() .into_iter()
.find(|method| method.name == best_name)) .find(|method| method.ident.name == best_name))
} }
}) })
} }
@ -1456,7 +1456,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
let max_dist = max(name.as_str().len(), 3) / 3; let max_dist = max(name.as_str().len(), 3) / 3;
self.tcx.associated_items(def_id) self.tcx.associated_items(def_id)
.filter(|x| { .filter(|x| {
let dist = lev_distance(&*name.as_str(), &x.name.as_str()); let dist = lev_distance(&*name.as_str(), &x.ident.as_str());
Namespace::from(x.kind) == Namespace::Value && dist > 0 Namespace::from(x.kind) == Namespace::Value && dist > 0
&& dist <= max_dist && dist <= max_dist
}) })

View File

@ -444,7 +444,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} }
if let Some(lev_candidate) = lev_candidate { if let Some(lev_candidate) = lev_candidate {
err.help(&format!("did you mean `{}`?", lev_candidate.name)); err.help(&format!("did you mean `{}`?", lev_candidate.ident));
} }
err.emit(); err.emit();
} }

View File

@ -1333,15 +1333,15 @@ fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.sess, impl_item.span, E0520, tcx.sess, impl_item.span, E0520,
"`{}` specializes an item from a parent `impl`, but \ "`{}` specializes an item from a parent `impl`, but \
that item is not marked `default`", that item is not marked `default`",
impl_item.name); impl_item.ident);
err.span_label(impl_item.span, format!("cannot specialize default item `{}`", err.span_label(impl_item.span, format!("cannot specialize default item `{}`",
impl_item.name)); impl_item.ident));
match tcx.span_of_impl(parent_impl) { match tcx.span_of_impl(parent_impl) {
Ok(span) => { Ok(span) => {
err.span_label(span, "parent `impl` is here"); err.span_label(span, "parent `impl` is here");
err.note(&format!("to specialize, `{}` in the parent `impl` must be marked `default`", err.note(&format!("to specialize, `{}` in the parent `impl` must be marked `default`",
impl_item.name)); impl_item.ident));
} }
Err(cname) => { Err(cname) => {
err.note(&format!("parent implementation is in crate `{}`", cname)); err.note(&format!("parent implementation is in crate `{}`", cname));
@ -1365,7 +1365,7 @@ fn check_specialization_validity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
hir::ImplItemKind::Type(_) => ty::AssociatedKind::Type hir::ImplItemKind::Type(_) => ty::AssociatedKind::Type
}; };
let parent = ancestors.defs(tcx, trait_item.name, kind, trait_def.def_id).skip(1).next() let parent = ancestors.defs(tcx, trait_item.ident, kind, trait_def.def_id).skip(1).next()
.map(|node_item| node_item.map(|parent| parent.defaultness)); .map(|node_item| node_item.map(|parent| parent.defaultness));
if let Some(parent) = parent { if let Some(parent) = parent {
@ -1400,13 +1400,11 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let ty_impl_item = tcx.associated_item(tcx.hir.local_def_id(impl_item.id)); let ty_impl_item = tcx.associated_item(tcx.hir.local_def_id(impl_item.id));
let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id) let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id)
.find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) && .find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) &&
tcx.hygienic_eq(ty_impl_item.name.to_ident(), ac.name.to_ident(), tcx.hygienic_eq(ty_impl_item.ident, ac.ident, impl_trait_ref.def_id))
impl_trait_ref.def_id))
.or_else(|| { .or_else(|| {
// Not compatible, but needed for the error message // Not compatible, but needed for the error message
tcx.associated_items(impl_trait_ref.def_id) tcx.associated_items(impl_trait_ref.def_id)
.find(|ac| tcx.hygienic_eq(ty_impl_item.name.to_ident(), ac.name.to_ident(), .find(|ac| tcx.hygienic_eq(ty_impl_item.ident, ac.ident, impl_trait_ref.def_id))
impl_trait_ref.def_id))
}); });
// Check that impl definition matches trait definition // Check that impl definition matches trait definition
@ -1424,7 +1422,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0323, let mut err = struct_span_err!(tcx.sess, impl_item.span, E0323,
"item `{}` is an associated const, \ "item `{}` is an associated const, \
which doesn't match its trait `{}`", which doesn't match its trait `{}`",
ty_impl_item.name, ty_impl_item.ident,
impl_trait_ref); impl_trait_ref);
err.span_label(impl_item.span, "does not match trait"); err.span_label(impl_item.span, "does not match trait");
// We can only get the spans from local trait definition // We can only get the spans from local trait definition
@ -1448,7 +1446,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324, let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324,
"item `{}` is an associated method, \ "item `{}` is an associated method, \
which doesn't match its trait `{}`", which doesn't match its trait `{}`",
ty_impl_item.name, ty_impl_item.ident,
impl_trait_ref); impl_trait_ref);
err.span_label(impl_item.span, "does not match trait"); err.span_label(impl_item.span, "does not match trait");
if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) { if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
@ -1466,7 +1464,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0325, let mut err = struct_span_err!(tcx.sess, impl_item.span, E0325,
"item `{}` is an associated type, \ "item `{}` is an associated type, \
which doesn't match its trait `{}`", which doesn't match its trait `{}`",
ty_impl_item.name, ty_impl_item.ident,
impl_trait_ref); impl_trait_ref);
err.span_label(impl_item.span, "does not match trait"); err.span_label(impl_item.span, "does not match trait");
if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) { if let Some(trait_span) = tcx.hir.span_if_local(ty_trait_item.def_id) {
@ -1487,7 +1485,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let associated_type_overridden = overridden_associated_type.is_some(); let associated_type_overridden = overridden_associated_type.is_some();
for trait_item in tcx.associated_items(impl_trait_ref.def_id) { for trait_item in tcx.associated_items(impl_trait_ref.def_id) {
let is_implemented = trait_def.ancestors(tcx, impl_id) let is_implemented = trait_def.ancestors(tcx, impl_id)
.defs(tcx, trait_item.name, trait_item.kind, impl_trait_ref.def_id) .defs(tcx, trait_item.ident, trait_item.kind, impl_trait_ref.def_id)
.next() .next()
.map(|node_item| !node_item.node.is_from_trait()) .map(|node_item| !node_item.node.is_from_trait())
.unwrap_or(false); .unwrap_or(false);
@ -1496,7 +1494,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if !trait_item.defaultness.has_value() { if !trait_item.defaultness.has_value() {
missing_items.push(trait_item); missing_items.push(trait_item);
} else if associated_type_overridden { } else if associated_type_overridden {
invalidated_items.push(trait_item.name); invalidated_items.push(trait_item.ident);
} }
} }
} }
@ -1505,17 +1503,17 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut err = struct_span_err!(tcx.sess, impl_span, E0046, let mut err = struct_span_err!(tcx.sess, impl_span, E0046,
"not all trait items implemented, missing: `{}`", "not all trait items implemented, missing: `{}`",
missing_items.iter() missing_items.iter()
.map(|trait_item| trait_item.name.to_string()) .map(|trait_item| trait_item.ident.to_string())
.collect::<Vec<_>>().join("`, `")); .collect::<Vec<_>>().join("`, `"));
err.span_label(impl_span, format!("missing `{}` in implementation", err.span_label(impl_span, format!("missing `{}` in implementation",
missing_items.iter() missing_items.iter()
.map(|trait_item| trait_item.name.to_string()) .map(|trait_item| trait_item.ident.to_string())
.collect::<Vec<_>>().join("`, `"))); .collect::<Vec<_>>().join("`, `")));
for trait_item in missing_items { for trait_item in missing_items {
if let Some(span) = tcx.hir.span_if_local(trait_item.def_id) { if let Some(span) = tcx.hir.span_if_local(trait_item.def_id) {
err.span_label(span, format!("`{}` from trait", trait_item.name)); err.span_label(span, format!("`{}` from trait", trait_item.ident));
} else { } else {
err.note_trait_signature(trait_item.name.to_string(), err.note_trait_signature(trait_item.ident.to_string(),
trait_item.signature(&tcx)); trait_item.signature(&tcx));
} }
} }
@ -1527,7 +1525,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
span_err!(tcx.sess, invalidator.span, E0399, span_err!(tcx.sess, invalidator.span, E0399,
"the following trait items need to be reimplemented \ "the following trait items need to be reimplemented \
as `{}` was overridden: `{}`", as `{}` was overridden: `{}`",
invalidator.name, invalidator.ident,
invalidated_items.iter() invalidated_items.iter()
.map(|name| name.to_string()) .map(|name| name.to_string())
.collect::<Vec<_>>().join("`, `")) .collect::<Vec<_>>().join("`, `"))
@ -2470,7 +2468,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
None None
} }
fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, Symbol) { fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, ast::Ident) {
let (tr, name) = match (op, is_mut) { let (tr, name) = match (op, is_mut) {
(PlaceOp::Deref, false) => (PlaceOp::Deref, false) =>
(self.tcx.lang_items().deref_trait(), "deref"), (self.tcx.lang_items().deref_trait(), "deref"),
@ -2481,7 +2479,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(PlaceOp::Index, true) => (PlaceOp::Index, true) =>
(self.tcx.lang_items().index_mut_trait(), "index_mut"), (self.tcx.lang_items().index_mut_trait(), "index_mut"),
}; };
(tr, Symbol::intern(name)) (tr, ast::Ident::from_str(name))
} }
fn try_overloaded_place_op(&self, fn try_overloaded_place_op(&self,

View File

@ -18,7 +18,7 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoB
use rustc::infer::type_variable::TypeVariableOrigin; use rustc::infer::type_variable::TypeVariableOrigin;
use errors; use errors;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::symbol::Symbol; use syntax::ast::Ident;
use rustc::hir; use rustc::hir;
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
@ -564,7 +564,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
trait_did); trait_did);
let method = trait_did.and_then(|trait_did| { let method = trait_did.and_then(|trait_did| {
let opname = Symbol::intern(opname); let opname = Ident::from_str(opname);
self.lookup_method_in_trait(span, opname, trait_did, lhs_ty, Some(other_tys)) self.lookup_method_in_trait(span, opname, trait_did, lhs_ty, Some(other_tys))
}); });

View File

@ -35,7 +35,7 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
let name_and_namespace = |def_id| { let name_and_namespace = |def_id| {
let item = self.tcx.associated_item(def_id); let item = self.tcx.associated_item(def_id);
(item.name, Namespace::from(item.kind)) (item.ident, Namespace::from(item.kind))
}; };
let impl_items1 = self.tcx.associated_item_def_ids(impl1); let impl_items1 = self.tcx.associated_item_def_ids(impl1);

View File

@ -184,14 +184,14 @@ fn enforce_impl_items_are_distinct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
hir::ImplItemKind::Type(_) => &mut seen_type_items, hir::ImplItemKind::Type(_) => &mut seen_type_items,
_ => &mut seen_value_items, _ => &mut seen_value_items,
}; };
match seen_items.entry(impl_item.name) { match seen_items.entry(impl_item.ident.modern()) {
Occupied(entry) => { Occupied(entry) => {
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201, let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201,
"duplicate definitions with name `{}`:", "duplicate definitions with name `{}`:",
impl_item.name); impl_item.ident);
err.span_label(*entry.get(), err.span_label(*entry.get(),
format!("previous definition of `{}` here", format!("previous definition of `{}` here",
impl_item.name)); impl_item.ident));
err.span_label(impl_item.span, "duplicate definition"); err.span_label(impl_item.span, "duplicate definition");
err.emit(); err.emit();
} }

View File

@ -391,7 +391,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
let provided = trait_.def_id().map(|did| { let provided = trait_.def_id().map(|did| {
tcx.provided_trait_methods(did) tcx.provided_trait_methods(did)
.into_iter() .into_iter()
.map(|meth| meth.name.to_string()) .map(|meth| meth.ident.to_string())
.collect() .collect()
}).unwrap_or(FxHashSet()); }).unwrap_or(FxHashSet());

View File

@ -1146,7 +1146,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
Def::Struct(did) | Def::Union(did) | Def::Enum(did) | Def::TyAlias(did) => { Def::Struct(did) | Def::Union(did) | Def::Enum(did) | Def::TyAlias(did) => {
let item = cx.tcx.inherent_impls(did).iter() let item = cx.tcx.inherent_impls(did).iter()
.flat_map(|imp| cx.tcx.associated_items(*imp)) .flat_map(|imp| cx.tcx.associated_items(*imp))
.find(|item| item.name == item_name); .find(|item| item.ident.name == item_name);
if let Some(item) = item { if let Some(item) = item {
let out = match item.kind { let out = match item.kind {
ty::AssociatedKind::Method if is_val => "method", ty::AssociatedKind::Method if is_val => "method",
@ -1181,7 +1181,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
Def::Trait(did) => { Def::Trait(did) => {
let item = cx.tcx.associated_item_def_ids(did).iter() let item = cx.tcx.associated_item_def_ids(did).iter()
.map(|item| cx.tcx.associated_item(*item)) .map(|item| cx.tcx.associated_item(*item))
.find(|item| item.name == item_name); .find(|item| item.ident.name == item_name);
if let Some(item) = item { if let Some(item) = item {
let kind = match item.kind { let kind = match item.kind {
ty::AssociatedKind::Const if is_val => "associatedconstant", ty::AssociatedKind::Const if is_val => "associatedconstant",
@ -1823,7 +1823,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"), GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"),
}; };
Type::QPath { Type::QPath {
name: cx.tcx.associated_item(self.item_def_id).name.clean(cx), name: cx.tcx.associated_item(self.item_def_id).ident.name.clean(cx),
self_type: box self.self_ty().clean(cx), self_type: box self.self_ty().clean(cx),
trait_: box trait_ trait_: box trait_
} }
@ -2360,7 +2360,7 @@ impl Clean<Item> for hir::TraitItem {
} }
}; };
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),
def_id: cx.tcx.hir.local_def_id(self.id), def_id: cx.tcx.hir.local_def_id(self.id),
@ -2388,7 +2388,7 @@ impl Clean<Item> for hir::ImplItem {
}, true), }, true),
}; };
Item { Item {
name: Some(self.name.clean(cx)), name: Some(self.ident.name.clean(cx)),
source: self.span.clean(cx), source: self.span.clean(cx),
attrs: self.attrs.clean(cx), attrs: self.attrs.clean(cx),
def_id: cx.tcx.hir.local_def_id(self.id), def_id: cx.tcx.hir.local_def_id(self.id),
@ -2474,7 +2474,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
} }
} }
ty::AssociatedKind::Type => { ty::AssociatedKind::Type => {
let my_name = self.name.clean(cx); let my_name = self.ident.name.clean(cx);
if let ty::TraitContainer(did) = self.container { if let ty::TraitContainer(did) = self.container {
// When loading a cross-crate associated type, the bounds for this type // When loading a cross-crate associated type, the bounds for this type
@ -2537,7 +2537,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
}; };
Item { Item {
name: Some(self.name.clean(cx)), name: Some(self.ident.name.clean(cx)),
visibility, visibility,
stability: get_stability(cx, self.def_id), stability: get_stability(cx, self.def_id),
deprecation: get_deprecation(cx, self.def_id), deprecation: get_deprecation(cx, self.def_id),
@ -3099,7 +3099,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
let mut bindings = vec![]; let mut bindings = vec![];
for pb in obj.projection_bounds() { for pb in obj.projection_bounds() {
bindings.push(TypeBinding { bindings.push(TypeBinding {
name: cx.tcx.associated_item(pb.item_def_id()).name.clean(cx), name: cx.tcx.associated_item(pb.item_def_id()).ident.name.clean(cx),
ty: pb.skip_binder().ty.clean(cx) ty: pb.skip_binder().ty.clean(cx)
}); });
} }
@ -3156,7 +3156,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
if proj.projection_ty.trait_ref(cx.tcx) == *trait_ref.skip_binder() { if proj.projection_ty.trait_ref(cx.tcx) == *trait_ref.skip_binder() {
Some(TypeBinding { Some(TypeBinding {
name: cx.tcx.associated_item(proj.projection_ty.item_def_id) name: cx.tcx.associated_item(proj.projection_ty.item_def_id)
.name.clean(cx), .ident.name.clean(cx),
ty: proj.ty.clean(cx), ty: proj.ty.clean(cx),
}) })
} else { } else {
@ -3823,7 +3823,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
let provided = trait_.def_id().map(|did| { let provided = trait_.def_id().map(|did| {
cx.tcx.provided_trait_methods(did) cx.tcx.provided_trait_methods(did)
.into_iter() .into_iter()
.map(|meth| meth.name.to_string()) .map(|meth| meth.ident.to_string())
.collect() .collect()
}).unwrap_or(FxHashSet()); }).unwrap_or(FxHashSet());

View File

@ -718,13 +718,13 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
} }
fn visit_trait_item(&mut self, item: &'hir hir::TraitItem) { fn visit_trait_item(&mut self, item: &'hir hir::TraitItem) {
self.visit_testable(item.name.to_string(), &item.attrs, |this| { self.visit_testable(item.ident.to_string(), &item.attrs, |this| {
intravisit::walk_trait_item(this, item); intravisit::walk_trait_item(this, item);
}); });
} }
fn visit_impl_item(&mut self, item: &'hir hir::ImplItem) { fn visit_impl_item(&mut self, item: &'hir hir::ImplItem) {
self.visit_testable(item.name.to_string(), &item.attrs, |this| { self.visit_testable(item.ident.to_string(), &item.attrs, |this| {
intravisit::walk_impl_item(this, item); intravisit::walk_impl_item(this, item);
}); });
} }

View File

@ -18,7 +18,7 @@
use GLOBALS; use GLOBALS;
use Span; use Span;
use edition::Edition; use edition::Edition;
use symbol::{Ident, Symbol}; use symbol::Symbol;
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};
use std::collections::HashMap; use std::collections::HashMap;
@ -190,7 +190,6 @@ pub struct HygieneData {
marks: Vec<MarkData>, marks: Vec<MarkData>,
syntax_contexts: Vec<SyntaxContextData>, syntax_contexts: Vec<SyntaxContextData>,
markings: HashMap<(SyntaxContext, Mark), SyntaxContext>, markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
gensym_to_ctxt: HashMap<Symbol, Span>,
default_edition: Edition, default_edition: Edition,
} }
@ -211,7 +210,6 @@ impl HygieneData {
modern: SyntaxContext(0), modern: SyntaxContext(0),
}], }],
markings: HashMap::new(), markings: HashMap::new(),
gensym_to_ctxt: HashMap::new(),
default_edition: Edition::Edition2015, default_edition: Edition::Edition2015,
} }
} }
@ -559,22 +557,3 @@ impl Decodable for SyntaxContext {
Ok(SyntaxContext::empty()) // FIXME(jseyfried) intercrate hygiene Ok(SyntaxContext::empty()) // FIXME(jseyfried) intercrate hygiene
} }
} }
impl Symbol {
pub fn from_ident(ident: Ident) -> Symbol {
HygieneData::with(|data| {
let gensym = ident.name.gensymed();
data.gensym_to_ctxt.insert(gensym, ident.span);
gensym
})
}
pub fn to_ident(self) -> Ident {
HygieneData::with(|data| {
match data.gensym_to_ctxt.get(&self) {
Some(&span) => Ident::new(self.interned(), span),
None => Ident::with_empty_ctxt(self),
}
})
}
}