Auto merge of #51492 - petrochenkov:hirident, r=eddyb
Use `Ident`s in HIR and remove emulation of hygiene with gensyms continuation of https://github.com/rust-lang/rust/pull/51072, part of https://github.com/rust-lang/rust/issues/49300 Not all `Name`s in HIR are replaced with `Ident`s, only those needed for hygiene or already having attached spans.
This commit is contained in:
commit
d84ad59710
@ -57,7 +57,7 @@ pub enum FnKind<'a> {
|
||||
ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
|
||||
|
||||
/// fn foo(&self)
|
||||
Method(Name, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
|
||||
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
|
||||
|
||||
/// |x, y| {}
|
||||
Closure(&'a [Attribute]),
|
||||
@ -426,14 +426,14 @@ pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
|
||||
}
|
||||
|
||||
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
|
||||
visitor.visit_name(label.span, label.name);
|
||||
visitor.visit_ident(label.ident);
|
||||
}
|
||||
|
||||
pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
|
||||
visitor.visit_id(lifetime.id);
|
||||
match lifetime.name {
|
||||
LifetimeName::Param(ParamName::Plain(name)) => {
|
||||
visitor.visit_name(lifetime.span, name);
|
||||
LifetimeName::Param(ParamName::Plain(ident)) => {
|
||||
visitor.visit_ident(ident);
|
||||
}
|
||||
LifetimeName::Param(ParamName::Fresh(_)) |
|
||||
LifetimeName::Static |
|
||||
@ -644,7 +644,7 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
|
||||
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
path_span: Span,
|
||||
segment: &'v PathSegment) {
|
||||
visitor.visit_name(path_span, segment.name);
|
||||
visitor.visit_ident(segment.ident);
|
||||
if let Some(ref args) = segment.args {
|
||||
visitor.visit_generic_args(path_span, args);
|
||||
}
|
||||
@ -660,7 +660,7 @@ pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
type_binding: &'v TypeBinding) {
|
||||
visitor.visit_id(type_binding.id);
|
||||
visitor.visit_name(type_binding.span, type_binding.name);
|
||||
visitor.visit_ident(type_binding.ident);
|
||||
visitor.visit_ty(&type_binding.ty);
|
||||
}
|
||||
|
||||
@ -689,9 +689,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
||||
PatKind::Ref(ref subpattern, _) => {
|
||||
visitor.visit_pat(subpattern)
|
||||
}
|
||||
PatKind::Binding(_, canonical_id, ref pth1, ref optional_subpattern) => {
|
||||
PatKind::Binding(_, canonical_id, ident, ref optional_subpattern) => {
|
||||
visitor.visit_def_mention(Def::Local(canonical_id));
|
||||
visitor.visit_name(pth1.span, pth1.node);
|
||||
visitor.visit_ident(ident);
|
||||
walk_list!(visitor, visit_pat, optional_subpattern);
|
||||
}
|
||||
PatKind::Lit(ref expression) => visitor.visit_expr(expression),
|
||||
@ -714,11 +714,11 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
|
||||
visitor.visit_name(foreign_item.span, foreign_item.name);
|
||||
|
||||
match foreign_item.node {
|
||||
ForeignItemFn(ref function_declaration, ref names, ref generics) => {
|
||||
ForeignItemFn(ref function_declaration, ref param_names, ref generics) => {
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_fn_decl(function_declaration);
|
||||
for name in names {
|
||||
visitor.visit_name(name.span, name.node);
|
||||
for ¶m_name in param_names {
|
||||
visitor.visit_ident(param_name);
|
||||
}
|
||||
}
|
||||
ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ),
|
||||
@ -741,7 +741,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
|
||||
visitor.visit_id(param.id);
|
||||
walk_list!(visitor, visit_attribute, ¶m.attrs);
|
||||
match param.name {
|
||||
ParamName::Plain(name) => visitor.visit_name(param.span, name),
|
||||
ParamName::Plain(ident) => visitor.visit_ident(ident),
|
||||
ParamName::Fresh(_) => {}
|
||||
}
|
||||
match param.kind {
|
||||
@ -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) {
|
||||
visitor.visit_name(trait_item.span, trait_item.name);
|
||||
visitor.visit_ident(trait_item.ident);
|
||||
walk_list!(visitor, visit_attribute, &trait_item.attrs);
|
||||
visitor.visit_generics(&trait_item.generics);
|
||||
match trait_item.node {
|
||||
@ -832,15 +832,15 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
|
||||
visitor.visit_ty(ty);
|
||||
walk_list!(visitor, visit_nested_body, default);
|
||||
}
|
||||
TraitItemKind::Method(ref sig, TraitMethod::Required(ref names)) => {
|
||||
TraitItemKind::Method(ref sig, TraitMethod::Required(ref param_names)) => {
|
||||
visitor.visit_id(trait_item.id);
|
||||
visitor.visit_fn_decl(&sig.decl);
|
||||
for name in names {
|
||||
visitor.visit_name(name.span, name.node);
|
||||
for ¶m_name in param_names {
|
||||
visitor.visit_ident(param_name);
|
||||
}
|
||||
}
|
||||
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,
|
||||
None,
|
||||
&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) {
|
||||
// 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_name(span, name);
|
||||
visitor.visit_ident(ident);
|
||||
visitor.visit_associated_item_kind(kind);
|
||||
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 {
|
||||
id: _,
|
||||
hir_id: _,
|
||||
name,
|
||||
ident,
|
||||
ref vis,
|
||||
ref defaultness,
|
||||
ref attrs,
|
||||
ref generics,
|
||||
ref node,
|
||||
span
|
||||
span: _,
|
||||
} = *impl_item;
|
||||
|
||||
visitor.visit_name(span, name);
|
||||
visitor.visit_ident(ident);
|
||||
visitor.visit_vis(vis);
|
||||
visitor.visit_defaultness(defaultness);
|
||||
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);
|
||||
}
|
||||
ImplItemKind::Method(ref sig, body_id) => {
|
||||
visitor.visit_fn(FnKind::Method(impl_item.name,
|
||||
visitor.visit_fn(FnKind::Method(impl_item.ident,
|
||||
sig,
|
||||
Some(&impl_item.vis),
|
||||
&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) {
|
||||
// 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_name(span, name);
|
||||
visitor.visit_ident(ident);
|
||||
visitor.visit_associated_item_kind(kind);
|
||||
visitor.visit_vis(vis);
|
||||
visitor.visit_defaultness(defaultness);
|
||||
|
@ -52,7 +52,7 @@ use middle::cstore::CrateStore;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use session::Session;
|
||||
use util::common::FN_OUTPUT_NAME;
|
||||
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
|
||||
use util::nodemap::{DefIdMap, NodeMap};
|
||||
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::fmt::Debug;
|
||||
@ -85,7 +85,6 @@ pub struct LoweringContext<'a> {
|
||||
cstore: &'a CrateStore,
|
||||
|
||||
resolver: &'a mut Resolver,
|
||||
name_map: FxHashMap<Ident, Name>,
|
||||
|
||||
/// The items being lowered are collected here.
|
||||
items: BTreeMap<NodeId, hir::Item>,
|
||||
@ -138,7 +137,7 @@ pub struct LoweringContext<'a> {
|
||||
// When `is_collectin_in_band_lifetimes` is true, each lifetime is checked
|
||||
// against this list to see if it is already in-scope, or if a definition
|
||||
// needs to be created for it.
|
||||
in_scope_lifetimes: Vec<Name>,
|
||||
in_scope_lifetimes: Vec<Ident>,
|
||||
|
||||
type_def_lifetime_params: DefIdMap<usize>,
|
||||
|
||||
@ -210,7 +209,6 @@ pub fn lower_crate(
|
||||
sess,
|
||||
cstore,
|
||||
resolver,
|
||||
name_map: FxHashMap(),
|
||||
items: BTreeMap::new(),
|
||||
trait_items: BTreeMap::new(),
|
||||
impl_items: BTreeMap::new(),
|
||||
@ -604,8 +602,8 @@ impl<'a> LoweringContext<'a> {
|
||||
self.sess.diagnostic()
|
||||
}
|
||||
|
||||
fn str_to_ident(&self, s: &'static str) -> Name {
|
||||
Symbol::gensym(s)
|
||||
fn str_to_ident(&self, s: &'static str) -> Ident {
|
||||
Ident::with_empty_ctxt(Symbol::gensym(s))
|
||||
}
|
||||
|
||||
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
|
||||
@ -678,15 +676,15 @@ impl<'a> LoweringContext<'a> {
|
||||
// that collisions are ok here and this shouldn't
|
||||
// really show up for end-user.
|
||||
let str_name = match hir_name {
|
||||
ParamName::Plain(name) => name.as_str(),
|
||||
ParamName::Fresh(_) => keywords::UnderscoreLifetime.name().as_str(),
|
||||
ParamName::Plain(ident) => ident.as_interned_str(),
|
||||
ParamName::Fresh(_) => keywords::UnderscoreLifetime.name().as_interned_str(),
|
||||
};
|
||||
|
||||
// Add a definition for the in-band lifetime def
|
||||
self.resolver.definitions().create_def_with_parent(
|
||||
parent_id.index,
|
||||
def_node_id,
|
||||
DefPathData::LifetimeParam(str_name.as_interned_str()),
|
||||
DefPathData::LifetimeParam(str_name),
|
||||
DefIndexAddressSpace::High,
|
||||
Mark::root(),
|
||||
span,
|
||||
@ -712,22 +710,23 @@ impl<'a> LoweringContext<'a> {
|
||||
/// lifetimes are enabled, then we want to push that lifetime into
|
||||
/// the vector of names to define later. In that case, it will get
|
||||
/// added to the appropriate generics.
|
||||
fn maybe_collect_in_band_lifetime(&mut self, span: Span, name: Name) {
|
||||
fn maybe_collect_in_band_lifetime(&mut self, ident: Ident) {
|
||||
if !self.is_collecting_in_band_lifetimes {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.in_scope_lifetimes.contains(&name) {
|
||||
if self.in_scope_lifetimes.contains(&ident.modern()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let hir_name = ParamName::Plain(name);
|
||||
let hir_name = ParamName::Plain(ident);
|
||||
|
||||
if self.lifetimes_to_define.iter().any(|(_, lt_name)| *lt_name == hir_name) {
|
||||
if self.lifetimes_to_define.iter()
|
||||
.any(|(_, lt_name)| lt_name.modern() == hir_name.modern()) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.lifetimes_to_define.push((span, hir_name));
|
||||
self.lifetimes_to_define.push((ident.span, hir_name));
|
||||
}
|
||||
|
||||
/// When we have either an elided or `'_` lifetime in an impl
|
||||
@ -750,7 +749,7 @@ impl<'a> LoweringContext<'a> {
|
||||
{
|
||||
let old_len = self.in_scope_lifetimes.len();
|
||||
let lt_def_names = params.iter().filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => Some(param.ident.name),
|
||||
GenericParamKind::Lifetime { .. } => Some(param.ident.modern()),
|
||||
_ => None,
|
||||
});
|
||||
self.in_scope_lifetimes.extend(lt_def_names);
|
||||
@ -774,7 +773,7 @@ impl<'a> LoweringContext<'a> {
|
||||
{
|
||||
let old_len = self.in_scope_lifetimes.len();
|
||||
let lt_def_names = params.iter().filter_map(|param| match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => Some(param.name.name()),
|
||||
hir::GenericParamKind::Lifetime { .. } => Some(param.name.ident().modern()),
|
||||
_ => None,
|
||||
});
|
||||
self.in_scope_lifetimes.extend(lt_def_names);
|
||||
@ -956,20 +955,9 @@ 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> {
|
||||
label.map(|label| hir::Label {
|
||||
name: label.ident.name,
|
||||
span: label.ident.span,
|
||||
ident: label.ident,
|
||||
})
|
||||
}
|
||||
|
||||
@ -1063,7 +1051,7 @@ impl<'a> LoweringContext<'a> {
|
||||
fn lower_ty_binding(&mut self, b: &TypeBinding, itctx: ImplTraitContext) -> hir::TypeBinding {
|
||||
hir::TypeBinding {
|
||||
id: self.lower_node_id(b.id).node_id,
|
||||
name: self.lower_ident(b.ident),
|
||||
ident: b.ident,
|
||||
ty: self.lower_ty(&b.ty, itctx),
|
||||
span: b.span,
|
||||
}
|
||||
@ -1138,7 +1126,7 @@ impl<'a> LoweringContext<'a> {
|
||||
None,
|
||||
P(hir::Path {
|
||||
def: self.expect_full_def(t.id),
|
||||
segments: hir_vec![hir::PathSegment::from_name(keywords::SelfType.name())],
|
||||
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfType.ident())],
|
||||
span: t.span,
|
||||
}),
|
||||
)),
|
||||
@ -1194,14 +1182,14 @@ impl<'a> LoweringContext<'a> {
|
||||
|
||||
let hir_bounds = self.lower_param_bounds(bounds, itctx);
|
||||
// Set the name to `impl Bound1 + Bound2`
|
||||
let name = Symbol::intern(&pprust::ty_to_string(t));
|
||||
let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span);
|
||||
self.in_band_ty_params.push(hir::GenericParam {
|
||||
id: def_node_id,
|
||||
name: ParamName::Plain(name),
|
||||
span,
|
||||
name: ParamName::Plain(ident),
|
||||
pure_wrt_drop: false,
|
||||
attrs: hir_vec![],
|
||||
bounds: hir_bounds,
|
||||
span,
|
||||
kind: hir::GenericParamKind::Type {
|
||||
default: None,
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
@ -1213,7 +1201,7 @@ impl<'a> LoweringContext<'a> {
|
||||
P(hir::Path {
|
||||
span,
|
||||
def: Def::TyParam(DefId::local(def_index)),
|
||||
segments: hir_vec![hir::PathSegment::from_name(name)],
|
||||
segments: hir_vec![hir::PathSegment::from_ident(ident)],
|
||||
}),
|
||||
))
|
||||
}
|
||||
@ -1443,7 +1431,7 @@ impl<'a> LoweringContext<'a> {
|
||||
self.context.resolver.definitions().create_def_with_parent(
|
||||
self.parent,
|
||||
def_node_id,
|
||||
DefPathData::LifetimeParam(name.name().as_interned_str()),
|
||||
DefPathData::LifetimeParam(name.ident().as_interned_str()),
|
||||
DefIndexAddressSpace::High,
|
||||
Mark::root(),
|
||||
lifetime.span,
|
||||
@ -1451,7 +1439,7 @@ impl<'a> LoweringContext<'a> {
|
||||
|
||||
let name = match name {
|
||||
hir::LifetimeName::Underscore => {
|
||||
hir::ParamName::Plain(keywords::UnderscoreLifetime.name())
|
||||
hir::ParamName::Plain(keywords::UnderscoreLifetime.ident())
|
||||
}
|
||||
hir::LifetimeName::Param(param_name) => param_name,
|
||||
_ => bug!("expected LifetimeName::Param or ParamName::Plain"),
|
||||
@ -1688,7 +1676,7 @@ impl<'a> LoweringContext<'a> {
|
||||
&mut self,
|
||||
def: Def,
|
||||
p: &Path,
|
||||
name: Option<Name>,
|
||||
ident: Option<Ident>,
|
||||
param_mode: ParamMode,
|
||||
) -> hir::Path {
|
||||
hir::Path {
|
||||
@ -1705,7 +1693,7 @@ impl<'a> LoweringContext<'a> {
|
||||
ImplTraitContext::Disallowed,
|
||||
)
|
||||
})
|
||||
.chain(name.map(|name| hir::PathSegment::from_name(name)))
|
||||
.chain(ident.map(|ident| hir::PathSegment::from_ident(ident)))
|
||||
.collect(),
|
||||
span: p.span,
|
||||
}
|
||||
@ -1768,7 +1756,7 @@ impl<'a> LoweringContext<'a> {
|
||||
}
|
||||
|
||||
hir::PathSegment::new(
|
||||
self.lower_ident(segment.ident),
|
||||
segment.ident,
|
||||
generic_args,
|
||||
infer_types,
|
||||
)
|
||||
@ -1819,7 +1807,7 @@ impl<'a> LoweringContext<'a> {
|
||||
bindings: hir_vec![
|
||||
hir::TypeBinding {
|
||||
id: this.next_id().node_id,
|
||||
name: Symbol::intern(FN_OUTPUT_NAME),
|
||||
ident: Ident::from_str(FN_OUTPUT_NAME),
|
||||
ty: output
|
||||
.as_ref()
|
||||
.map(|ty| this.lower_ty(&ty, DISALLOWED))
|
||||
@ -1867,12 +1855,12 @@ impl<'a> LoweringContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Spanned<Name>> {
|
||||
fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
|
||||
decl.inputs
|
||||
.iter()
|
||||
.map(|arg| match arg.pat.node {
|
||||
PatKind::Ident(_, ident, None) => respan(ident.span, ident.name),
|
||||
_ => respan(arg.pat.span, keywords::Invalid.name()),
|
||||
PatKind::Ident(_, ident, _) => ident,
|
||||
_ => Ident::new(keywords::Invalid.name(), arg.pat.span),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@ -2114,7 +2102,7 @@ impl<'a> LoweringContext<'a> {
|
||||
let future_params = P(hir::GenericArgs {
|
||||
args: hir_vec![],
|
||||
bindings: hir_vec![hir::TypeBinding {
|
||||
name: Symbol::intern(FN_OUTPUT_NAME),
|
||||
ident: Ident::from_str(FN_OUTPUT_NAME),
|
||||
ty: output_ty,
|
||||
id: this.next_id().node_id,
|
||||
span,
|
||||
@ -2176,21 +2164,23 @@ impl<'a> LoweringContext<'a> {
|
||||
|
||||
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
|
||||
let span = l.ident.span;
|
||||
match self.lower_ident(l.ident) {
|
||||
x if x == "'static" => self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
|
||||
x if x == "'_" => match self.anonymous_lifetime_mode {
|
||||
AnonymousLifetimeMode::CreateParameter => {
|
||||
let fresh_name = self.collect_fresh_in_band_lifetime(span);
|
||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(fresh_name))
|
||||
}
|
||||
match l.ident {
|
||||
ident if ident.name == keywords::StaticLifetime.name() =>
|
||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
|
||||
ident if ident.name == keywords::UnderscoreLifetime.name() =>
|
||||
match self.anonymous_lifetime_mode {
|
||||
AnonymousLifetimeMode::CreateParameter => {
|
||||
let fresh_name = self.collect_fresh_in_band_lifetime(span);
|
||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(fresh_name))
|
||||
}
|
||||
|
||||
AnonymousLifetimeMode::PassThrough => {
|
||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Underscore)
|
||||
}
|
||||
},
|
||||
name => {
|
||||
self.maybe_collect_in_band_lifetime(span, name);
|
||||
let param_name = ParamName::Plain(name);
|
||||
AnonymousLifetimeMode::PassThrough => {
|
||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Underscore)
|
||||
}
|
||||
},
|
||||
ident => {
|
||||
self.maybe_collect_in_band_lifetime(ident);
|
||||
let param_name = ParamName::Plain(ident);
|
||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(param_name))
|
||||
}
|
||||
}
|
||||
@ -2232,7 +2222,7 @@ impl<'a> LoweringContext<'a> {
|
||||
let lt = self.lower_lifetime(&Lifetime { id: param.id, ident: param.ident });
|
||||
let param_name = match lt.name {
|
||||
hir::LifetimeName::Param(param_name) => param_name,
|
||||
_ => hir::ParamName::Plain(lt.name.name()),
|
||||
_ => hir::ParamName::Plain(lt.name.ident()),
|
||||
};
|
||||
let param = hir::GenericParam {
|
||||
id: lt.id,
|
||||
@ -2249,14 +2239,14 @@ impl<'a> LoweringContext<'a> {
|
||||
param
|
||||
}
|
||||
GenericParamKind::Type { ref default, .. } => {
|
||||
let mut name = self.lower_ident(param.ident);
|
||||
|
||||
// Don't expose `Self` (recovered "keyword used as ident" parse error).
|
||||
// `rustc::ty` expects `Self` to be only used for a trait's `Self`.
|
||||
// Instead, use gensym("Self") to create a distinct name that looks the same.
|
||||
if name == keywords::SelfType.name() {
|
||||
name = Symbol::gensym("Self");
|
||||
}
|
||||
let ident = if param.ident.name == keywords::SelfType.name() {
|
||||
param.ident.gensym()
|
||||
} else {
|
||||
param.ident
|
||||
};
|
||||
|
||||
let add_bounds = add_bounds.get(¶m.id).map_or(&[][..], |x| &x);
|
||||
if !add_bounds.is_empty() {
|
||||
@ -2267,11 +2257,11 @@ impl<'a> LoweringContext<'a> {
|
||||
|
||||
hir::GenericParam {
|
||||
id: self.lower_node_id(param.id).node_id,
|
||||
name: hir::ParamName::Plain(name),
|
||||
span: param.ident.span,
|
||||
name: hir::ParamName::Plain(ident),
|
||||
pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"),
|
||||
attrs: self.lower_attrs(¶m.attrs),
|
||||
bounds,
|
||||
span: ident.span,
|
||||
kind: hir::GenericParamKind::Type {
|
||||
default: default.as_ref().map(|x| {
|
||||
self.lower_ty(x, ImplTraitContext::Disallowed)
|
||||
@ -2961,7 +2951,7 @@ impl<'a> LoweringContext<'a> {
|
||||
hir::TraitItem {
|
||||
id: node_id,
|
||||
hir_id,
|
||||
name: self.lower_ident(i.ident),
|
||||
ident: i.ident,
|
||||
attrs: self.lower_attrs(&i.attrs),
|
||||
generics,
|
||||
node,
|
||||
@ -2987,7 +2977,7 @@ impl<'a> LoweringContext<'a> {
|
||||
};
|
||||
hir::TraitItemRef {
|
||||
id: hir::TraitItemId { node_id: i.id },
|
||||
name: self.lower_ident(i.ident),
|
||||
ident: i.ident,
|
||||
span: i.span,
|
||||
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
|
||||
kind,
|
||||
@ -3053,7 +3043,7 @@ impl<'a> LoweringContext<'a> {
|
||||
hir::ImplItem {
|
||||
id: node_id,
|
||||
hir_id,
|
||||
name: self.lower_ident(i.ident),
|
||||
ident: i.ident,
|
||||
attrs: self.lower_attrs(&i.attrs),
|
||||
generics,
|
||||
vis: self.lower_visibility(&i.vis, None),
|
||||
@ -3068,7 +3058,7 @@ impl<'a> LoweringContext<'a> {
|
||||
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
|
||||
hir::ImplItemRef {
|
||||
id: hir::ImplItemId { node_id: i.id },
|
||||
name: self.lower_ident(i.ident),
|
||||
ident: i.ident,
|
||||
span: i.span,
|
||||
vis: self.lower_visibility(&i.vis, Some(i.id)),
|
||||
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
|
||||
@ -3295,7 +3285,7 @@ impl<'a> LoweringContext<'a> {
|
||||
hir::PatKind::Binding(
|
||||
self.lower_binding_mode(binding_mode),
|
||||
canonical_id,
|
||||
respan(ident.span, ident.name),
|
||||
ident,
|
||||
sub.as_ref().map(|x| self.lower_pat(x)),
|
||||
)
|
||||
}
|
||||
@ -3304,7 +3294,7 @@ impl<'a> LoweringContext<'a> {
|
||||
P(hir::Path {
|
||||
span: ident.span,
|
||||
def,
|
||||
segments: hir_vec![hir::PathSegment::from_name(ident.name)],
|
||||
segments: hir_vec![hir::PathSegment::from_ident(ident)],
|
||||
}),
|
||||
)),
|
||||
}
|
||||
@ -3667,7 +3657,7 @@ impl<'a> LoweringContext<'a> {
|
||||
let e2 = self.lower_expr(e2);
|
||||
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], None, false));
|
||||
let ty = P(self.ty_path(id, span, hir::QPath::Resolved(None, ty_path)));
|
||||
let new_seg = P(hir::PathSegment::from_name(Symbol::intern("new")));
|
||||
let new_seg = P(hir::PathSegment::from_ident(Ident::from_str("new")));
|
||||
let new_path = hir::QPath::TypeRelative(ty, new_seg);
|
||||
let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new()));
|
||||
hir::ExprCall(new, hir_vec![e1, e2])
|
||||
@ -4337,14 +4327,14 @@ impl<'a> LoweringContext<'a> {
|
||||
self.expr(span, hir::ExprCall(e, args), ThinVec::new())
|
||||
}
|
||||
|
||||
fn expr_ident(&mut self, span: Span, id: Name, binding: NodeId) -> hir::Expr {
|
||||
self.expr_ident_with_attrs(span, id, binding, ThinVec::new())
|
||||
fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr {
|
||||
self.expr_ident_with_attrs(span, ident, binding, ThinVec::new())
|
||||
}
|
||||
|
||||
fn expr_ident_with_attrs(
|
||||
&mut self,
|
||||
span: Span,
|
||||
id: Name,
|
||||
ident: Ident,
|
||||
binding: NodeId,
|
||||
attrs: ThinVec<Attribute>,
|
||||
) -> hir::Expr {
|
||||
@ -4353,7 +4343,7 @@ impl<'a> LoweringContext<'a> {
|
||||
P(hir::Path {
|
||||
span,
|
||||
def: Def::Local(binding),
|
||||
segments: hir_vec![hir::PathSegment::from_name(id)],
|
||||
segments: hir_vec![hir::PathSegment::from_ident(ident)],
|
||||
}),
|
||||
));
|
||||
|
||||
@ -4435,7 +4425,7 @@ impl<'a> LoweringContext<'a> {
|
||||
&mut self,
|
||||
sp: Span,
|
||||
mutbl: bool,
|
||||
ident: Name,
|
||||
ident: Ident,
|
||||
ex: P<hir::Expr>,
|
||||
) -> (hir::Stmt, NodeId) {
|
||||
let pat = if mutbl {
|
||||
@ -4506,14 +4496,14 @@ impl<'a> LoweringContext<'a> {
|
||||
self.pat(span, pt)
|
||||
}
|
||||
|
||||
fn pat_ident(&mut self, span: Span, name: Name) -> P<hir::Pat> {
|
||||
self.pat_ident_binding_mode(span, name, hir::BindingAnnotation::Unannotated)
|
||||
fn pat_ident(&mut self, span: Span, ident: Ident) -> P<hir::Pat> {
|
||||
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
|
||||
}
|
||||
|
||||
fn pat_ident_binding_mode(
|
||||
&mut self,
|
||||
span: Span,
|
||||
name: Name,
|
||||
ident: Ident,
|
||||
bm: hir::BindingAnnotation,
|
||||
) -> P<hir::Pat> {
|
||||
let LoweredNodeId { node_id, hir_id } = self.next_id();
|
||||
@ -4521,7 +4511,7 @@ impl<'a> LoweringContext<'a> {
|
||||
P(hir::Pat {
|
||||
id: node_id,
|
||||
hir_id,
|
||||
node: hir::PatKind::Binding(bm, node_id, Spanned { span, node: name }, None),
|
||||
node: hir::PatKind::Binding(bm, node_id, ident.with_span_pos(span), None),
|
||||
span,
|
||||
})
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use hir as ast;
|
||||
use hir::map::{self, Node};
|
||||
use hir::{Expr, FnDecl};
|
||||
use hir::intravisit::FnKind;
|
||||
use syntax::ast::{Attribute, Name, NodeId};
|
||||
use syntax::ast::{Attribute, Ident, Name, NodeId};
|
||||
use syntax_pos::Span;
|
||||
|
||||
/// 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>| {
|
||||
FnKind::Closure(c.attrs)
|
||||
};
|
||||
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _, attrs| {
|
||||
FnKind::Method(name, sig, vis, attrs)
|
||||
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
|
||||
FnKind::Method(ident, sig, vis, attrs)
|
||||
};
|
||||
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
|
||||
I: FnOnce(ItemFnParts<'a>) -> A,
|
||||
M: FnOnce(NodeId,
|
||||
Name,
|
||||
Ident,
|
||||
&'a ast::MethodSig,
|
||||
Option<&'a ast::Visibility>,
|
||||
ast::BodyId,
|
||||
@ -245,14 +245,14 @@ impl<'a> FnLikeNode<'a> {
|
||||
},
|
||||
map::NodeTraitItem(ti) => match ti.node {
|
||||
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"),
|
||||
},
|
||||
map::NodeImplItem(ii) => {
|
||||
match ii.node {
|
||||
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")
|
||||
|
@ -495,7 +495,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
// map the actual nodes, not the duplicate ones in the *Ref.
|
||||
let TraitItemRef {
|
||||
id,
|
||||
name: _,
|
||||
ident: _,
|
||||
kind: _,
|
||||
span: _,
|
||||
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.
|
||||
let ImplItemRef {
|
||||
id,
|
||||
name: _,
|
||||
ident: _,
|
||||
kind: _,
|
||||
span: _,
|
||||
vis: _,
|
||||
|
@ -112,11 +112,11 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
// information we encapsulate into, the better
|
||||
let def_data = match i.node {
|
||||
ItemKind::Impl(..) => DefPathData::Impl,
|
||||
ItemKind::Trait(..) => DefPathData::Trait(i.ident.name.as_interned_str()),
|
||||
ItemKind::Trait(..) => DefPathData::Trait(i.ident.as_interned_str()),
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
|
||||
ItemKind::TraitAlias(..) |
|
||||
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
|
||||
DefPathData::TypeNs(i.ident.name.as_interned_str()),
|
||||
DefPathData::TypeNs(i.ident.as_interned_str()),
|
||||
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
|
||||
return visit::walk_item(self, i);
|
||||
}
|
||||
@ -129,10 +129,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
|this| visit::walk_item(this, i)
|
||||
)
|
||||
}
|
||||
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_interned_str()),
|
||||
ItemKind::Mod(..) => DefPathData::Module(i.ident.as_interned_str()),
|
||||
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
|
||||
DefPathData::ValueNs(i.ident.name.as_interned_str()),
|
||||
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name.as_interned_str()),
|
||||
DefPathData::ValueNs(i.ident.as_interned_str()),
|
||||
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.as_interned_str()),
|
||||
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id),
|
||||
ItemKind::GlobalAsm(..) => DefPathData::Misc,
|
||||
ItemKind::Use(..) => {
|
||||
@ -169,7 +169,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
}
|
||||
|
||||
let def = self.create_def(foreign_item.id,
|
||||
DefPathData::ValueNs(foreign_item.ident.name.as_interned_str()),
|
||||
DefPathData::ValueNs(foreign_item.ident.as_interned_str()),
|
||||
REGULAR_SPACE,
|
||||
foreign_item.span);
|
||||
|
||||
@ -180,8 +180,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
|
||||
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
|
||||
let def = self.create_def(v.node.data.id(),
|
||||
DefPathData::EnumVariant(v.node.ident
|
||||
.name.as_interned_str()),
|
||||
DefPathData::EnumVariant(v.node.ident.as_interned_str()),
|
||||
REGULAR_SPACE,
|
||||
v.span);
|
||||
self.with_parent(def, |this| visit::walk_variant(this, v, g, item_id));
|
||||
@ -201,7 +200,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
}
|
||||
|
||||
fn visit_generic_param(&mut self, param: &'a GenericParam) {
|
||||
let name = param.ident.name.as_interned_str();
|
||||
let name = param.ident.as_interned_str();
|
||||
let def_path_data = match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeParam(name),
|
||||
GenericParamKind::Type { .. } => DefPathData::TypeParam(name),
|
||||
@ -214,9 +213,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
|
||||
let def_data = match ti.node {
|
||||
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ti.ident.name.as_interned_str()),
|
||||
DefPathData::ValueNs(ti.ident.as_interned_str()),
|
||||
TraitItemKind::Type(..) => {
|
||||
DefPathData::AssocTypeInTrait(ti.ident.name.as_interned_str())
|
||||
DefPathData::AssocTypeInTrait(ti.ident.as_interned_str())
|
||||
},
|
||||
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
|
||||
};
|
||||
@ -239,8 +238,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||
)
|
||||
}
|
||||
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ii.ident.name.as_interned_str()),
|
||||
ImplItemKind::Type(..) => DefPathData::AssocTypeInImpl(ii.ident.name.as_interned_str()),
|
||||
DefPathData::ValueNs(ii.ident.as_interned_str()),
|
||||
ImplItemKind::Type(..) => DefPathData::AssocTypeInImpl(ii.ident.as_interned_str()),
|
||||
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
|
||||
};
|
||||
|
||||
|
@ -616,7 +616,7 @@ impl<'hir> Map<'hir> {
|
||||
NodeItem(&Item { node: ItemTrait(..), .. }) => {
|
||||
keywords::SelfType.name()
|
||||
}
|
||||
NodeGenericParam(param) => param.name.name(),
|
||||
NodeGenericParam(param) => param.name.ident().name,
|
||||
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
|
||||
}
|
||||
}
|
||||
@ -949,13 +949,13 @@ impl<'hir> Map<'hir> {
|
||||
match self.get(id) {
|
||||
NodeItem(i) => i.name,
|
||||
NodeForeignItem(i) => i.name,
|
||||
NodeImplItem(ii) => ii.name,
|
||||
NodeTraitItem(ti) => ti.name,
|
||||
NodeImplItem(ii) => ii.ident.name,
|
||||
NodeTraitItem(ti) => ti.ident.name,
|
||||
NodeVariant(v) => v.node.name,
|
||||
NodeField(f) => f.ident.name,
|
||||
NodeLifetime(lt) => lt.name.name(),
|
||||
NodeGenericParam(param) => param.name.name(),
|
||||
NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
|
||||
NodeLifetime(lt) => lt.name.ident().name,
|
||||
NodeGenericParam(param) => param.name.ident().name,
|
||||
NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.name,
|
||||
NodeStructCtor(_) => self.name(self.get_parent(id)),
|
||||
_ => bug!("no name for {}", self.node_to_string(id))
|
||||
}
|
||||
@ -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 Variant_ { fn name(&self) -> Name { self.name } }
|
||||
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
|
||||
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
|
||||
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
|
||||
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
|
||||
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
|
||||
|
||||
|
||||
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)) => {
|
||||
match ii.node {
|
||||
ImplItemKind::Const(..) => {
|
||||
format!("assoc const {} in {}{}", ii.name, path_str(), id_str)
|
||||
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
|
||||
}
|
||||
ImplItemKind::Method(..) => {
|
||||
format!("method {} in {}{}", ii.name, path_str(), id_str)
|
||||
format!("method {} in {}{}", ii.ident, path_str(), id_str)
|
||||
}
|
||||
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",
|
||||
};
|
||||
|
||||
format!("{} {} in {}{}", kind, ti.name, path_str(), id_str)
|
||||
format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str)
|
||||
}
|
||||
Some(NodeVariant(ref variant)) => {
|
||||
format!("variant {} in {}{}",
|
||||
|
@ -175,13 +175,12 @@ pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId(!0);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub struct Label {
|
||||
pub name: Name,
|
||||
pub span: Span,
|
||||
pub ident: Ident,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Label {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "label({:?})", self.name)
|
||||
write!(f, "label({:?})", self.ident)
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +201,7 @@ pub struct Lifetime {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub enum ParamName {
|
||||
/// Some user-given name like `T` or `'x`.
|
||||
Plain(Name),
|
||||
Plain(Ident),
|
||||
|
||||
/// Synthetic name generated when user elided a lifetime in an impl header,
|
||||
/// e.g. the lifetimes in cases like these:
|
||||
@ -221,10 +220,17 @@ pub enum ParamName {
|
||||
}
|
||||
|
||||
impl ParamName {
|
||||
pub fn name(&self) -> Name {
|
||||
pub fn ident(&self) -> Ident {
|
||||
match *self {
|
||||
ParamName::Plain(name) => name,
|
||||
ParamName::Fresh(_) => keywords::UnderscoreLifetime.name(),
|
||||
ParamName::Plain(ident) => ident,
|
||||
ParamName::Fresh(_) => keywords::UnderscoreLifetime.ident(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modern(&self) -> ParamName {
|
||||
match *self {
|
||||
ParamName::Plain(ident) => ParamName::Plain(ident.modern()),
|
||||
param_name => param_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,33 +251,44 @@ pub enum LifetimeName {
|
||||
}
|
||||
|
||||
impl LifetimeName {
|
||||
pub fn name(&self) -> Name {
|
||||
use self::LifetimeName::*;
|
||||
pub fn ident(&self) -> Ident {
|
||||
match *self {
|
||||
Implicit => keywords::Invalid.name(),
|
||||
Underscore => keywords::UnderscoreLifetime.name(),
|
||||
Static => keywords::StaticLifetime.name(),
|
||||
Param(param_name) => param_name.name(),
|
||||
LifetimeName::Implicit => keywords::Invalid.ident(),
|
||||
LifetimeName::Underscore => keywords::UnderscoreLifetime.ident(),
|
||||
LifetimeName::Static => keywords::StaticLifetime.ident(),
|
||||
LifetimeName::Param(param_name) => param_name.ident(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_elided(&self) -> bool {
|
||||
use self::LifetimeName::*;
|
||||
match self {
|
||||
Implicit | Underscore => true,
|
||||
LifetimeName::Implicit | LifetimeName::Underscore => true,
|
||||
|
||||
// It might seem surprising that `Fresh(_)` counts as
|
||||
// *not* elided -- but this is because, as far as the code
|
||||
// in the compiler is concerned -- `Fresh(_)` variants act
|
||||
// equivalently to "some fresh name". They correspond to
|
||||
// early-bound regions on an impl, in other words.
|
||||
Param(_) | Static => false,
|
||||
LifetimeName::Param(_) | LifetimeName::Static => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_static(&self) -> bool {
|
||||
self == &LifetimeName::Static
|
||||
}
|
||||
|
||||
pub fn modern(&self) -> LifetimeName {
|
||||
match *self {
|
||||
LifetimeName::Param(param_name) => LifetimeName::Param(param_name.modern()),
|
||||
lifetime_name => lifetime_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Lifetime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.name.ident().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Lifetime {
|
||||
@ -307,7 +324,7 @@ pub struct Path {
|
||||
|
||||
impl Path {
|
||||
pub fn is_global(&self) -> bool {
|
||||
!self.segments.is_empty() && self.segments[0].name == keywords::CrateRoot.name()
|
||||
!self.segments.is_empty() && self.segments[0].ident.name == keywords::CrateRoot.name()
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,7 +345,7 @@ impl fmt::Display for Path {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct PathSegment {
|
||||
/// The identifier portion of this path segment.
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
|
||||
/// Type/lifetime parameters attached to this path. They come in
|
||||
/// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
|
||||
@ -346,17 +363,17 @@ pub struct PathSegment {
|
||||
|
||||
impl PathSegment {
|
||||
/// Convert an identifier to the corresponding segment.
|
||||
pub fn from_name(name: Name) -> PathSegment {
|
||||
pub fn from_ident(ident: Ident) -> PathSegment {
|
||||
PathSegment {
|
||||
name,
|
||||
ident,
|
||||
infer_types: true,
|
||||
args: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(name: Name, args: GenericArgs, infer_types: bool) -> Self {
|
||||
pub fn new(ident: Ident, args: GenericArgs, infer_types: bool) -> Self {
|
||||
PathSegment {
|
||||
name,
|
||||
ident,
|
||||
infer_types,
|
||||
args: if args.is_empty() {
|
||||
None
|
||||
@ -859,7 +876,7 @@ pub enum PatKind {
|
||||
/// The `NodeId` is the canonical ID for the variable being bound,
|
||||
/// e.g. in `Ok(x) | Err(x)`, both `x` use the same canonical ID,
|
||||
/// which is the pattern ID of the first `x`.
|
||||
Binding(BindingAnnotation, NodeId, Spanned<Name>, Option<P<Pat>>),
|
||||
Binding(BindingAnnotation, NodeId, Ident, Option<P<Pat>>),
|
||||
|
||||
/// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`.
|
||||
/// The `bool` is `true` in the presence of a `..`.
|
||||
@ -1525,7 +1542,7 @@ pub struct TraitItemId {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct TraitItem {
|
||||
pub id: NodeId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub hir_id: HirId,
|
||||
pub attrs: HirVec<Attribute>,
|
||||
pub generics: Generics,
|
||||
@ -1537,7 +1554,7 @@ pub struct TraitItem {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum TraitMethod {
|
||||
/// No default body in the trait, just a signature.
|
||||
Required(HirVec<Spanned<Name>>),
|
||||
Required(HirVec<Ident>),
|
||||
|
||||
/// Both signature and body are provided in the trait.
|
||||
Provided(BodyId),
|
||||
@ -1568,7 +1585,7 @@ pub struct ImplItemId {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct ImplItem {
|
||||
pub id: NodeId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub hir_id: HirId,
|
||||
pub vis: Visibility,
|
||||
pub defaultness: Defaultness,
|
||||
@ -1594,7 +1611,7 @@ pub enum ImplItemKind {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct TypeBinding {
|
||||
pub id: NodeId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub ty: P<Ty>,
|
||||
pub span: Span,
|
||||
}
|
||||
@ -1632,7 +1649,7 @@ pub struct BareFnTy {
|
||||
pub abi: Abi,
|
||||
pub generic_params: HirVec<GenericParam>,
|
||||
pub decl: P<FnDecl>,
|
||||
pub arg_names: HirVec<Spanned<Name>>,
|
||||
pub arg_names: HirVec<Ident>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
@ -2129,7 +2146,7 @@ impl Item_ {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct TraitItemRef {
|
||||
pub id: TraitItemId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub kind: AssociatedItemKind,
|
||||
pub span: Span,
|
||||
pub defaultness: Defaultness,
|
||||
@ -2144,7 +2161,7 @@ pub struct TraitItemRef {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct ImplItemRef {
|
||||
pub id: ImplItemId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub kind: AssociatedItemKind,
|
||||
pub span: Span,
|
||||
pub vis: Visibility,
|
||||
@ -2172,7 +2189,7 @@ pub struct ForeignItem {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum ForeignItem_ {
|
||||
/// A foreign function
|
||||
ForeignItemFn(P<FnDecl>, HirVec<Spanned<Name>>, Generics),
|
||||
ForeignItemFn(P<FnDecl>, HirVec<Ident>, Generics),
|
||||
/// A foreign static item (`static ext: u8`), with optional mutability
|
||||
/// (the boolean is true when mutable)
|
||||
ForeignItemStatic(P<Ty>, bool),
|
||||
|
@ -12,7 +12,6 @@ use hir::def::Def;
|
||||
use hir::def_id::DefId;
|
||||
use hir::{self, HirId, PatKind};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use std::iter::{Enumerate, ExactSizeIterator};
|
||||
@ -91,11 +90,11 @@ impl hir::Pat {
|
||||
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
|
||||
/// `match foo() { Some(a) => (), None => () }`
|
||||
pub fn each_binding<F>(&self, mut f: F)
|
||||
where F: FnMut(hir::BindingAnnotation, HirId, Span, &Spanned<ast::Name>),
|
||||
where F: FnMut(hir::BindingAnnotation, HirId, Span, ast::Ident),
|
||||
{
|
||||
self.walk(|p| {
|
||||
if let PatKind::Binding(binding_mode, _, ref pth, _) = p.node {
|
||||
f(binding_mode, p.hir_id, p.span, pth);
|
||||
if let PatKind::Binding(binding_mode, _, ident, _) = p.node {
|
||||
f(binding_mode, p.hir_id, p.span, ident);
|
||||
}
|
||||
true
|
||||
});
|
||||
@ -132,20 +131,10 @@ impl hir::Pat {
|
||||
contains_bindings
|
||||
}
|
||||
|
||||
pub fn simple_name(&self) -> Option<ast::Name> {
|
||||
pub fn simple_ident(&self) -> Option<ast::Ident> {
|
||||
match self.node {
|
||||
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ref path1, None) |
|
||||
PatKind::Binding(hir::BindingAnnotation::Mutable, _, ref path1, None) =>
|
||||
Some(path1.node),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn simple_span(&self) -> Option<Span> {
|
||||
match self.node {
|
||||
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ref path1, None) |
|
||||
PatKind::Binding(hir::BindingAnnotation::Mutable, _, ref path1, None) =>
|
||||
Some(path1.span),
|
||||
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) |
|
||||
PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, None) => Some(ident),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub use self::AnnNode::*;
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{CodeMap, Spanned};
|
||||
use syntax::codemap::CodeMap;
|
||||
use syntax::parse::ParseSess;
|
||||
use syntax::parse::lexer::comments;
|
||||
use syntax::print::pp::{self, Breaks};
|
||||
@ -497,14 +497,14 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
fn print_associated_const(&mut self,
|
||||
name: ast::Name,
|
||||
ident: ast::Ident,
|
||||
ty: &hir::Ty,
|
||||
default: Option<hir::BodyId>,
|
||||
vis: &hir::Visibility)
|
||||
-> io::Result<()> {
|
||||
self.s.word(&visibility_qualified(vis, ""))?;
|
||||
self.word_space("const")?;
|
||||
self.print_name(name)?;
|
||||
self.print_ident(ident)?;
|
||||
self.word_space(":")?;
|
||||
self.print_type(ty)?;
|
||||
if let Some(expr) = default {
|
||||
@ -516,12 +516,12 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
fn print_associated_type(&mut self,
|
||||
name: ast::Name,
|
||||
ident: ast::Ident,
|
||||
bounds: Option<&hir::GenericBounds>,
|
||||
ty: Option<&hir::Ty>)
|
||||
-> io::Result<()> {
|
||||
self.word_space("type")?;
|
||||
self.print_name(name)?;
|
||||
self.print_ident(ident)?;
|
||||
if let Some(bounds) = bounds {
|
||||
self.print_bounds(":", bounds)?;
|
||||
}
|
||||
@ -559,7 +559,7 @@ impl<'a> State<'a> {
|
||||
|
||||
match kind {
|
||||
hir::UseKind::Single => {
|
||||
if path.segments.last().unwrap().name != item.name {
|
||||
if path.segments.last().unwrap().ident.name != item.name {
|
||||
self.s.space()?;
|
||||
self.word_space("as")?;
|
||||
self.print_name(item.name)?;
|
||||
@ -845,7 +845,8 @@ impl<'a> State<'a> {
|
||||
hir::Visibility::Crate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
|
||||
hir::Visibility::Restricted { ref path, .. } => {
|
||||
self.s.word("pub(")?;
|
||||
if path.segments.len() == 1 && path.segments[0].name == keywords::Super.name() {
|
||||
if path.segments.len() == 1 &&
|
||||
path.segments[0].ident.name == keywords::Super.name() {
|
||||
// Special case: `super` can print like `pub(super)`.
|
||||
self.s.word("super")?;
|
||||
} else {
|
||||
@ -928,16 +929,16 @@ impl<'a> State<'a> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn print_method_sig(&mut self,
|
||||
name: ast::Name,
|
||||
ident: ast::Ident,
|
||||
m: &hir::MethodSig,
|
||||
generics: &hir::Generics,
|
||||
vis: &hir::Visibility,
|
||||
arg_names: &[Spanned<ast::Name>],
|
||||
arg_names: &[ast::Ident],
|
||||
body_id: Option<hir::BodyId>)
|
||||
-> io::Result<()> {
|
||||
self.print_fn(&m.decl,
|
||||
m.header,
|
||||
Some(name),
|
||||
Some(ident.name),
|
||||
generics,
|
||||
vis,
|
||||
arg_names,
|
||||
@ -951,16 +952,16 @@ impl<'a> State<'a> {
|
||||
self.print_outer_attributes(&ti.attrs)?;
|
||||
match ti.node {
|
||||
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)) => {
|
||||
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)?;
|
||||
self.s.word(";")?;
|
||||
}
|
||||
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
|
||||
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))?;
|
||||
self.nbsp()?;
|
||||
self.end()?; // need to close a box
|
||||
@ -968,7 +969,7 @@ impl<'a> State<'a> {
|
||||
self.ann.nested(self, Nested::Body(body))?;
|
||||
}
|
||||
hir::TraitItemKind::Type(ref bounds, ref default) => {
|
||||
self.print_associated_type(ti.name,
|
||||
self.print_associated_type(ti.ident,
|
||||
Some(bounds),
|
||||
default.as_ref().map(|ty| &**ty))?;
|
||||
}
|
||||
@ -985,18 +986,18 @@ impl<'a> State<'a> {
|
||||
|
||||
match ii.node {
|
||||
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) => {
|
||||
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.end()?; // need to close a box
|
||||
self.end()?; // need to close a box
|
||||
self.ann.nested(self, Nested::Body(body))?;
|
||||
}
|
||||
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))
|
||||
@ -1266,7 +1267,7 @@ impl<'a> State<'a> {
|
||||
let base_args = &args[1..];
|
||||
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX)?;
|
||||
self.s.word(".")?;
|
||||
self.print_name(segment.name)?;
|
||||
self.print_ident(segment.ident)?;
|
||||
|
||||
segment.with_generic_args(|generic_args| {
|
||||
if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() {
|
||||
@ -1379,7 +1380,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
hir::ExprWhile(ref test, ref blk, opt_label) => {
|
||||
if let Some(label) = opt_label {
|
||||
self.print_name(label.name)?;
|
||||
self.print_ident(label.ident)?;
|
||||
self.word_space(":")?;
|
||||
}
|
||||
self.head("while")?;
|
||||
@ -1389,7 +1390,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
hir::ExprLoop(ref blk, opt_label, _) => {
|
||||
if let Some(label) = opt_label {
|
||||
self.print_name(label.name)?;
|
||||
self.print_ident(label.ident)?;
|
||||
self.word_space(":")?;
|
||||
}
|
||||
self.head("loop")?;
|
||||
@ -1425,7 +1426,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
hir::ExprBlock(ref blk, opt_label) => {
|
||||
if let Some(label) = opt_label {
|
||||
self.print_name(label.name)?;
|
||||
self.print_ident(label.ident)?;
|
||||
self.word_space(":")?;
|
||||
}
|
||||
// containing cbox, will be closed by print-block at }
|
||||
@ -1467,7 +1468,7 @@ impl<'a> State<'a> {
|
||||
self.s.word("break")?;
|
||||
self.s.space()?;
|
||||
if let Some(label) = destination.label {
|
||||
self.print_name(label.name)?;
|
||||
self.print_ident(label.ident)?;
|
||||
self.s.space()?;
|
||||
}
|
||||
if let Some(ref expr) = *opt_expr {
|
||||
@ -1479,7 +1480,7 @@ impl<'a> State<'a> {
|
||||
self.s.word("continue")?;
|
||||
self.s.space()?;
|
||||
if let Some(label) = destination.label {
|
||||
self.print_name(label.name)?;
|
||||
self.print_ident(label.ident)?;
|
||||
self.s.space()?
|
||||
}
|
||||
}
|
||||
@ -1614,7 +1615,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
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<()> {
|
||||
@ -1634,9 +1635,9 @@ impl<'a> State<'a> {
|
||||
if i > 0 {
|
||||
self.s.word("::")?
|
||||
}
|
||||
if segment.name != keywords::CrateRoot.name() &&
|
||||
segment.name != keywords::DollarCrate.name() {
|
||||
self.print_name(segment.name)?;
|
||||
if segment.ident.name != keywords::CrateRoot.name() &&
|
||||
segment.ident.name != keywords::DollarCrate.name() {
|
||||
self.print_ident(segment.ident)?;
|
||||
segment.with_generic_args(|generic_args| {
|
||||
self.print_generic_args(generic_args, segment.infer_types,
|
||||
colons_before_params)
|
||||
@ -1665,9 +1666,9 @@ impl<'a> State<'a> {
|
||||
if i > 0 {
|
||||
self.s.word("::")?
|
||||
}
|
||||
if segment.name != keywords::CrateRoot.name() &&
|
||||
segment.name != keywords::DollarCrate.name() {
|
||||
self.print_name(segment.name)?;
|
||||
if segment.ident.name != keywords::CrateRoot.name() &&
|
||||
segment.ident.name != keywords::DollarCrate.name() {
|
||||
self.print_ident(segment.ident)?;
|
||||
segment.with_generic_args(|generic_args| {
|
||||
self.print_generic_args(generic_args,
|
||||
segment.infer_types,
|
||||
@ -1679,7 +1680,7 @@ impl<'a> State<'a> {
|
||||
self.s.word(">")?;
|
||||
self.s.word("::")?;
|
||||
let item_segment = path.segments.last().unwrap();
|
||||
self.print_name(item_segment.name)?;
|
||||
self.print_ident(item_segment.ident)?;
|
||||
item_segment.with_generic_args(|generic_args| {
|
||||
self.print_generic_args(generic_args,
|
||||
item_segment.infer_types,
|
||||
@ -1691,7 +1692,7 @@ impl<'a> State<'a> {
|
||||
self.print_type(qself)?;
|
||||
self.s.word(">")?;
|
||||
self.s.word("::")?;
|
||||
self.print_name(item_segment.name)?;
|
||||
self.print_ident(item_segment.ident)?;
|
||||
item_segment.with_generic_args(|generic_args| {
|
||||
self.print_generic_args(generic_args,
|
||||
item_segment.infer_types,
|
||||
@ -1762,7 +1763,7 @@ impl<'a> State<'a> {
|
||||
|
||||
for binding in generic_args.bindings.iter() {
|
||||
start_or_comma(self)?;
|
||||
self.print_name(binding.name)?;
|
||||
self.print_ident(binding.ident)?;
|
||||
self.s.space()?;
|
||||
self.word_space("=")?;
|
||||
self.print_type(&binding.ty)?;
|
||||
@ -1783,7 +1784,7 @@ impl<'a> State<'a> {
|
||||
// is that it doesn't matter
|
||||
match pat.node {
|
||||
PatKind::Wild => self.s.word("_")?,
|
||||
PatKind::Binding(binding_mode, _, ref path1, ref sub) => {
|
||||
PatKind::Binding(binding_mode, _, ident, ref sub) => {
|
||||
match binding_mode {
|
||||
hir::BindingAnnotation::Ref => {
|
||||
self.word_nbsp("ref")?;
|
||||
@ -1798,7 +1799,7 @@ impl<'a> State<'a> {
|
||||
self.word_nbsp("mut")?;
|
||||
}
|
||||
}
|
||||
self.print_name(path1.node)?;
|
||||
self.print_ident(ident)?;
|
||||
if let Some(ref p) = *sub {
|
||||
self.s.word("@")?;
|
||||
self.print_pat(&p)?;
|
||||
@ -1963,7 +1964,7 @@ impl<'a> State<'a> {
|
||||
match arm.body.node {
|
||||
hir::ExprBlock(ref blk, opt_label) => {
|
||||
if let Some(label) = opt_label {
|
||||
self.print_name(label.name)?;
|
||||
self.print_ident(label.ident)?;
|
||||
self.word_space(":")?;
|
||||
}
|
||||
// the block will close the pattern's ibox
|
||||
@ -1989,7 +1990,7 @@ impl<'a> State<'a> {
|
||||
name: Option<ast::Name>,
|
||||
generics: &hir::Generics,
|
||||
vis: &hir::Visibility,
|
||||
arg_names: &[Spanned<ast::Name>],
|
||||
arg_names: &[ast::Ident],
|
||||
body_id: Option<hir::BodyId>)
|
||||
-> io::Result<()> {
|
||||
self.print_fn_header_info(header, vis)?;
|
||||
@ -2006,8 +2007,8 @@ impl<'a> State<'a> {
|
||||
assert!(arg_names.is_empty() || body_id.is_none());
|
||||
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
|
||||
s.ibox(indent_unit)?;
|
||||
if let Some(name) = arg_names.get(i) {
|
||||
s.s.word(&name.node.as_str())?;
|
||||
if let Some(arg_name) = arg_names.get(i) {
|
||||
s.s.word(&arg_name.as_str())?;
|
||||
s.s.word(":")?;
|
||||
s.s.space()?;
|
||||
} else if let Some(body_id) = body_id {
|
||||
@ -2112,7 +2113,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
pub fn print_generic_param(&mut self, param: &GenericParam) -> io::Result<()> {
|
||||
self.print_name(param.name.name())?;
|
||||
self.print_ident(param.name.ident())?;
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
let mut sep = ":";
|
||||
@ -2143,7 +2144,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
pub fn print_lifetime(&mut self, lifetime: &hir::Lifetime) -> io::Result<()> {
|
||||
self.print_name(lifetime.name.name())
|
||||
self.print_ident(lifetime.name.ident())
|
||||
}
|
||||
|
||||
pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause) -> io::Result<()> {
|
||||
@ -2241,7 +2242,7 @@ impl<'a> State<'a> {
|
||||
decl: &hir::FnDecl,
|
||||
name: Option<ast::Name>,
|
||||
generic_params: &[hir::GenericParam],
|
||||
arg_names: &[Spanned<ast::Name>])
|
||||
arg_names: &[ast::Ident])
|
||||
-> io::Result<()> {
|
||||
self.ibox(indent_unit)?;
|
||||
if !generic_params.is_empty() {
|
||||
|
@ -155,8 +155,7 @@ impl_stable_hash_for!(enum hir::LifetimeName {
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::Label {
|
||||
span,
|
||||
name
|
||||
ident
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::Lifetime {
|
||||
@ -172,7 +171,7 @@ impl_stable_hash_for!(struct hir::Path {
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::PathSegment {
|
||||
name,
|
||||
ident -> (ident.name),
|
||||
infer_types,
|
||||
args
|
||||
});
|
||||
@ -201,10 +200,10 @@ impl_stable_hash_for!(enum hir::TraitBoundModifier {
|
||||
impl_stable_hash_for!(struct hir::GenericParam {
|
||||
id,
|
||||
name,
|
||||
span,
|
||||
pure_wrt_drop,
|
||||
attrs,
|
||||
bounds,
|
||||
span,
|
||||
kind
|
||||
});
|
||||
|
||||
@ -278,7 +277,7 @@ impl_stable_hash_for!(struct hir::MethodSig {
|
||||
|
||||
impl_stable_hash_for!(struct hir::TypeBinding {
|
||||
id,
|
||||
name,
|
||||
ident -> (ident.name),
|
||||
ty,
|
||||
span
|
||||
});
|
||||
@ -359,20 +358,11 @@ impl_stable_hash_for!(enum hir::FunctionRetTy {
|
||||
Return(t)
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitRef {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::TraitRef {
|
||||
ref path,
|
||||
// Don't hash the ref_id. It is tracked via the thing it is used to access
|
||||
ref_id: _,
|
||||
} = *self;
|
||||
|
||||
path.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct hir::TraitRef {
|
||||
// Don't hash the ref_id. It is tracked via the thing it is used to access
|
||||
ref_id -> _,
|
||||
path,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::PolyTraitRef {
|
||||
bound_generic_params,
|
||||
@ -395,66 +385,32 @@ impl_stable_hash_for!(struct hir::MacroDef {
|
||||
body
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::Block {
|
||||
stmts,
|
||||
expr,
|
||||
id -> _,
|
||||
hir_id -> _,
|
||||
rules,
|
||||
span,
|
||||
targeted_by_break,
|
||||
recovered,
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::Block {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::Block {
|
||||
ref stmts,
|
||||
ref expr,
|
||||
id: _,
|
||||
hir_id: _,
|
||||
rules,
|
||||
span,
|
||||
targeted_by_break,
|
||||
recovered,
|
||||
} = *self;
|
||||
|
||||
stmts.hash_stable(hcx, hasher);
|
||||
expr.hash_stable(hcx, hasher);
|
||||
rules.hash_stable(hcx, hasher);
|
||||
span.hash_stable(hcx, hasher);
|
||||
recovered.hash_stable(hcx, hasher);
|
||||
targeted_by_break.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::Pat {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::Pat {
|
||||
id: _,
|
||||
hir_id: _,
|
||||
ref node,
|
||||
ref span
|
||||
} = *self;
|
||||
|
||||
|
||||
node.hash_stable(hcx, hasher);
|
||||
span.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct hir::Pat {
|
||||
id -> _,
|
||||
hir_id -> _,
|
||||
node,
|
||||
span,
|
||||
});
|
||||
|
||||
impl_stable_hash_for_spanned!(hir::FieldPat);
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::FieldPat {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::FieldPat {
|
||||
id: _,
|
||||
ident,
|
||||
ref pat,
|
||||
is_shorthand,
|
||||
} = *self;
|
||||
|
||||
ident.hash_stable(hcx, hasher);
|
||||
pat.hash_stable(hcx, hasher);
|
||||
is_shorthand.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct hir::FieldPat {
|
||||
id -> _,
|
||||
ident -> (ident.name),
|
||||
pat,
|
||||
is_shorthand,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(enum hir::BindingAnnotation {
|
||||
Unannotated,
|
||||
@ -537,24 +493,13 @@ impl_stable_hash_for!(struct hir::Arm {
|
||||
body
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::Field {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::Field {
|
||||
id: _,
|
||||
ident,
|
||||
ref expr,
|
||||
span,
|
||||
is_shorthand,
|
||||
} = *self;
|
||||
|
||||
ident.hash_stable(hcx, hasher);
|
||||
expr.hash_stable(hcx, hasher);
|
||||
span.hash_stable(hcx, hasher);
|
||||
is_shorthand.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct hir::Field {
|
||||
id -> _,
|
||||
ident,
|
||||
expr,
|
||||
span,
|
||||
is_shorthand,
|
||||
});
|
||||
|
||||
impl_stable_hash_for_spanned!(ast::Name);
|
||||
|
||||
@ -686,19 +631,10 @@ impl_stable_hash_for!(enum hir::LoopIdError {
|
||||
UnresolvedLabel
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for ast::Ident {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ast::Ident {
|
||||
name,
|
||||
span,
|
||||
} = *self;
|
||||
|
||||
name.hash_stable(hcx, hasher);
|
||||
span.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct ast::Ident {
|
||||
name,
|
||||
span,
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
@ -707,7 +643,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
|
||||
let hir::TraitItem {
|
||||
id: _,
|
||||
hir_id: _,
|
||||
name,
|
||||
ident,
|
||||
ref attrs,
|
||||
ref generics,
|
||||
ref node,
|
||||
@ -715,7 +651,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
|
||||
} = *self;
|
||||
|
||||
hcx.hash_hir_item_like(|hcx| {
|
||||
name.hash_stable(hcx, hasher);
|
||||
ident.name.hash_stable(hcx, hasher);
|
||||
attrs.hash_stable(hcx, hasher);
|
||||
generics.hash_stable(hcx, hasher);
|
||||
node.hash_stable(hcx, hasher);
|
||||
@ -742,7 +678,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
|
||||
let hir::ImplItem {
|
||||
id: _,
|
||||
hir_id: _,
|
||||
name,
|
||||
ident,
|
||||
ref vis,
|
||||
defaultness,
|
||||
ref attrs,
|
||||
@ -752,7 +688,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
|
||||
} = *self;
|
||||
|
||||
hcx.hash_hir_item_like(|hcx| {
|
||||
name.hash_stable(hcx, hasher);
|
||||
ident.name.hash_stable(hcx, hasher);
|
||||
vis.hash_stable(hcx, hasher);
|
||||
defaultness.hash_stable(hcx, hasher);
|
||||
attrs.hash_stable(hcx, hasher);
|
||||
@ -818,21 +754,13 @@ impl_stable_hash_for!(enum hir::ImplPolarity {
|
||||
Negative
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::Mod {
|
||||
inner,
|
||||
// We are not hashing the IDs of the items contained in the module.
|
||||
// This is harmless and matches the current behavior but it's not
|
||||
// actually correct. See issue #40876.
|
||||
item_ids: _,
|
||||
} = *self;
|
||||
|
||||
inner.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct hir::Mod {
|
||||
inner,
|
||||
// We are not hashing the IDs of the items contained in the module.
|
||||
// This is harmless and matches the current behavior but it's not
|
||||
// actually correct. See issue #40876.
|
||||
item_ids -> _,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::ForeignMod {
|
||||
abi,
|
||||
@ -860,7 +788,7 @@ impl_stable_hash_for!(enum hir::UseKind {
|
||||
|
||||
impl_stable_hash_for!(struct hir::StructField {
|
||||
span,
|
||||
ident,
|
||||
ident -> (ident.name),
|
||||
vis,
|
||||
id,
|
||||
ty,
|
||||
@ -918,7 +846,7 @@ impl_stable_hash_for!(enum hir::Item_ {
|
||||
|
||||
impl_stable_hash_for!(struct hir::TraitItemRef {
|
||||
id,
|
||||
name,
|
||||
ident -> (ident.name),
|
||||
kind,
|
||||
span,
|
||||
defaultness
|
||||
@ -926,15 +854,14 @@ impl_stable_hash_for!(struct hir::TraitItemRef {
|
||||
|
||||
impl_stable_hash_for!(struct hir::ImplItemRef {
|
||||
id,
|
||||
name,
|
||||
ident -> (ident.name),
|
||||
kind,
|
||||
span,
|
||||
vis,
|
||||
defaultness
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>>
|
||||
for hir::AssociatedItemKind {
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::AssociatedItemKind {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
@ -1014,45 +941,22 @@ impl_stable_hash_for!(struct hir::InlineAsmOutput {
|
||||
is_indirect
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::GlobalAsm {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::GlobalAsm {
|
||||
asm,
|
||||
ctxt: _
|
||||
} = *self;
|
||||
impl_stable_hash_for!(struct hir::GlobalAsm {
|
||||
asm,
|
||||
ctxt -> _, // This is used for error reporting
|
||||
});
|
||||
|
||||
asm.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::InlineAsm {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::InlineAsm {
|
||||
asm,
|
||||
asm_str_style,
|
||||
ref outputs,
|
||||
ref inputs,
|
||||
ref clobbers,
|
||||
volatile,
|
||||
alignstack,
|
||||
dialect,
|
||||
ctxt: _, // This is used for error reporting
|
||||
} = *self;
|
||||
|
||||
asm.hash_stable(hcx, hasher);
|
||||
asm_str_style.hash_stable(hcx, hasher);
|
||||
outputs.hash_stable(hcx, hasher);
|
||||
inputs.hash_stable(hcx, hasher);
|
||||
clobbers.hash_stable(hcx, hasher);
|
||||
volatile.hash_stable(hcx, hasher);
|
||||
alignstack.hash_stable(hcx, hasher);
|
||||
dialect.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct hir::InlineAsm {
|
||||
asm,
|
||||
asm_str_style,
|
||||
outputs,
|
||||
inputs,
|
||||
clobbers,
|
||||
volatile,
|
||||
alignstack,
|
||||
dialect,
|
||||
ctxt -> _, // This is used for error reporting
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(enum hir::def::CtorKind {
|
||||
Fn,
|
||||
@ -1115,8 +1019,7 @@ impl_stable_hash_for!(enum hir::Constness {
|
||||
NotConst
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>>
|
||||
for hir::def_id::DefIndex {
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::def_id::DefIndex {
|
||||
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
@ -1142,8 +1045,7 @@ impl_stable_hash_for!(struct hir::def::Export {
|
||||
span
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>>
|
||||
for ::middle::lang_items::LangItem {
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for ::middle::lang_items::LangItem {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
_: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
@ -1156,8 +1058,7 @@ impl_stable_hash_for!(struct ::middle::lang_items::LanguageItems {
|
||||
missing
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>>
|
||||
for hir::TraitCandidate {
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
@ -1191,26 +1092,13 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::CodegenFnAttrs
|
||||
{
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'hir>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let hir::CodegenFnAttrs {
|
||||
flags,
|
||||
inline,
|
||||
export_name,
|
||||
ref target_features,
|
||||
linkage,
|
||||
} = *self;
|
||||
|
||||
flags.hash_stable(hcx, hasher);
|
||||
inline.hash_stable(hcx, hasher);
|
||||
export_name.hash_stable(hcx, hasher);
|
||||
target_features.hash_stable(hcx, hasher);
|
||||
linkage.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct hir::CodegenFnAttrs {
|
||||
flags,
|
||||
inline,
|
||||
export_name,
|
||||
target_features,
|
||||
linkage,
|
||||
});
|
||||
|
||||
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::CodegenFnAttrFlags
|
||||
{
|
||||
|
@ -357,17 +357,11 @@ impl_stable_hash_for!(enum ty::VariantDiscr {
|
||||
Relative(distance)
|
||||
});
|
||||
|
||||
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::FieldDef {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::FieldDef { did, ident, vis } = *self;
|
||||
|
||||
did.hash_stable(hcx, hasher);
|
||||
ident.name.hash_stable(hcx, hasher);
|
||||
vis.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct ty::FieldDef {
|
||||
did,
|
||||
ident -> (ident.name),
|
||||
vis,
|
||||
});
|
||||
|
||||
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
|
||||
for ::middle::const_val::ConstVal<'gcx> {
|
||||
@ -545,15 +539,7 @@ impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
|
||||
predicates
|
||||
});
|
||||
|
||||
|
||||
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
|
||||
for ::mir::interpret::EvalError<'gcx> {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
self.kind.hash_stable(hcx, hasher)
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind });
|
||||
|
||||
impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
|
||||
for ::mir::interpret::EvalErrorKind<'gcx, O> {
|
||||
@ -726,28 +712,15 @@ impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
|
||||
Struct(index)
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::Generics {
|
||||
parent,
|
||||
ref parent_count,
|
||||
ref params,
|
||||
|
||||
// Reverse map to each param's `index` field, from its `def_id`.
|
||||
param_def_id_to_index: _, // Don't hash this
|
||||
has_self,
|
||||
has_late_bound_regions,
|
||||
} = *self;
|
||||
|
||||
parent.hash_stable(hcx, hasher);
|
||||
parent_count.hash_stable(hcx, hasher);
|
||||
params.hash_stable(hcx, hasher);
|
||||
has_self.hash_stable(hcx, hasher);
|
||||
has_late_bound_regions.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct ty::Generics {
|
||||
parent,
|
||||
parent_count,
|
||||
params,
|
||||
// Reverse map to each param's `index` field, from its `def_id`.
|
||||
param_def_id_to_index -> _, // Don't hash this
|
||||
has_self,
|
||||
has_late_bound_regions,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ty::GenericParamDef {
|
||||
name,
|
||||
@ -1079,61 +1052,34 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for ty::TraitDef {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::TraitDef {
|
||||
// We already have the def_path_hash below, no need to hash it twice
|
||||
def_id: _,
|
||||
unsafety,
|
||||
paren_sugar,
|
||||
has_auto_impl,
|
||||
def_path_hash,
|
||||
} = *self;
|
||||
|
||||
unsafety.hash_stable(hcx, hasher);
|
||||
paren_sugar.hash_stable(hcx, hasher);
|
||||
has_auto_impl.hash_stable(hcx, hasher);
|
||||
def_path_hash.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct ty::TraitDef {
|
||||
// We already have the def_path_hash below, no need to hash it twice
|
||||
def_id -> _,
|
||||
unsafety,
|
||||
paren_sugar,
|
||||
has_auto_impl,
|
||||
def_path_hash,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ty::Destructor {
|
||||
did
|
||||
});
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for ty::CrateVariancesMap {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::CrateVariancesMap {
|
||||
ref variances,
|
||||
// This is just an irrelevant helper value.
|
||||
empty_variance: _,
|
||||
} = *self;
|
||||
impl_stable_hash_for!(struct ty::CrateVariancesMap {
|
||||
variances,
|
||||
// This is just an irrelevant helper value.
|
||||
empty_variance -> _,
|
||||
});
|
||||
|
||||
variances.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::CratePredicatesMap<'gcx> {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
let ty::CratePredicatesMap {
|
||||
ref predicates,
|
||||
// This is just an irrelevant helper value.
|
||||
empty_predicate: _,
|
||||
} = *self;
|
||||
|
||||
predicates.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
|
||||
predicates,
|
||||
// This is just an irrelevant helper value.
|
||||
empty_predicate -> _,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ty::AssociatedItem {
|
||||
def_id,
|
||||
name,
|
||||
ident -> (ident.name),
|
||||
kind,
|
||||
vis,
|
||||
defaultness,
|
||||
|
@ -1255,7 +1255,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!(
|
||||
" for lifetime parameter {}in trait containing associated type `{}`",
|
||||
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::BoundRegionInCoherence(name) => {
|
||||
|
@ -131,8 +131,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
labels.clear();
|
||||
labels.push((pattern.span, format!("consider giving this closure parameter a type")));
|
||||
} else if let Some(pattern) = local_visitor.found_local_pattern {
|
||||
if let Some(simple_name) = pattern.simple_name() {
|
||||
labels.push((pattern.span, format!("consider giving `{}` a type", simple_name)));
|
||||
if let Some(simple_ident) = pattern.simple_ident() {
|
||||
labels.push((pattern.span, format!("consider giving `{}` a type", simple_ident)));
|
||||
} else {
|
||||
labels.push((pattern.span, format!("consider giving the pattern a type")));
|
||||
}
|
||||
|
@ -96,14 +96,14 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||
let sub_is_ret_type =
|
||||
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
|
||||
|
||||
let span_label_var1 = if let Some(simple_name) = anon_arg_sup.pat.simple_name() {
|
||||
format!(" from `{}`", simple_name)
|
||||
let span_label_var1 = if let Some(simple_ident) = anon_arg_sup.pat.simple_ident() {
|
||||
format!(" from `{}`", simple_ident)
|
||||
} else {
|
||||
format!("")
|
||||
};
|
||||
|
||||
let span_label_var2 = if let Some(simple_name) = anon_arg_sub.pat.simple_name() {
|
||||
format!(" into `{}`", simple_name)
|
||||
let span_label_var2 = if let Some(simple_ident) = anon_arg_sub.pat.simple_ident() {
|
||||
format!(" into `{}`", simple_ident)
|
||||
} else {
|
||||
format!("")
|
||||
};
|
||||
|
@ -95,10 +95,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let (error_var, span_label_var) = if let Some(simple_name) = arg.pat.simple_name() {
|
||||
let (error_var, span_label_var) = if let Some(simple_ident) = arg.pat.simple_ident() {
|
||||
(
|
||||
format!("the type of `{}`", simple_name),
|
||||
format!("the type of `{}`", simple_name),
|
||||
format!("the type of `{}`", simple_ident),
|
||||
format!("the type of `{}`", simple_ident),
|
||||
)
|
||||
} else {
|
||||
("parameter type".to_owned(), "type".to_owned())
|
||||
|
@ -64,15 +64,14 @@ macro_rules! span_bug {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! __impl_stable_hash_field {
|
||||
(DECL IGNORED) => (_);
|
||||
(DECL $name:ident) => (ref $name);
|
||||
(USE IGNORED $ctx:expr, $hasher:expr) => ({});
|
||||
(USE $name:ident, $ctx:expr, $hasher:expr) => ($name.hash_stable($ctx, $hasher));
|
||||
($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher));
|
||||
($field:ident, $ctx:expr, $hasher:expr, _) => ({ let _ = $field; });
|
||||
($field:ident, $ctx:expr, $hasher:expr, $delegate:expr) => ($delegate.hash_stable($ctx, $hasher));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_stable_hash_for {
|
||||
(enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* $(,)* }) => {
|
||||
(enum $enum_name:path { $( $variant:ident $( ( $($field:ident $(-> $delegate:tt)?),* ) )* ),* $(,)? }) => {
|
||||
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $enum_name {
|
||||
#[inline]
|
||||
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
|
||||
@ -83,15 +82,15 @@ macro_rules! impl_stable_hash_for {
|
||||
|
||||
match *self {
|
||||
$(
|
||||
$variant $( ( $( __impl_stable_hash_field!(DECL $arg) ),* ) )* => {
|
||||
$($( __impl_stable_hash_field!(USE $arg, __ctx, __hasher) );*)*
|
||||
$variant $( ( $(ref $field),* ) )* => {
|
||||
$($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*)*
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
(struct $struct_name:path { $($field:ident),* }) => {
|
||||
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
|
||||
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name {
|
||||
#[inline]
|
||||
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
|
||||
@ -101,11 +100,11 @@ macro_rules! impl_stable_hash_for {
|
||||
$(ref $field),*
|
||||
} = *self;
|
||||
|
||||
$( $field.hash_stable(__ctx, __hasher));*
|
||||
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
|
||||
}
|
||||
}
|
||||
};
|
||||
(tuple_struct $struct_name:path { $($field:ident),* }) => {
|
||||
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
|
||||
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name {
|
||||
#[inline]
|
||||
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
|
||||
@ -115,7 +114,7 @@ macro_rules! impl_stable_hash_for {
|
||||
$(ref $field),*
|
||||
) = *self;
|
||||
|
||||
$( $field.hash_stable(__ctx, __hasher));*
|
||||
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -599,7 +599,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
||||
if !self.symbol_is_live(impl_item.id, None) {
|
||||
self.warn_dead_code(impl_item.id,
|
||||
impl_item.span,
|
||||
impl_item.name,
|
||||
impl_item.ident.name,
|
||||
"associated const",
|
||||
"used");
|
||||
}
|
||||
@ -608,7 +608,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
||||
hir::ImplItemKind::Method(_, body_id) => {
|
||||
if !self.symbol_is_live(impl_item.id, None) {
|
||||
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)
|
||||
}
|
||||
|
@ -374,10 +374,9 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
|
||||
let body = ir.tcx.hir.body(body_id);
|
||||
|
||||
for arg in &body.arguments {
|
||||
arg.pat.each_binding(|_bm, hir_id, _x, path1| {
|
||||
arg.pat.each_binding(|_bm, hir_id, _x, ident| {
|
||||
debug!("adding argument {:?}", hir_id);
|
||||
let name = path1.node;
|
||||
fn_maps.add_variable(Arg(hir_id, name));
|
||||
fn_maps.add_variable(Arg(hir_id, ident.name));
|
||||
})
|
||||
};
|
||||
|
||||
@ -430,12 +429,11 @@ fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P<hir::Pat>) {
|
||||
}
|
||||
}
|
||||
|
||||
pat.each_binding(|_bm, hir_id, _sp, path1| {
|
||||
let name = path1.node;
|
||||
ir.add_live_node_for_node(hir_id, VarDefNode(path1.span));
|
||||
pat.each_binding(|_bm, hir_id, _sp, ident| {
|
||||
ir.add_live_node_for_node(hir_id, VarDefNode(ident.span));
|
||||
ir.add_variable(Local(LocalInfo {
|
||||
id: hir_id,
|
||||
name,
|
||||
name: ident.name,
|
||||
is_shorthand: shorthand_field_ids.contains(&hir_id)
|
||||
}));
|
||||
});
|
||||
@ -1374,7 +1372,7 @@ fn check_local<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, local: &'tcx hir::Local)
|
||||
},
|
||||
None => {
|
||||
this.pat_bindings(&local.pat, |this, ln, var, sp, id| {
|
||||
let span = local.pat.simple_span().unwrap_or(sp);
|
||||
let span = local.pat.simple_ident().map_or(sp, |ident| ident.span);
|
||||
this.warn_about_unused(span, id, ln, var);
|
||||
})
|
||||
}
|
||||
@ -1475,12 +1473,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
|
||||
fn warn_about_unused_args(&self, body: &hir::Body, entry_ln: LiveNode) {
|
||||
for arg in &body.arguments {
|
||||
arg.pat.each_binding(|_bm, hir_id, _, path1| {
|
||||
let sp = path1.span;
|
||||
arg.pat.each_binding(|_bm, hir_id, _, ident| {
|
||||
let sp = ident.span;
|
||||
let var = self.variable(hir_id, sp);
|
||||
// Ignore unused self.
|
||||
let name = path1.node;
|
||||
if name != keywords::SelfValue.name() {
|
||||
if ident.name != keywords::SelfValue.name() {
|
||||
if !self.warn_about_unused(sp, hir_id, entry_ln, var) {
|
||||
if self.live_on_entry(entry_ln, var).is_none() {
|
||||
self.report_dead_assign(hir_id, sp, var, true);
|
||||
|
@ -94,7 +94,7 @@ impl Region {
|
||||
let def_id = hir_map.local_def_id(param.id);
|
||||
let origin = LifetimeDefOrigin::from_param(param);
|
||||
debug!("Region::early: index={} def_id={:?}", i, def_id);
|
||||
(param.name, Region::EarlyBound(i, def_id, origin))
|
||||
(param.name.modern(), Region::EarlyBound(i, def_id, origin))
|
||||
}
|
||||
|
||||
fn late(hir_map: &Map, param: &GenericParam) -> (ParamName, Region) {
|
||||
@ -108,7 +108,7 @@ impl Region {
|
||||
def_id,
|
||||
origin,
|
||||
);
|
||||
(param.name, Region::LateBound(depth, def_id, origin))
|
||||
(param.name.modern(), Region::LateBound(depth, def_id, origin))
|
||||
}
|
||||
|
||||
fn late_anon(index: &Cell<u32>) -> Region {
|
||||
@ -254,7 +254,7 @@ struct LifetimeContext<'a, 'tcx: 'a> {
|
||||
is_in_fn_syntax: bool,
|
||||
|
||||
/// List of labels in the function/method currently under analysis.
|
||||
labels_in_fn: Vec<(ast::Name, Span)>,
|
||||
labels_in_fn: Vec<ast::Ident>,
|
||||
|
||||
/// Cache for cross-crate per-definition object lifetime defaults.
|
||||
xcrate_object_lifetime_defaults: DefIdMap<Vec<ObjectLifetimeDefault>>,
|
||||
@ -689,7 +689,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
let (name, reg) = Region::early(&self.tcx.hir, &mut index, ¶m);
|
||||
if let hir::ParamName::Plain(param_name) = name {
|
||||
if param_name == keywords::UnderscoreLifetime.name() {
|
||||
if param_name.name == keywords::UnderscoreLifetime.name() {
|
||||
// Pick the elided lifetime "definition" if one exists
|
||||
// and use it to make an elision scope.
|
||||
elision = Some(reg);
|
||||
@ -1109,7 +1109,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
|
||||
struct GatherLabels<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
scope: ScopeRef<'a>,
|
||||
labels_in_fn: &'a mut Vec<(ast::Name, Span)>,
|
||||
labels_in_fn: &'a mut Vec<ast::Ident>,
|
||||
}
|
||||
|
||||
let mut gather = GatherLabels {
|
||||
@ -1125,32 +1125,31 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, ex: &hir::Expr) {
|
||||
if let Some((label, label_span)) = expression_label(ex) {
|
||||
for &(prior, prior_span) in &self.labels_in_fn[..] {
|
||||
if let Some(label) = expression_label(ex) {
|
||||
for prior_label in &self.labels_in_fn[..] {
|
||||
// FIXME (#24278): non-hygienic comparison
|
||||
if label == prior {
|
||||
if label.name == prior_label.name {
|
||||
signal_shadowing_problem(
|
||||
self.tcx,
|
||||
label,
|
||||
original_label(prior_span),
|
||||
shadower_label(label_span),
|
||||
label.name,
|
||||
original_label(prior_label.span),
|
||||
shadower_label(label.span),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
check_if_label_shadows_lifetime(self.tcx, self.scope, label, label_span);
|
||||
check_if_label_shadows_lifetime(self.tcx, self.scope, label);
|
||||
|
||||
self.labels_in_fn.push((label, label_span));
|
||||
self.labels_in_fn.push(label);
|
||||
}
|
||||
intravisit::walk_expr(self, ex)
|
||||
}
|
||||
}
|
||||
|
||||
fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> {
|
||||
fn expression_label(ex: &hir::Expr) -> Option<ast::Ident> {
|
||||
match ex.node {
|
||||
hir::ExprWhile(.., Some(label)) | hir::ExprLoop(_, Some(label), _) => {
|
||||
Some((label.name, label.span))
|
||||
}
|
||||
hir::ExprWhile(.., Some(label)) |
|
||||
hir::ExprLoop(_, Some(label), _) => Some(label.ident),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -1158,8 +1157,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
|
||||
fn check_if_label_shadows_lifetime(
|
||||
tcx: TyCtxt<'_, '_, '_>,
|
||||
mut scope: ScopeRef<'_>,
|
||||
label: ast::Name,
|
||||
label_span: Span,
|
||||
label: ast::Ident,
|
||||
) {
|
||||
loop {
|
||||
match *scope {
|
||||
@ -1177,15 +1175,14 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
|
||||
ref lifetimes, s, ..
|
||||
} => {
|
||||
// FIXME (#24278): non-hygienic comparison
|
||||
let param_name = hir::ParamName::Plain(label);
|
||||
if let Some(def) = lifetimes.get(¶m_name) {
|
||||
if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) {
|
||||
let node_id = tcx.hir.as_local_node_id(def.id().unwrap()).unwrap();
|
||||
|
||||
signal_shadowing_problem(
|
||||
tcx,
|
||||
label,
|
||||
label.name,
|
||||
original_lifetime(tcx.hir.span(node_id)),
|
||||
shadower_label(label_span),
|
||||
shadower_label(label.span),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -1220,7 +1217,7 @@ fn compute_object_lifetime_defaults(
|
||||
generics.params.iter().find_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
if i == 0 {
|
||||
return Some(param.name.name().to_string());
|
||||
return Some(param.name.ident().to_string());
|
||||
}
|
||||
i -= 1;
|
||||
None
|
||||
@ -1254,7 +1251,7 @@ fn object_lifetime_defaults_for_item(
|
||||
fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::GenericBound]) {
|
||||
for bound in bounds {
|
||||
if let hir::GenericBound::Outlives(ref lifetime) = *bound {
|
||||
set.insert(lifetime.name);
|
||||
set.insert(lifetime.name.modern());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1400,10 +1397,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
debug!("node id first={:?}", node_id);
|
||||
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
|
||||
hir::map::NodeLifetime(hir_lifetime) => {
|
||||
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.name()))
|
||||
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.ident()))
|
||||
}
|
||||
hir::map::NodeGenericParam(param) => {
|
||||
Some((param.id, param.span, param.name.name()))
|
||||
Some((param.id, param.span, param.name.ident()))
|
||||
}
|
||||
_ => None,
|
||||
} {
|
||||
@ -1426,10 +1423,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
|
||||
hir::map::NodeLifetime(hir_lifetime) => {
|
||||
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.name()))
|
||||
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.ident()))
|
||||
}
|
||||
hir::map::NodeGenericParam(param) => {
|
||||
Some((param.id, param.span, param.name.name()))
|
||||
Some((param.id, param.span, param.name.ident()))
|
||||
}
|
||||
_ => None,
|
||||
} {
|
||||
@ -1582,7 +1579,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
LifetimeName::Param(param_name) => param_name,
|
||||
_ => bug!("expected LifetimeName::Param"),
|
||||
};
|
||||
if let Some(&def) = lifetimes.get(&name) {
|
||||
if let Some(&def) = lifetimes.get(&name.modern()) {
|
||||
break Some(def.shifted(late_depth));
|
||||
} else {
|
||||
late_depth += 1;
|
||||
@ -1651,7 +1648,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
lifetime_ref.span,
|
||||
E0261,
|
||||
"use of undeclared lifetime name `{}`",
|
||||
lifetime_ref.name.name()
|
||||
lifetime_ref
|
||||
).span_label(lifetime_ref.span, "undeclared lifetime")
|
||||
.emit();
|
||||
}
|
||||
@ -2246,7 +2243,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
}).collect();
|
||||
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
|
||||
if let hir::ParamName::Plain(_) = lifetime_i_name {
|
||||
let name = lifetime_i_name.name();
|
||||
let name = lifetime_i_name.ident().name;
|
||||
if name == keywords::UnderscoreLifetime.name() ||
|
||||
name == keywords::StaticLifetime.name() {
|
||||
let mut err = struct_span_err!(
|
||||
@ -2254,7 +2251,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
lifetime_i.span,
|
||||
E0262,
|
||||
"invalid lifetime parameter name: `{}`",
|
||||
name
|
||||
lifetime_i.name.ident(),
|
||||
);
|
||||
err.span_label(
|
||||
lifetime_i.span,
|
||||
@ -2272,7 +2269,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
lifetime_j.span,
|
||||
E0263,
|
||||
"lifetime name `{}` declared twice in the same scope",
|
||||
lifetime_j.name.name()
|
||||
lifetime_j.name.ident()
|
||||
).span_label(lifetime_j.span, "declared twice")
|
||||
.span_label(lifetime_i.span, "previous declaration here")
|
||||
.emit();
|
||||
@ -2301,12 +2298,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
lifetime_i.span.to(lt.span),
|
||||
&format!(
|
||||
"unnecessary lifetime parameter `{}`",
|
||||
lifetime_i.name.name(),
|
||||
lifetime_i.name.ident(),
|
||||
),
|
||||
).help(&format!(
|
||||
"you can use the `'static` lifetime directly, in place \
|
||||
of `{}`",
|
||||
lifetime_i.name.name(),
|
||||
lifetime_i.name.ident(),
|
||||
)).emit();
|
||||
}
|
||||
hir::LifetimeName::Param(_)
|
||||
@ -2325,13 +2322,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
mut old_scope: ScopeRef,
|
||||
param: &'tcx hir::GenericParam,
|
||||
) {
|
||||
for &(label, label_span) in &self.labels_in_fn {
|
||||
for label in &self.labels_in_fn {
|
||||
// FIXME (#24278): non-hygienic comparison
|
||||
if param.name.name() == label {
|
||||
if param.name.ident().name == label.name {
|
||||
signal_shadowing_problem(
|
||||
self.tcx,
|
||||
label,
|
||||
original_label(label_span),
|
||||
label.name,
|
||||
original_label(label.span),
|
||||
shadower_lifetime(¶m),
|
||||
);
|
||||
return;
|
||||
@ -2353,12 +2350,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
Scope::Binder {
|
||||
ref lifetimes, s, ..
|
||||
} => {
|
||||
if let Some(&def) = lifetimes.get(¶m.name) {
|
||||
if let Some(&def) = lifetimes.get(¶m.name.modern()) {
|
||||
let node_id = self.tcx.hir.as_local_node_id(def.id().unwrap()).unwrap();
|
||||
|
||||
signal_shadowing_problem(
|
||||
self.tcx,
|
||||
param.name.name(),
|
||||
param.name.ident().name,
|
||||
original_lifetime(self.tcx.hir.span(node_id)),
|
||||
shadower_lifetime(¶m),
|
||||
);
|
||||
@ -2520,7 +2517,8 @@ fn insert_late_bound_lifetimes(
|
||||
hir::GenericParamKind::Lifetime { .. } => {
|
||||
if !param.bounds.is_empty() {
|
||||
// `'a: 'b` means both `'a` and `'b` are referenced
|
||||
appears_in_where_clause.regions.insert(hir::LifetimeName::Param(param.name));
|
||||
appears_in_where_clause
|
||||
.regions.insert(hir::LifetimeName::Param(param.name.modern()));
|
||||
}
|
||||
}
|
||||
hir::GenericParamKind::Type { .. } => {}
|
||||
@ -2537,7 +2535,7 @@ fn insert_late_bound_lifetimes(
|
||||
// - do not appear in the where-clauses
|
||||
// - are not implicitly captured by `impl Trait`
|
||||
for param in &generics.params {
|
||||
let lt_name = hir::LifetimeName::Param(param.name);
|
||||
let lt_name = hir::LifetimeName::Param(param.name.modern());
|
||||
// appears in the where clauses? early-bound.
|
||||
if appears_in_where_clause.regions.contains(<_name) {
|
||||
continue;
|
||||
@ -2551,7 +2549,7 @@ fn insert_late_bound_lifetimes(
|
||||
}
|
||||
|
||||
debug!("insert_late_bound_lifetimes: lifetime {:?} with id {:?} is late-bound",
|
||||
param.name.name(),
|
||||
param.name.ident(),
|
||||
param.id);
|
||||
|
||||
let inserted = map.late_bound.insert(param.id);
|
||||
@ -2596,7 +2594,7 @@ fn insert_late_bound_lifetimes(
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
|
||||
self.regions.insert(lifetime_ref.name);
|
||||
self.regions.insert(lifetime_ref.name.modern());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2610,7 +2608,7 @@ fn insert_late_bound_lifetimes(
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
|
||||
self.regions.insert(lifetime_ref.name);
|
||||
self.regions.insert(lifetime_ref.name.modern());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -744,7 +744,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||
for impl_item_ref in impl_item_refs {
|
||||
let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
|
||||
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 {
|
||||
// Pass `None` to skip deprecation warnings.
|
||||
self.tcx.check_stability(def_id, None, impl_item.span);
|
||||
|
@ -130,7 +130,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
.filter(|item| item.kind == ty::AssociatedKind::Method)
|
||||
.filter_map(|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| {
|
||||
if let ObjectSafetyViolation::Method(_,
|
||||
MethodViolationCode::WhereClauseReferencesSelf(span)) = violation {
|
||||
@ -159,7 +159,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
violations.extend(self.associated_items(trait_def_id)
|
||||
.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={:?}) = {:?}",
|
||||
trait_def_id,
|
||||
|
@ -31,7 +31,7 @@ use infer::type_variable::TypeVariableOrigin;
|
||||
use middle::const_val::ConstVal;
|
||||
use mir::interpret::{GlobalId};
|
||||
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::ast::Ident;
|
||||
use ty::subst::{Subst, Substs};
|
||||
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
|
||||
use ty::fold::{TypeFoldable, TypeFolder};
|
||||
@ -1349,10 +1349,10 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(
|
||||
obligation.predicate.self_ty(),
|
||||
gen_sig)
|
||||
.map_bound(|(trait_ref, yield_ty, return_ty)| {
|
||||
let name = tcx.associated_item(obligation.predicate.item_def_id).name;
|
||||
let ty = if name == Symbol::intern("Return") {
|
||||
let name = tcx.associated_item(obligation.predicate.item_def_id).ident.name;
|
||||
let ty = if name == "Return" {
|
||||
return_ty
|
||||
} else if name == Symbol::intern("Yield") {
|
||||
} else if name == "Yield" {
|
||||
yield_ty
|
||||
} else {
|
||||
bug!()
|
||||
@ -1452,7 +1452,7 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
|
||||
projection_ty: ty::ProjectionTy::from_ref_and_name(
|
||||
tcx,
|
||||
trait_ref,
|
||||
Symbol::intern(FN_OUTPUT_NAME),
|
||||
Ident::from_str(FN_OUTPUT_NAME),
|
||||
),
|
||||
ty: ret_type
|
||||
}
|
||||
@ -1508,7 +1508,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
|
||||
// checker method `check_impl_items_against_trait`, so here we
|
||||
// just return TyError.
|
||||
debug!("confirm_impl_candidate: no associated type {:?} for {:?}",
|
||||
assoc_ty.item.name,
|
||||
assoc_ty.item.ident,
|
||||
obligation.predicate);
|
||||
tcx.types.err
|
||||
} else {
|
||||
@ -1533,7 +1533,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
|
||||
-> specialization_graph::NodeItem<ty::AssociatedItem>
|
||||
{
|
||||
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 = tcx.trait_def(trait_def_id);
|
||||
|
||||
@ -1546,7 +1546,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
|
||||
let impl_node = specialization_graph::Node::Impl(impl_def_id);
|
||||
for item in impl_node.items(tcx) {
|
||||
if item.kind == ty::AssociatedKind::Type &&
|
||||
tcx.hygienic_eq(item.name, assoc_ty_name, trait_def_id) {
|
||||
tcx.hygienic_eq(item.ident, assoc_ty_name, trait_def_id) {
|
||||
return specialization_graph::NodeItem {
|
||||
node: specialization_graph::Node::Impl(impl_def_id),
|
||||
item,
|
||||
|
@ -129,7 +129,7 @@ pub fn find_associated_item<'a, 'tcx>(
|
||||
let trait_def = tcx.trait_def(trait_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) => {
|
||||
let substs = tcx.infer_ctxt().enter(|infcx| {
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
|
@ -18,7 +18,7 @@ use traits;
|
||||
use ty::{self, TyCtxt, TypeFoldable};
|
||||
use ty::fast_reject::{self, SimplifiedType};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use syntax::ast::Name;
|
||||
use syntax::ast::Ident;
|
||||
use util::captures::Captures;
|
||||
use util::nodemap::{DefIdMap, FxHashMap};
|
||||
|
||||
@ -372,14 +372,14 @@ impl<'a, 'gcx, 'tcx> Ancestors {
|
||||
pub fn defs(
|
||||
self,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
trait_item_name: Name,
|
||||
trait_item_name: Ident,
|
||||
trait_item_kind: ty::AssociatedKind,
|
||||
trait_def_id: DefId,
|
||||
) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a {
|
||||
self.flat_map(move |node| {
|
||||
node.items(tcx).filter(move |impl_item| {
|
||||
impl_item.kind == trait_item_kind &&
|
||||
tcx.hygienic_eq(impl_item.name, trait_item_name, trait_def_id)
|
||||
tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id)
|
||||
}).map(move |item| NodeItem { node: node, item: item })
|
||||
})
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ pub struct ImplHeader<'tcx> {
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct AssociatedItem {
|
||||
pub def_id: DefId,
|
||||
pub name: Name,
|
||||
pub ident: Ident,
|
||||
pub kind: AssociatedKind,
|
||||
pub vis: Visibility,
|
||||
pub defaultness: hir::Defaultness,
|
||||
@ -224,9 +224,9 @@ impl AssociatedItem {
|
||||
// regions just fine, showing `fn(&MyType)`.
|
||||
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 => {
|
||||
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 {
|
||||
name: trait_item_ref.name,
|
||||
ident: trait_item_ref.ident,
|
||||
kind,
|
||||
// Visibility of trait items is inherited from their traits.
|
||||
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),
|
||||
};
|
||||
|
||||
ty::AssociatedItem {
|
||||
name: impl_item_ref.name,
|
||||
AssociatedItem {
|
||||
ident: impl_item_ref.ident,
|
||||
kind,
|
||||
// Visibility of trait impl items doesn't matter.
|
||||
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(
|
||||
self,
|
||||
def_id: DefId,
|
||||
) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
|
||||
) -> impl Iterator<Item = AssociatedItem> + 'a {
|
||||
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])))
|
||||
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
|
||||
@ -2717,9 +2717,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
// Hygienically compare a use-site name (`use_name`) for a field or an associated item with its
|
||||
// supposed definition name (`def_name`). The method also needs `DefId` of the supposed
|
||||
// definition's parent/scope to perform comparison.
|
||||
pub fn hygienic_eq(self, use_name: Name, def_name: Name, def_parent_def_id: DefId) -> bool {
|
||||
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 hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
|
||||
self.adjust_ident(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.modern()
|
||||
}
|
||||
|
||||
pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) {
|
||||
|
@ -25,7 +25,7 @@ use mir::interpret::{Scalar, Pointer, Value, ConstValue};
|
||||
use std::iter;
|
||||
use std::cmp::Ordering;
|
||||
use rustc_target::spec::abi;
|
||||
use syntax::ast::{self, Name};
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::symbol::{keywords, InternedString};
|
||||
|
||||
use serialize;
|
||||
@ -853,11 +853,11 @@ impl<'a, 'tcx> ProjectionTy<'tcx> {
|
||||
/// Construct a ProjectionTy by searching the trait from trait_ref for the
|
||||
/// associated item named item_name.
|
||||
pub fn from_ref_and_name(
|
||||
tcx: TyCtxt, trait_ref: ty::TraitRef<'tcx>, item_name: Name
|
||||
tcx: TyCtxt, trait_ref: ty::TraitRef<'tcx>, item_name: Ident
|
||||
) -> ProjectionTy<'tcx> {
|
||||
let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| {
|
||||
item.kind == ty::AssociatedKind::Type &&
|
||||
tcx.hygienic_eq(item_name, item.name, trait_ref.def_id)
|
||||
tcx.hygienic_eq(item_name, item.ident, trait_ref.def_id)
|
||||
}).unwrap().def_id;
|
||||
|
||||
ProjectionTy {
|
||||
|
@ -429,7 +429,7 @@ impl PrintContext {
|
||||
ty::tls::with(|tcx|
|
||||
print!(f, self,
|
||||
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))
|
||||
)?;
|
||||
}
|
||||
@ -1286,7 +1286,7 @@ define_print! {
|
||||
// parameterized(f, self.substs, self.item_def_id, &[])
|
||||
// (which currently ICEs).
|
||||
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))
|
||||
}
|
||||
|
@ -109,10 +109,10 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
||||
cmt: &'c mc::cmt_<'tcx>) {
|
||||
let source = get_pattern_source(bccx.tcx,move_pat);
|
||||
let pat_span_path_opt = match move_pat.node {
|
||||
PatKind::Binding(_, _, ref path1, _) => {
|
||||
PatKind::Binding(_, _, ident, _) => {
|
||||
Some(MovePlace {
|
||||
span: move_pat.span,
|
||||
name: path1.node,
|
||||
name: ident.name,
|
||||
pat_source: source,
|
||||
})
|
||||
}
|
||||
|
@ -46,11 +46,9 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
|
||||
let tcx = self.bccx.tcx;
|
||||
let mut mutables = FxHashMap();
|
||||
for p in pats {
|
||||
p.each_binding(|_, hir_id, span, path1| {
|
||||
let name = path1.node;
|
||||
|
||||
p.each_binding(|_, hir_id, span, ident| {
|
||||
// Skip anything that looks like `_foo`
|
||||
if name.as_str().starts_with("_") {
|
||||
if ident.as_str().starts_with("_") {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,7 +63,7 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
|
||||
_ => return,
|
||||
}
|
||||
|
||||
mutables.entry(name).or_insert(Vec::new()).push((hir_id, span));
|
||||
mutables.entry(ident.name).or_insert(Vec::new()).push((hir_id, span));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1075,7 +1075,7 @@ impl RustcDefaultCalls {
|
||||
let mut cfgs = Vec::new();
|
||||
for &(name, ref value) in sess.parse_sess.config.iter() {
|
||||
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,
|
||||
span: DUMMY_SP,
|
||||
});
|
||||
|
@ -151,7 +151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
|
||||
GenericParamKind::Lifetime { .. } => {}
|
||||
GenericParamKind::Type { synthetic, .. } => {
|
||||
if synthetic.is_none() {
|
||||
self.check_case(cx, "type parameter", param.name.name(), param.span);
|
||||
self.check_case(cx, "type parameter", param.name.ident().name, param.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -258,7 +258,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
|
||||
fn check_generic_param(&mut self, cx: &LateContext, param: &hir::GenericParam) {
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
let name = param.name.name().as_str();
|
||||
let name = param.name.ident().as_str();
|
||||
self.check_snake_case(cx, "lifetime", &name, Some(param.span));
|
||||
}
|
||||
GenericParamKind::Type { .. } => {}
|
||||
@ -302,20 +302,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) {
|
||||
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(ref names)) = item.node {
|
||||
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(ref pnames)) = item.node {
|
||||
self.check_snake_case(cx,
|
||||
"trait method",
|
||||
&item.name.as_str(),
|
||||
&item.ident.as_str(),
|
||||
Some(item.span));
|
||||
for name in names {
|
||||
self.check_snake_case(cx, "variable", &name.node.as_str(), Some(name.span));
|
||||
for param_name in pnames {
|
||||
self.check_snake_case(cx, "variable", ¶m_name.as_str(), Some(param_name.span));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
|
||||
if let &PatKind::Binding(_, _, ref path1, _) = &p.node {
|
||||
self.check_snake_case(cx, "variable", &path1.node.as_str(), Some(p.span));
|
||||
if let &PatKind::Binding(_, _, ref ident, _) = &p.node {
|
||||
self.check_snake_case(cx, "variable", &ident.as_str(), Some(p.span));
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,7 +385,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
|
||||
fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) {
|
||||
match ti.node {
|
||||
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) {
|
||||
match ii.node {
|
||||
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);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -407,7 +409,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
|
||||
if path.segments.len() == 1 {
|
||||
NonUpperCaseGlobals::check_upper_case(cx,
|
||||
"constant in pattern",
|
||||
path.segments[0].name,
|
||||
path.segments[0].ident.name,
|
||||
path.span);
|
||||
}
|
||||
}
|
||||
|
@ -182,18 +182,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
|
||||
// (Issue #49588)
|
||||
continue;
|
||||
}
|
||||
if let PatKind::Binding(_, _, name, None) = fieldpat.node.pat.node {
|
||||
let binding_ident = ast::Ident::new(name.node, name.span);
|
||||
if cx.tcx.find_field_index(binding_ident, &variant) ==
|
||||
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node {
|
||||
if cx.tcx.find_field_index(ident, &variant) ==
|
||||
Some(cx.tcx.field_index(fieldpat.node.id, cx.tables)) {
|
||||
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,
|
||||
fieldpat.span,
|
||||
&format!("the `{}:` in this pattern is redundant",
|
||||
name.node));
|
||||
&format!("the `{}:` in this pattern is redundant", ident));
|
||||
let subspan = cx.tcx.sess.codemap().span_through_char(fieldpat.span, ':');
|
||||
err.span_suggestion_short(subspan,
|
||||
"remove this",
|
||||
format!("{}", name.node));
|
||||
err.span_suggestion_short(subspan, "remove this", format!("{}", ident));
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
@ -1082,7 +1078,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
|
||||
let container = ty::ImplContainer(vtable_impl.impl_def_id);
|
||||
// It matches if it comes from the same impl,
|
||||
// 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
|
||||
|
@ -817,7 +817,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
};
|
||||
|
||||
ty::AssociatedItem {
|
||||
name: name.as_symbol(),
|
||||
ident: Ident::from_interned_str(name),
|
||||
kind,
|
||||
vis: item.visibility.decode(self),
|
||||
defaultness: container.defaultness(),
|
||||
|
@ -39,9 +39,8 @@ use std::path::Path;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use std::u32;
|
||||
use syntax::ast::{self, CRATE_NODE_ID};
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::attr;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax_pos::{self, hygiene, FileName, FileMap, Span, DUMMY_SP};
|
||||
|
||||
use rustc::hir::{self, PatKind};
|
||||
@ -975,16 +974,15 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
||||
let body = self.tcx.hir.body(body_id);
|
||||
self.lazy_seq(body.arguments.iter().map(|arg| {
|
||||
match arg.pat.node {
|
||||
PatKind::Binding(_, _, name, _) => name.node,
|
||||
_ => Symbol::intern("")
|
||||
PatKind::Binding(_, _, ident, _) => ident.name,
|
||||
_ => keywords::Invalid.name(),
|
||||
}
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
fn encode_fn_arg_names(&mut self, names: &[Spanned<ast::Name>])
|
||||
-> LazySeq<ast::Name> {
|
||||
self.lazy_seq(names.iter().map(|name| name.node))
|
||||
fn encode_fn_arg_names(&mut self, param_names: &[ast::Ident]) -> LazySeq<ast::Name> {
|
||||
self.lazy_seq(param_names.iter().map(|ident| ident.name))
|
||||
}
|
||||
|
||||
fn encode_optimized_mir(&mut self, def_id: DefId) -> Option<Lazy<mir::Mir<'tcx>>> {
|
||||
|
@ -15,6 +15,7 @@
|
||||
#![feature(box_patterns)]
|
||||
#![feature(fs_read_write)]
|
||||
#![feature(libc)]
|
||||
#![feature(macro_at_most_once_rep)]
|
||||
#![cfg_attr(stage0, feature(macro_lifetime_matcher))]
|
||||
#![feature(proc_macro_internals)]
|
||||
#![feature(quote)]
|
||||
|
@ -538,8 +538,8 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
|
||||
mutability: Mutability::Not,
|
||||
};
|
||||
if let Some(hir::map::NodeBinding(pat)) = tcx.hir.find(var_id) {
|
||||
if let hir::PatKind::Binding(_, _, ref name, _) = pat.node {
|
||||
decl.debug_name = name.node;
|
||||
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
|
||||
decl.debug_name = ident.name;
|
||||
|
||||
let bm = *hir.tables.pat_binding_modes()
|
||||
.get(pat.hir_id)
|
||||
@ -675,8 +675,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
// If this is a simple binding pattern, give the local a nice name for debuginfo.
|
||||
let mut name = None;
|
||||
if let Some(pat) = pattern {
|
||||
if let hir::PatKind::Binding(_, _, ref ident, _) = pat.node {
|
||||
name = Some(ident.node);
|
||||
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
|
||||
name = Some(ident.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
|
||||
let method_name = Symbol::intern(method_name);
|
||||
let substs = self.tcx.mk_substs_trait(self_ty, params);
|
||||
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 = method_ty.subst(self.tcx, substs);
|
||||
return (method_ty,
|
||||
|
@ -308,7 +308,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
|
||||
|
||||
fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
|
||||
pat.walk(|p| {
|
||||
if let PatKind::Binding(_, _, name, None) = p.node {
|
||||
if let PatKind::Binding(_, _, ident, None) = p.node {
|
||||
let bm = *cx.tables
|
||||
.pat_binding_modes()
|
||||
.get(p.hir_id)
|
||||
@ -321,17 +321,17 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
|
||||
let pat_ty = cx.tables.pat_ty(p);
|
||||
if let ty::TyAdt(edef, _) = pat_ty.sty {
|
||||
if edef.is_enum() && edef.variants.iter().any(|variant| {
|
||||
variant.name == name.node && variant.ctor_kind == CtorKind::Const
|
||||
variant.name == ident.name && variant.ctor_kind == CtorKind::Const
|
||||
}) {
|
||||
let ty_path = cx.tcx.item_path_str(edef.did);
|
||||
let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
|
||||
"pattern binding `{}` is named the same as one \
|
||||
of the variants of the type `{}`",
|
||||
name.node, ty_path);
|
||||
ident, ty_path);
|
||||
err.span_suggestion_with_applicability(
|
||||
p.span,
|
||||
"to match on the variant, qualify the path",
|
||||
format!("{}::{}", ty_path, name.node),
|
||||
format!("{}::{}", ty_path, ident),
|
||||
Applicability::MachineApplicable
|
||||
);
|
||||
err.emit();
|
||||
|
@ -461,7 +461,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
PatKind::Binding(_, id, ref name, ref sub) => {
|
||||
PatKind::Binding(_, id, ident, ref sub) => {
|
||||
let var_ty = self.tables.node_id_to_type(pat.hir_id);
|
||||
let region = match var_ty.sty {
|
||||
ty::TyRef(r, _, _) => Some(r),
|
||||
@ -491,14 +491,14 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
if let ty::TyRef(_, rty, _) = ty.sty {
|
||||
ty = rty;
|
||||
} else {
|
||||
bug!("`ref {}` has wrong type {}", name.node, ty);
|
||||
bug!("`ref {}` has wrong type {}", ident, ty);
|
||||
}
|
||||
}
|
||||
|
||||
PatternKind::Binding {
|
||||
mutability,
|
||||
mode,
|
||||
name: name.node,
|
||||
name: ident.name,
|
||||
var: id,
|
||||
ty: var_ty,
|
||||
subpattern: self.lower_opt_pattern(sub),
|
||||
|
@ -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) {
|
||||
let overridden_methods: FxHashSet<_> =
|
||||
impl_item_refs.iter()
|
||||
.map(|iiref| iiref.name)
|
||||
.map(|iiref| iiref.ident.modern())
|
||||
.collect();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
|
||||
|
||||
for projection in projections {
|
||||
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("=");
|
||||
self.push_type_name(projection.ty, output);
|
||||
|
@ -830,8 +830,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
|
||||
let is_local_static = if let Def::Static(..) = def { def_id.is_local() } else { false };
|
||||
if !self.item_is_accessible(def_id) && !is_local_static {
|
||||
let name = match *qpath {
|
||||
hir::QPath::Resolved(_, ref path) => format!("{}", path),
|
||||
hir::QPath::TypeRelative(_, ref segment) => segment.name.to_string(),
|
||||
hir::QPath::Resolved(_, ref path) => path.to_string(),
|
||||
hir::QPath::TypeRelative(_, ref segment) => segment.ident.to_string(),
|
||||
};
|
||||
let msg = format!("{} `{}` is private", def.kind_name(), name);
|
||||
self.tcx.sess.span_err(span, &msg);
|
||||
|
@ -1497,17 +1497,17 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
|
||||
args: Option<P<hir::GenericArgs>>,
|
||||
is_value: bool
|
||||
) -> hir::Path {
|
||||
let mut segments = iter::once(keywords::CrateRoot.name())
|
||||
let mut segments = iter::once(keywords::CrateRoot.ident())
|
||||
.chain(
|
||||
crate_root.into_iter()
|
||||
.chain(components.iter().cloned())
|
||||
.map(Symbol::intern)
|
||||
).map(hir::PathSegment::from_name).collect::<Vec<_>>();
|
||||
.map(Ident::from_str)
|
||||
).map(hir::PathSegment::from_ident).collect::<Vec<_>>();
|
||||
|
||||
if let Some(args) = args {
|
||||
let name = segments.last().unwrap().name;
|
||||
let ident = segments.last().unwrap().ident;
|
||||
*segments.last_mut().unwrap() = hir::PathSegment {
|
||||
name,
|
||||
ident,
|
||||
args: Some(args),
|
||||
infer_types: true,
|
||||
};
|
||||
@ -1550,16 +1550,16 @@ impl<'a> Resolver<'a> {
|
||||
hir::Path {
|
||||
span,
|
||||
def: Def::Err,
|
||||
segments: iter::once(keywords::CrateRoot.name()).chain({
|
||||
path_str.split("::").skip(1).map(Symbol::intern)
|
||||
}).map(hir::PathSegment::from_name).collect(),
|
||||
segments: iter::once(keywords::CrateRoot.ident()).chain({
|
||||
path_str.split("::").skip(1).map(Ident::from_str)
|
||||
}).map(hir::PathSegment::from_ident).collect(),
|
||||
}
|
||||
} else {
|
||||
hir::Path {
|
||||
span,
|
||||
def: Def::Err,
|
||||
segments: path_str.split("::").map(Symbol::intern)
|
||||
.map(hir::PathSegment::from_name).collect(),
|
||||
segments: path_str.split("::").map(Ident::from_str)
|
||||
.map(hir::PathSegment::from_ident).collect(),
|
||||
}
|
||||
};
|
||||
self.resolve_hir_path_cb(&mut path, is_value, |_, _, _| errored = true);
|
||||
@ -1572,13 +1572,11 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
/// resolve_hir_path, but takes a callback in case there was an error
|
||||
fn resolve_hir_path_cb<F>(&mut self, path: &mut hir::Path, is_value: bool, error_callback: F)
|
||||
where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
|
||||
{
|
||||
where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
|
||||
{
|
||||
let namespace = if is_value { ValueNS } else { TypeNS };
|
||||
let hir::Path { ref segments, span, ref mut def } = *path;
|
||||
let path: Vec<Ident> = segments.iter()
|
||||
.map(|seg| Ident::new(seg.name, span))
|
||||
.collect();
|
||||
let path: Vec<_> = segments.iter().map(|seg| seg.ident).collect();
|
||||
// FIXME (Manishearth): Intra doc links won't get warned of epoch changes
|
||||
match self.resolve_path(&path, Some(namespace), true, span, CrateLint::No) {
|
||||
PathResult::Module(module) => *def = module.def().unwrap(),
|
||||
@ -3507,7 +3505,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
match path.get(1) {
|
||||
// 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
|
||||
Some(_) => {}
|
||||
// If the path has length one (and it's `CrateRoot` most likely)
|
||||
|
@ -316,14 +316,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
|
||||
sig: &'l ast::MethodSig,
|
||||
body: Option<&'l ast::Block>,
|
||||
id: ast::NodeId,
|
||||
name: ast::Ident,
|
||||
ident: ast::Ident,
|
||||
generics: &'l ast::Generics,
|
||||
vis: ast::Visibility,
|
||||
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);
|
||||
if body.is_some() {
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
qualname.push_str(&self.tcx.item_path_str(def_id));
|
||||
self.tcx
|
||||
.associated_items(def_id)
|
||||
.find(|item| item.name == name)
|
||||
.find(|item| item.ident.name == name)
|
||||
.map(|item| decl_id = Some(item.def_id));
|
||||
}
|
||||
qualname.push_str(">");
|
||||
@ -775,7 +775,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
let ti = self.tcx.associated_item(decl_id);
|
||||
self.tcx
|
||||
.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)
|
||||
} else {
|
||||
None
|
||||
|
@ -417,7 +417,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
|
||||
let hypotheses = vec![trait_implemented];
|
||||
|
||||
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
|
||||
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name);
|
||||
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)`
|
||||
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });
|
||||
|
@ -83,7 +83,7 @@ pub trait AstConv<'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
struct ConvertedBinding<'tcx> {
|
||||
item_name: ast::Name,
|
||||
item_name: ast::Ident,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
}
|
||||
@ -342,7 +342,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
|
||||
let assoc_bindings = generic_args.bindings.iter().map(|binding| {
|
||||
ConvertedBinding {
|
||||
item_name: binding.name,
|
||||
item_name: binding.ident,
|
||||
ty: self.ast_ty_to_ty(&binding.ty),
|
||||
span: binding.span,
|
||||
}
|
||||
@ -485,12 +485,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
|
||||
fn trait_defines_associated_type_named(&self,
|
||||
trait_def_id: DefId,
|
||||
assoc_name: ast::Name)
|
||||
assoc_name: ast::Ident)
|
||||
-> bool
|
||||
{
|
||||
self.tcx().associated_items(trait_def_id).any(|item| {
|
||||
item.kind == ty::AssociatedKind::Type &&
|
||||
self.tcx().hygienic_eq(assoc_name, item.name, trait_def_id)
|
||||
self.tcx().hygienic_eq(assoc_name, item.ident, trait_def_id)
|
||||
})
|
||||
}
|
||||
|
||||
@ -569,9 +569,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
}?;
|
||||
|
||||
let (assoc_ident, def_scope) =
|
||||
tcx.adjust_ident(binding.item_name.to_ident(), 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| {
|
||||
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");
|
||||
|
||||
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();
|
||||
struct_span_err!(tcx.sess, span, E0191,
|
||||
"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))
|
||||
.span_label(span, format!(
|
||||
"missing associated type `{}` value", assoc_item.name))
|
||||
"missing associated type `{}` value", assoc_item.ident))
|
||||
.emit();
|
||||
}
|
||||
|
||||
@ -778,7 +778,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
// any ambiguity.
|
||||
fn find_bound_for_assoc_item(&self,
|
||||
ty_param_def_id: DefId,
|
||||
assoc_name: ast::Name,
|
||||
assoc_name: ast::Ident,
|
||||
span: Span)
|
||||
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
|
||||
{
|
||||
@ -807,7 +807,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
fn one_bound_for_assoc_type<I>(&self,
|
||||
mut bounds: I,
|
||||
ty_param_name: &str,
|
||||
assoc_name: ast::Name,
|
||||
assoc_name: ast::Ident,
|
||||
span: Span)
|
||||
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
|
||||
where I: Iterator<Item=ty::PolyTraitRef<'tcx>>
|
||||
@ -837,7 +837,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
for bound in bounds {
|
||||
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
|
||||
item.kind == ty::AssociatedKind::Type &&
|
||||
self.tcx().hygienic_eq(assoc_name, item.name, 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));
|
||||
|
||||
@ -873,7 +873,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
-> (Ty<'tcx>, Def)
|
||||
{
|
||||
let tcx = self.tcx();
|
||||
let assoc_name = item_segment.name;
|
||||
let assoc_name = item_segment.ident;
|
||||
|
||||
debug!("associated_path_def_to_ty: {:?}::{}", ty, assoc_name);
|
||||
|
||||
@ -895,8 +895,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
|
||||
let candidates =
|
||||
traits::supertraits(tcx, ty::Binder::bind(trait_ref))
|
||||
.filter(|r| self.trait_defines_associated_type_named(r.def_id(),
|
||||
assoc_name));
|
||||
.filter(|r| self.trait_defines_associated_type_named(r.def_id(), assoc_name));
|
||||
|
||||
match self.one_bound_for_assoc_type(candidates, "Self", assoc_name, span) {
|
||||
Ok(bound) => bound,
|
||||
@ -923,10 +922,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
};
|
||||
|
||||
let trait_did = bound.def_id();
|
||||
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name.to_ident(), 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| {
|
||||
Namespace::from(i.kind) == Namespace::Type &&
|
||||
i.name.to_ident() == assoc_ident
|
||||
i.ident.modern() == assoc_ident
|
||||
})
|
||||
.expect("missing associated type");
|
||||
|
||||
@ -963,7 +962,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
self.report_ambiguous_associated_type(span,
|
||||
"Type",
|
||||
&path_str,
|
||||
&item_segment.name.as_str());
|
||||
&item_segment.ident.as_str());
|
||||
return tcx.types.err;
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,7 @@ use rustc::ty::{ToPredicate, TypeFoldable};
|
||||
use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref};
|
||||
|
||||
use syntax_pos::Span;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::ast::Ident;
|
||||
|
||||
use std::iter;
|
||||
|
||||
@ -134,7 +134,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
|
||||
ty::ProjectionTy::from_ref_and_name(
|
||||
tcx,
|
||||
trait_ref,
|
||||
Symbol::intern("Target"),
|
||||
Ident::from_str("Target"),
|
||||
),
|
||||
cause,
|
||||
0,
|
||||
|
@ -18,7 +18,7 @@ use rustc::{infer, traits};
|
||||
use rustc::ty::{self, TyCtxt, TypeFoldable, Ty};
|
||||
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc_target::spec::abi;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::ast::Ident;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use rustc::hir;
|
||||
@ -157,9 +157,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
MethodCallee<'tcx>)> {
|
||||
// Try the options that are least restrictive on the caller first.
|
||||
for &(opt_trait_def_id, method_name, borrow) in
|
||||
&[(self.tcx.lang_items().fn_trait(), Symbol::intern("call"), true),
|
||||
(self.tcx.lang_items().fn_mut_trait(), Symbol::intern("call_mut"), true),
|
||||
(self.tcx.lang_items().fn_once_trait(), Symbol::intern("call_once"), false)] {
|
||||
&[(self.tcx.lang_items().fn_trait(), Ident::from_str("call"), true),
|
||||
(self.tcx.lang_items().fn_mut_trait(), Ident::from_str("call_mut"), true),
|
||||
(self.tcx.lang_items().fn_once_trait(), Ident::from_str("call_once"), false)] {
|
||||
let trait_def_id = match opt_trait_def_id {
|
||||
Some(def_id) => def_id,
|
||||
None => continue,
|
||||
|
@ -100,7 +100,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
span: impl_m_span,
|
||||
body_id: impl_m_node_id,
|
||||
code: ObligationCauseCode::CompareImplMethodObligation {
|
||||
item_name: impl_m.name,
|
||||
item_name: impl_m.ident.name,
|
||||
impl_item_def_id: impl_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),
|
||||
E0053,
|
||||
"method `{}` has an incompatible type for trait",
|
||||
trait_m.name);
|
||||
trait_m.ident);
|
||||
|
||||
infcx.note_type_err(&mut diag,
|
||||
&cause,
|
||||
@ -383,7 +383,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
E0195,
|
||||
"lifetime parameters or bounds on method `{}` do not match \
|
||||
the trait declaration",
|
||||
impl_m.name);
|
||||
impl_m.ident);
|
||||
err.span_label(span, "lifetimes do not match method in trait");
|
||||
if let Some(sp) = tcx.hir.span_if_local(trait_m.def_id) {
|
||||
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,
|
||||
"method `{}` has a `{}` declaration in the impl, but \
|
||||
not in the trait",
|
||||
trait_m.name,
|
||||
trait_m.ident,
|
||||
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) {
|
||||
err.span_label(span, format!("trait method declared without `{}`", self_descr));
|
||||
} else {
|
||||
err.note_trait_signature(trait_m.name.to_string(),
|
||||
err.note_trait_signature(trait_m.ident.to_string(),
|
||||
trait_m.signature(&tcx));
|
||||
}
|
||||
err.emit();
|
||||
@ -549,13 +549,13 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
E0186,
|
||||
"method `{}` has a `{}` declaration in the trait, but \
|
||||
not in the impl",
|
||||
trait_m.name,
|
||||
trait_m.ident,
|
||||
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) {
|
||||
err.span_label(span, format!("`{}` used in trait", self_descr));
|
||||
} else {
|
||||
err.note_trait_signature(trait_m.name.to_string(),
|
||||
err.note_trait_signature(trait_m.ident.to_string(),
|
||||
trait_m.signature(&tcx));
|
||||
}
|
||||
err.emit();
|
||||
@ -590,7 +590,7 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
E0049,
|
||||
"method `{}` has {} type parameter{} but its trait \
|
||||
declaration has {} type parameter{}",
|
||||
trait_m.name,
|
||||
trait_m.ident,
|
||||
num_impl_m_type_params,
|
||||
if num_impl_m_type_params == 1 { "" } else { "s" },
|
||||
num_trait_m_type_params,
|
||||
@ -681,7 +681,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
E0050,
|
||||
"method `{}` has {} parameter{} but the declaration in \
|
||||
trait `{}` has {}",
|
||||
trait_m.name,
|
||||
trait_m.ident,
|
||||
impl_number_args,
|
||||
if impl_number_args == 1 { "" } else { "s" },
|
||||
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)
|
||||
}));
|
||||
} else {
|
||||
err.note_trait_signature(trait_m.name.to_string(),
|
||||
err.note_trait_signature(trait_m.ident.to_string(),
|
||||
trait_m.signature(&tcx));
|
||||
}
|
||||
err.span_label(impl_span,
|
||||
@ -748,7 +748,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
impl_span,
|
||||
E0643,
|
||||
"method `{}` has incompatible signature for trait",
|
||||
trait_m.name);
|
||||
trait_m.ident);
|
||||
err.span_label(trait_span, "declaration in trait here");
|
||||
match (impl_synthetic, trait_synthetic) {
|
||||
// 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,
|
||||
"implemented const `{}` has an incompatible type for \
|
||||
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_span = trait_c_node_id.map(|trait_c_node_id| {
|
||||
|
@ -146,7 +146,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
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) {
|
||||
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<_>>();
|
||||
if !suggestions.is_empty() {
|
||||
err.span_suggestions(expr.span,
|
||||
@ -226,7 +226,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
})), 1) = (self.tcx.hir.find(parent), decl.inputs.len()) {
|
||||
let self_ty = self.tables.borrow().node_id_to_type(expr[0].hir_id);
|
||||
let self_ty = format!("{:?}", self_ty);
|
||||
let name = path.name.as_str();
|
||||
let name = path.ident.as_str();
|
||||
let is_as_ref_able = (
|
||||
self_ty.starts_with("&std::option::Option") ||
|
||||
self_ty.starts_with("&std::result::Result") ||
|
||||
|
@ -120,7 +120,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
allow_private: bool)
|
||||
-> bool {
|
||||
let mode = probe::Mode::MethodCall;
|
||||
match self.probe_for_name(method_name.span, mode, method_name.name,
|
||||
match self.probe_for_name(method_name.span, mode, method_name,
|
||||
IsSuggestion(false), self_ty, call_expr_id,
|
||||
ProbeScope::TraitsInScope) {
|
||||
Ok(..) => true,
|
||||
@ -157,14 +157,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
self_expr: &'gcx hir::Expr)
|
||||
-> Result<MethodCallee<'tcx>, MethodError<'tcx>> {
|
||||
debug!("lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})",
|
||||
segment.name,
|
||||
segment.ident,
|
||||
self_ty,
|
||||
call_expr,
|
||||
self_expr);
|
||||
|
||||
let pick = self.lookup_probe(
|
||||
span,
|
||||
segment.name,
|
||||
segment.ident,
|
||||
self_ty,
|
||||
call_expr,
|
||||
ProbeScope::TraitsInScope
|
||||
@ -192,7 +192,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
// We probe again, taking all traits into account (not only those in scope).
|
||||
let candidates =
|
||||
match self.lookup_probe(span,
|
||||
segment.name,
|
||||
segment.ident,
|
||||
self_ty,
|
||||
call_expr,
|
||||
ProbeScope::AllTraits) {
|
||||
@ -222,7 +222,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
fn lookup_probe(&self,
|
||||
span: Span,
|
||||
method_name: ast::Name,
|
||||
method_name: ast::Ident,
|
||||
self_ty: Ty<'tcx>,
|
||||
call_expr: &'gcx hir::Expr,
|
||||
scope: ProbeScope)
|
||||
@ -244,7 +244,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
/// of this method is basically the same as confirmation.
|
||||
pub fn lookup_method_in_trait(&self,
|
||||
span: Span,
|
||||
m_name: ast::Name,
|
||||
m_name: ast::Ident,
|
||||
trait_def_id: DefId,
|
||||
self_ty: Ty<'tcx>,
|
||||
opt_input_types: Option<&[Ty<'tcx>]>)
|
||||
@ -289,7 +289,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
// Trait must have a method named `m_name` and it should not have
|
||||
// type parameters or early-bound regions.
|
||||
let tcx = self.tcx;
|
||||
let method_item = self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap();
|
||||
let method_item =
|
||||
self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap();
|
||||
let def_id = method_item.def_id;
|
||||
let generics = tcx.generics_of(def_id);
|
||||
assert_eq!(generics.params.len(), 0);
|
||||
@ -362,7 +363,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
pub fn resolve_ufcs(&self,
|
||||
span: Span,
|
||||
method_name: ast::Name,
|
||||
method_name: ast::Ident,
|
||||
self_ty: Ty<'tcx>,
|
||||
expr_id: ast::NodeId)
|
||||
-> Result<Def, MethodError<'tcx>> {
|
||||
@ -385,10 +386,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
/// Find item with name `item_name` defined in impl/trait `def_id`
|
||||
/// and return it, or `None`, if no such item was defined there.
|
||||
pub fn associated_item(&self, def_id: DefId, item_name: ast::Name, ns: Namespace)
|
||||
pub fn associated_item(&self, def_id: DefId, item_name: ast::Ident, ns: Namespace)
|
||||
-> Option<ty::AssociatedItem> {
|
||||
self.tcx.associated_items(def_id)
|
||||
.find(|item| Namespace::from(item.kind) == ns &&
|
||||
self.tcx.hygienic_eq(item_name, item.name, def_id))
|
||||
self.tcx.associated_items(def_id).find(|item| {
|
||||
Namespace::from(item.kind) == ns &&
|
||||
self.tcx.hygienic_eq(item_name, item.ident, def_id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ struct ProbeContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
|
||||
fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
|
||||
span: Span,
|
||||
mode: Mode,
|
||||
method_name: Option<ast::Name>,
|
||||
method_name: Option<ast::Ident>,
|
||||
return_type: Option<Ty<'tcx>>,
|
||||
steps: Rc<Vec<CandidateStep<'tcx>>>,
|
||||
inherent_candidates: Vec<Candidate<'tcx>>,
|
||||
@ -213,7 +213,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn probe_for_name(&self,
|
||||
span: Span,
|
||||
mode: Mode,
|
||||
item_name: ast::Name,
|
||||
item_name: ast::Ident,
|
||||
is_suggestion: IsSuggestion,
|
||||
self_ty: Ty<'tcx>,
|
||||
scope_expr_id: ast::NodeId,
|
||||
@ -237,7 +237,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
fn probe_op<OP,R>(&'a self,
|
||||
span: Span,
|
||||
mode: Mode,
|
||||
method_name: Option<ast::Name>,
|
||||
method_name: Option<ast::Ident>,
|
||||
return_type: Option<Ty<'tcx>>,
|
||||
is_suggestion: IsSuggestion,
|
||||
self_ty: Ty<'tcx>,
|
||||
@ -382,7 +382,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
fn new(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
|
||||
span: Span,
|
||||
mode: Mode,
|
||||
method_name: Option<ast::Name>,
|
||||
method_name: Option<ast::Ident>,
|
||||
return_type: Option<Ty<'tcx>>,
|
||||
steps: Rc<Vec<CandidateStep<'tcx>>>,
|
||||
is_suggestion: IsSuggestion)
|
||||
@ -422,8 +422,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
{
|
||||
let is_accessible = if let Some(name) = self.method_name {
|
||||
let item = candidate.item;
|
||||
let def_scope =
|
||||
self.tcx.adjust_ident(name.to_ident(), item.container.id(), self.body_id).1;
|
||||
let def_scope = self.tcx.adjust_ident(name, item.container.id(), self.body_id).1;
|
||||
item.vis.is_accessible_from(def_scope, self.tcx)
|
||||
} else {
|
||||
true
|
||||
@ -799,7 +798,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn candidate_method_names(&self) -> Vec<ast::Name> {
|
||||
fn candidate_method_names(&self) -> Vec<ast::Ident> {
|
||||
let mut set = FxHashSet();
|
||||
let mut names: Vec<_> = self.inherent_candidates
|
||||
.iter()
|
||||
@ -811,7 +810,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
true
|
||||
}
|
||||
})
|
||||
.map(|candidate| candidate.item.name)
|
||||
.map(|candidate| candidate.item.ident)
|
||||
.filter(|&name| set.insert(name))
|
||||
.collect();
|
||||
|
||||
@ -1310,14 +1309,14 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
Ok(None)
|
||||
} else {
|
||||
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,
|
||||
&self.method_name.unwrap().as_str(),
|
||||
None)
|
||||
}.unwrap();
|
||||
Ok(applicable_close_candidates
|
||||
.into_iter()
|
||||
.find(|method| method.name == best_name))
|
||||
.find(|method| method.ident.name == best_name))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1457,7 +1456,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
let max_dist = max(name.as_str().len(), 3) / 3;
|
||||
self.tcx.associated_items(def_id)
|
||||
.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
|
||||
&& dist <= max_dist
|
||||
})
|
||||
|
@ -77,7 +77,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn report_method_error(&self,
|
||||
span: Span,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: ast::Name,
|
||||
item_name: ast::Ident,
|
||||
rcvr_expr: Option<&hir::Expr>,
|
||||
error: MethodError<'tcx>,
|
||||
args: Option<&'gcx [hir::Expr]>) {
|
||||
@ -340,8 +340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
match ty.sty {
|
||||
ty::TyAdt(def, substs) if !def.is_enum() => {
|
||||
let variant = &def.non_enum_variant();
|
||||
if let Some(index) =
|
||||
self.tcx.find_field_index(item_name.to_ident(), variant) {
|
||||
if let Some(index) = self.tcx.find_field_index(item_name, variant) {
|
||||
let field = &variant.fields[index];
|
||||
let snippet = tcx.sess.codemap().span_to_snippet(expr.span);
|
||||
let expr_string = match snippet {
|
||||
@ -393,7 +392,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
report_function!(expr.span, expr_string);
|
||||
} else if let hir::ExprPath(hir::QPath::Resolved(_, ref path)) = expr.node {
|
||||
if let Some(segment) = path.segments.last() {
|
||||
report_function!(expr.span, segment.name);
|
||||
report_function!(expr.span, segment.ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -445,7 +444,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@ -565,7 +564,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
err: &mut DiagnosticBuilder,
|
||||
span: Span,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: ast::Name,
|
||||
item_name: ast::Ident,
|
||||
rcvr_expr: Option<&hir::Expr>,
|
||||
valid_out_of_scope_traits: Vec<DefId>) {
|
||||
if self.suggest_valid_traits(err, valid_out_of_scope_traits) {
|
||||
|
@ -960,14 +960,14 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {
|
||||
|
||||
// Add pattern bindings.
|
||||
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
|
||||
if let PatKind::Binding(_, _, ref path1, _) = p.node {
|
||||
if let PatKind::Binding(_, _, ident, _) = p.node {
|
||||
let var_ty = self.assign(p.span, p.id, None);
|
||||
|
||||
self.fcx.require_type_is_sized(var_ty, p.span,
|
||||
traits::VariableType(p.id));
|
||||
|
||||
debug!("Pattern binding {} is assigned to {} with type {:?}",
|
||||
path1.node,
|
||||
ident,
|
||||
self.fcx.ty_to_string(
|
||||
self.fcx.locals.borrow().get(&p.id).unwrap().clone()),
|
||||
var_ty);
|
||||
@ -1050,7 +1050,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
||||
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
|
||||
// for simple cases like `fn foo(x: Trait)`,
|
||||
// where we would error once on the parameter as a whole, and once on the binding `x`.
|
||||
if arg.pat.simple_name().is_none() {
|
||||
if arg.pat.simple_ident().is_none() {
|
||||
fcx.require_type_is_sized(arg_ty, decl.output.span(), traits::MiscObligation);
|
||||
}
|
||||
|
||||
@ -1333,15 +1333,15 @@ fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx.sess, impl_item.span, E0520,
|
||||
"`{}` specializes an item from a parent `impl`, but \
|
||||
that item is not marked `default`",
|
||||
impl_item.name);
|
||||
impl_item.ident);
|
||||
err.span_label(impl_item.span, format!("cannot specialize default item `{}`",
|
||||
impl_item.name));
|
||||
impl_item.ident));
|
||||
|
||||
match tcx.span_of_impl(parent_impl) {
|
||||
Ok(span) => {
|
||||
err.span_label(span, "parent `impl` is here");
|
||||
err.note(&format!("to specialize, `{}` in the parent `impl` must be marked `default`",
|
||||
impl_item.name));
|
||||
impl_item.ident));
|
||||
}
|
||||
Err(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
|
||||
};
|
||||
|
||||
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));
|
||||
|
||||
if let Some(parent) = parent {
|
||||
@ -1400,11 +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_trait_item = tcx.associated_items(impl_trait_ref.def_id)
|
||||
.find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) &&
|
||||
tcx.hygienic_eq(ty_impl_item.name, ac.name, impl_trait_ref.def_id))
|
||||
tcx.hygienic_eq(ty_impl_item.ident, ac.ident, impl_trait_ref.def_id))
|
||||
.or_else(|| {
|
||||
// Not compatible, but needed for the error message
|
||||
tcx.associated_items(impl_trait_ref.def_id)
|
||||
.find(|ac| tcx.hygienic_eq(ty_impl_item.name, ac.name, impl_trait_ref.def_id))
|
||||
.find(|ac| tcx.hygienic_eq(ty_impl_item.ident, ac.ident, impl_trait_ref.def_id))
|
||||
});
|
||||
|
||||
// Check that impl definition matches trait definition
|
||||
@ -1422,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,
|
||||
"item `{}` is an associated const, \
|
||||
which doesn't match its trait `{}`",
|
||||
ty_impl_item.name,
|
||||
ty_impl_item.ident,
|
||||
impl_trait_ref);
|
||||
err.span_label(impl_item.span, "does not match trait");
|
||||
// We can only get the spans from local trait definition
|
||||
@ -1446,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,
|
||||
"item `{}` is an associated method, \
|
||||
which doesn't match its trait `{}`",
|
||||
ty_impl_item.name,
|
||||
ty_impl_item.ident,
|
||||
impl_trait_ref);
|
||||
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) {
|
||||
@ -1464,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,
|
||||
"item `{}` is an associated type, \
|
||||
which doesn't match its trait `{}`",
|
||||
ty_impl_item.name,
|
||||
ty_impl_item.ident,
|
||||
impl_trait_ref);
|
||||
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) {
|
||||
@ -1485,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();
|
||||
for trait_item in tcx.associated_items(impl_trait_ref.def_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()
|
||||
.map(|node_item| !node_item.node.is_from_trait())
|
||||
.unwrap_or(false);
|
||||
@ -1494,7 +1494,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
if !trait_item.defaultness.has_value() {
|
||||
missing_items.push(trait_item);
|
||||
} else if associated_type_overridden {
|
||||
invalidated_items.push(trait_item.name);
|
||||
invalidated_items.push(trait_item.ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1503,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,
|
||||
"not all trait items implemented, missing: `{}`",
|
||||
missing_items.iter()
|
||||
.map(|trait_item| trait_item.name.to_string())
|
||||
.map(|trait_item| trait_item.ident.to_string())
|
||||
.collect::<Vec<_>>().join("`, `"));
|
||||
err.span_label(impl_span, format!("missing `{}` in implementation",
|
||||
missing_items.iter()
|
||||
.map(|trait_item| trait_item.name.to_string())
|
||||
.map(|trait_item| trait_item.ident.to_string())
|
||||
.collect::<Vec<_>>().join("`, `")));
|
||||
for trait_item in missing_items {
|
||||
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 {
|
||||
err.note_trait_signature(trait_item.name.to_string(),
|
||||
err.note_trait_signature(trait_item.ident.to_string(),
|
||||
trait_item.signature(&tcx));
|
||||
}
|
||||
}
|
||||
@ -1525,7 +1525,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
span_err!(tcx.sess, invalidator.span, E0399,
|
||||
"the following trait items need to be reimplemented \
|
||||
as `{}` was overridden: `{}`",
|
||||
invalidator.name,
|
||||
invalidator.ident,
|
||||
invalidated_items.iter()
|
||||
.map(|name| name.to_string())
|
||||
.collect::<Vec<_>>().join("`, `"))
|
||||
@ -2468,7 +2468,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
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) {
|
||||
(PlaceOp::Deref, false) =>
|
||||
(self.tcx.lang_items().deref_trait(), "deref"),
|
||||
@ -2479,7 +2479,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
(PlaceOp::Index, true) =>
|
||||
(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,
|
||||
@ -3004,10 +3004,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
Ok(method)
|
||||
}
|
||||
Err(error) => {
|
||||
if segment.name != keywords::Invalid.name() {
|
||||
if segment.ident.name != keywords::Invalid.name() {
|
||||
self.report_method_error(span,
|
||||
rcvr_t,
|
||||
segment.name,
|
||||
segment.ident,
|
||||
Some(rcvr),
|
||||
error,
|
||||
Some(args));
|
||||
@ -3836,7 +3836,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
// ... except when we try to 'break rust;'.
|
||||
// ICE this expression in particular (see #43162).
|
||||
if let hir::ExprPath(hir::QPath::Resolved(_, ref path)) = e.node {
|
||||
if path.segments.len() == 1 && path.segments[0].name == "rust" {
|
||||
if path.segments.len() == 1 && path.segments[0].ident.name == "rust" {
|
||||
fatally_break_rust(self.tcx.sess);
|
||||
}
|
||||
}
|
||||
@ -4252,7 +4252,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
// errors with default match binding modes. See #44614.
|
||||
return (*cached_def, Some(ty), slice::from_ref(&**item_segment))
|
||||
}
|
||||
let item_name = item_segment.name;
|
||||
let item_name = item_segment.ident;
|
||||
let def = match self.resolve_ufcs(span, item_name, ty, node_id) {
|
||||
Ok(def) => def,
|
||||
Err(error) => {
|
||||
@ -4260,7 +4260,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
method::MethodError::PrivateMatch(def, _) => def,
|
||||
_ => Def::Err,
|
||||
};
|
||||
if item_name != keywords::Invalid.name() {
|
||||
if item_name.name != keywords::Invalid.name() {
|
||||
self.report_method_error(span, ty, item_name, None, error, None);
|
||||
}
|
||||
def
|
||||
|
@ -18,7 +18,7 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoB
|
||||
use rustc::infer::type_variable::TypeVariableOrigin;
|
||||
use errors;
|
||||
use syntax_pos::Span;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::ast::Ident;
|
||||
use rustc::hir;
|
||||
|
||||
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
@ -564,7 +564,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
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))
|
||||
});
|
||||
|
||||
|
@ -632,7 +632,7 @@ fn check_variances_for_type_defn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
}
|
||||
|
||||
let param = &hir_generics.params[index];
|
||||
report_bivariance(tcx, param.span, param.name.name());
|
||||
report_bivariance(tcx, param.span, param.name.ident().name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
|
||||
|
||||
let name_and_namespace = |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);
|
||||
|
@ -898,7 +898,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics);
|
||||
params.extend(early_lifetimes.enumerate().map(|(i, param)| {
|
||||
ty::GenericParamDef {
|
||||
name: param.name.name().as_interned_str(),
|
||||
name: param.name.ident().as_interned_str(),
|
||||
index: own_start + i as u32,
|
||||
def_id: tcx.hir.local_def_id(param.id),
|
||||
pure_wrt_drop: param.pure_wrt_drop,
|
||||
@ -914,7 +914,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
let mut i = 0;
|
||||
params.extend(ast_generics.params.iter().filter_map(|param| match param.kind {
|
||||
GenericParamKind::Type { ref default, synthetic, .. } => {
|
||||
if param.name.name() == keywords::SelfType.name() {
|
||||
if param.name.ident().name == keywords::SelfType.name() {
|
||||
span_bug!(param.span, "`Self` should not be the name of a regular parameter");
|
||||
}
|
||||
|
||||
@ -931,7 +931,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
||||
let ty_param = ty::GenericParamDef {
|
||||
index: type_start + i as u32,
|
||||
name: param.name.name().as_interned_str(),
|
||||
name: param.name.ident().as_interned_str(),
|
||||
def_id: tcx.hir.local_def_id(param.id),
|
||||
pure_wrt_drop: param.pure_wrt_drop,
|
||||
kind: ty::GenericParamDefKind::Type {
|
||||
@ -1437,7 +1437,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
def_id: tcx.hir.local_def_id(param.id),
|
||||
index,
|
||||
name: param.name.name().as_interned_str(),
|
||||
name: param.name.ident().as_interned_str(),
|
||||
}));
|
||||
index += 1;
|
||||
|
||||
@ -1461,7 +1461,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
for param in &ast_generics.params {
|
||||
match param.kind {
|
||||
GenericParamKind::Type { .. } => {
|
||||
let name = param.name.name().as_interned_str();
|
||||
let name = param.name.ident().as_interned_str();
|
||||
let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
|
||||
index += 1;
|
||||
|
||||
|
@ -184,14 +184,14 @@ fn enforce_impl_items_are_distinct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
hir::ImplItemKind::Type(_) => &mut seen_type_items,
|
||||
_ => &mut seen_value_items,
|
||||
};
|
||||
match seen_items.entry(impl_item.name) {
|
||||
match seen_items.entry(impl_item.ident.modern()) {
|
||||
Occupied(entry) => {
|
||||
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201,
|
||||
"duplicate definitions with name `{}`:",
|
||||
impl_item.name);
|
||||
impl_item.ident);
|
||||
err.span_label(*entry.get(),
|
||||
format!("previous definition of `{}` here",
|
||||
impl_item.name));
|
||||
impl_item.ident));
|
||||
err.span_label(impl_item.span, "duplicate definition");
|
||||
err.emit();
|
||||
}
|
||||
|
@ -200,10 +200,10 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
let mut segments = path.segments.into_vec();
|
||||
let last = segments.pop().unwrap();
|
||||
|
||||
let real_name = name.map(|name| Symbol::intern(&name));
|
||||
let real_name = name.map(|name| Ident::from_str(&name));
|
||||
|
||||
segments.push(hir::PathSegment::new(
|
||||
real_name.unwrap_or(last.name),
|
||||
real_name.unwrap_or(last.ident),
|
||||
self.generics_to_path_params(generics.clone()),
|
||||
false,
|
||||
));
|
||||
@ -251,9 +251,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime => {
|
||||
let name = if param.name == "" {
|
||||
hir::ParamName::Plain(keywords::StaticLifetime.name())
|
||||
hir::ParamName::Plain(keywords::StaticLifetime.ident())
|
||||
} else {
|
||||
hir::ParamName::Plain(param.name.as_symbol())
|
||||
hir::ParamName::Plain(ast::Ident::from_interned_str(param.name))
|
||||
};
|
||||
|
||||
args.push(hir::GenericArg::Lifetime(hir::Lifetime {
|
||||
@ -285,7 +285,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
span: DUMMY_SP,
|
||||
def: Def::TyParam(param.def_id),
|
||||
segments: HirVec::from_vec(vec![
|
||||
hir::PathSegment::from_name(param.name.as_symbol())
|
||||
hir::PathSegment::from_ident(Ident::from_interned_str(param.name))
|
||||
]),
|
||||
}),
|
||||
)),
|
||||
|
@ -391,7 +391,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
|
||||
let provided = trait_.def_id().map(|did| {
|
||||
tcx.provided_trait_methods(did)
|
||||
.into_iter()
|
||||
.map(|meth| meth.name.to_string())
|
||||
.map(|meth| meth.ident.to_string())
|
||||
.collect()
|
||||
}).unwrap_or(FxHashSet());
|
||||
|
||||
|
@ -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) => {
|
||||
let item = cx.tcx.inherent_impls(did).iter()
|
||||
.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 {
|
||||
let out = match item.kind {
|
||||
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) => {
|
||||
let item = cx.tcx.associated_item_def_ids(did).iter()
|
||||
.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 {
|
||||
let kind = match item.kind {
|
||||
ty::AssociatedKind::Const if is_val => "associatedconstant",
|
||||
@ -1664,7 +1664,7 @@ impl Clean<Lifetime> for hir::Lifetime {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Lifetime(self.name.name().to_string())
|
||||
Lifetime(self.name.ident().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1677,14 +1677,14 @@ impl Clean<Lifetime> for hir::GenericParam {
|
||||
hir::GenericBound::Outlives(lt) => lt,
|
||||
_ => panic!(),
|
||||
});
|
||||
let name = bounds.next().unwrap().name.name();
|
||||
let mut s = format!("{}: {}", self.name.name(), name);
|
||||
let name = bounds.next().unwrap().name.ident();
|
||||
let mut s = format!("{}: {}", self.name.ident(), name);
|
||||
for bound in bounds {
|
||||
s.push_str(&format!(" + {}", bound.name.name()));
|
||||
s.push_str(&format!(" + {}", bound.name.ident()));
|
||||
}
|
||||
Lifetime(s)
|
||||
} else {
|
||||
Lifetime(self.name.name().to_string())
|
||||
Lifetime(self.name.ident().to_string())
|
||||
}
|
||||
}
|
||||
_ => panic!(),
|
||||
@ -1823,7 +1823,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
|
||||
GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"),
|
||||
};
|
||||
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),
|
||||
trait_: box trait_
|
||||
}
|
||||
@ -1896,19 +1896,19 @@ impl Clean<GenericParamDef> for hir::GenericParam {
|
||||
hir::GenericBound::Outlives(lt) => lt,
|
||||
_ => panic!(),
|
||||
});
|
||||
let name = bounds.next().unwrap().name.name();
|
||||
let mut s = format!("{}: {}", self.name.name(), name);
|
||||
let name = bounds.next().unwrap().name.ident();
|
||||
let mut s = format!("{}: {}", self.name.ident(), name);
|
||||
for bound in bounds {
|
||||
s.push_str(&format!(" + {}", bound.name.name()));
|
||||
s.push_str(&format!(" + {}", bound.name.ident()));
|
||||
}
|
||||
s
|
||||
} else {
|
||||
self.name.name().to_string()
|
||||
self.name.ident().to_string()
|
||||
};
|
||||
(name, GenericParamDefKind::Lifetime)
|
||||
}
|
||||
hir::GenericParamKind::Type { ref default, synthetic, .. } => {
|
||||
(self.name.name().clean(cx), GenericParamDefKind::Type {
|
||||
(self.name.ident().name.clean(cx), GenericParamDefKind::Type {
|
||||
did: cx.tcx.hir.local_def_id(self.id),
|
||||
bounds: self.bounds.clean(cx),
|
||||
default: default.clean(cx),
|
||||
@ -2150,11 +2150,11 @@ pub struct Arguments {
|
||||
pub values: Vec<Argument>,
|
||||
}
|
||||
|
||||
impl<'a> Clean<Arguments> for (&'a [hir::Ty], &'a [Spanned<ast::Name>]) {
|
||||
impl<'a> Clean<Arguments> for (&'a [hir::Ty], &'a [ast::Ident]) {
|
||||
fn clean(&self, cx: &DocContext) -> Arguments {
|
||||
Arguments {
|
||||
values: self.0.iter().enumerate().map(|(i, ty)| {
|
||||
let mut name = self.1.get(i).map(|n| n.node.to_string())
|
||||
let mut name = self.1.get(i).map(|ident| ident.to_string())
|
||||
.unwrap_or(String::new());
|
||||
if name.is_empty() {
|
||||
name = "_".to_string();
|
||||
@ -2360,7 +2360,7 @@ impl Clean<Item> for hir::TraitItem {
|
||||
}
|
||||
};
|
||||
Item {
|
||||
name: Some(self.name.clean(cx)),
|
||||
name: Some(self.ident.name.clean(cx)),
|
||||
attrs: self.attrs.clean(cx),
|
||||
source: self.span.clean(cx),
|
||||
def_id: cx.tcx.hir.local_def_id(self.id),
|
||||
@ -2388,7 +2388,7 @@ impl Clean<Item> for hir::ImplItem {
|
||||
}, true),
|
||||
};
|
||||
Item {
|
||||
name: Some(self.name.clean(cx)),
|
||||
name: Some(self.ident.name.clean(cx)),
|
||||
source: self.span.clean(cx),
|
||||
attrs: self.attrs.clean(cx),
|
||||
def_id: cx.tcx.hir.local_def_id(self.id),
|
||||
@ -2474,7 +2474,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
|
||||
}
|
||||
}
|
||||
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 {
|
||||
// When loading a cross-crate associated type, the bounds for this type
|
||||
@ -2537,7 +2537,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
|
||||
};
|
||||
|
||||
Item {
|
||||
name: Some(self.name.clean(cx)),
|
||||
name: Some(self.ident.name.clean(cx)),
|
||||
visibility,
|
||||
stability: get_stability(cx, self.def_id),
|
||||
deprecation: get_deprecation(cx, self.def_id),
|
||||
@ -2949,7 +2949,7 @@ impl Clean<Type> for hir::Ty {
|
||||
segments: segments.into(),
|
||||
};
|
||||
Type::QPath {
|
||||
name: p.segments.last().unwrap().name.clean(cx),
|
||||
name: p.segments.last().unwrap().ident.name.clean(cx),
|
||||
self_type: box qself.clean(cx),
|
||||
trait_: box resolve_type(cx, trait_path.clean(cx), self.id)
|
||||
}
|
||||
@ -2966,7 +2966,7 @@ impl Clean<Type> for hir::Ty {
|
||||
segments: vec![].into(),
|
||||
};
|
||||
Type::QPath {
|
||||
name: segment.name.clean(cx),
|
||||
name: segment.ident.name.clean(cx),
|
||||
self_type: box qself.clean(cx),
|
||||
trait_: box resolve_type(cx, trait_path.clean(cx), self.id)
|
||||
}
|
||||
@ -3099,7 +3099,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
let mut bindings = vec![];
|
||||
for pb in obj.projection_bounds() {
|
||||
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)
|
||||
});
|
||||
}
|
||||
@ -3156,7 +3156,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
if proj.projection_ty.trait_ref(cx.tcx) == *trait_ref.skip_binder() {
|
||||
Some(TypeBinding {
|
||||
name: cx.tcx.associated_item(proj.projection_ty.item_def_id)
|
||||
.name.clean(cx),
|
||||
.ident.name.clean(cx),
|
||||
ty: proj.ty.clean(cx),
|
||||
})
|
||||
} else {
|
||||
@ -3575,7 +3575,7 @@ pub struct PathSegment {
|
||||
impl Clean<PathSegment> for hir::PathSegment {
|
||||
fn clean(&self, cx: &DocContext) -> PathSegment {
|
||||
PathSegment {
|
||||
name: self.name.clean(cx),
|
||||
name: self.ident.name.clean(cx),
|
||||
args: self.with_generic_args(|generic_args| generic_args.clean(cx))
|
||||
}
|
||||
}
|
||||
@ -3628,7 +3628,7 @@ fn strip_path(path: &Path) -> Path {
|
||||
fn qpath_to_string(p: &hir::QPath) -> String {
|
||||
let segments = match *p {
|
||||
hir::QPath::Resolved(_, ref path) => &path.segments,
|
||||
hir::QPath::TypeRelative(_, ref segment) => return segment.name.to_string(),
|
||||
hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(),
|
||||
};
|
||||
|
||||
let mut s = String::new();
|
||||
@ -3636,8 +3636,8 @@ fn qpath_to_string(p: &hir::QPath) -> String {
|
||||
if i > 0 {
|
||||
s.push_str("::");
|
||||
}
|
||||
if seg.name != keywords::CrateRoot.name() {
|
||||
s.push_str(&*seg.name.as_str());
|
||||
if seg.ident.name != keywords::CrateRoot.name() {
|
||||
s.push_str(&*seg.ident.as_str());
|
||||
}
|
||||
}
|
||||
s
|
||||
@ -3823,7 +3823,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
|
||||
let provided = trait_.def_id().map(|did| {
|
||||
cx.tcx.provided_trait_methods(did)
|
||||
.into_iter()
|
||||
.map(|meth| meth.name.to_string())
|
||||
.map(|meth| meth.ident.to_string())
|
||||
.collect()
|
||||
}).unwrap_or(FxHashSet());
|
||||
|
||||
@ -4064,7 +4064,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
|
||||
|
||||
match p.node {
|
||||
PatKind::Wild => "_".to_string(),
|
||||
PatKind::Binding(_, _, ref p, _) => p.node.to_string(),
|
||||
PatKind::Binding(_, _, ident, _) => ident.to_string(),
|
||||
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
|
||||
PatKind::Struct(ref name, ref fields, etc) => {
|
||||
format!("{} {{ {}{} }}", qpath_to_string(name),
|
||||
@ -4293,7 +4293,7 @@ pub struct TypeBinding {
|
||||
impl Clean<TypeBinding> for hir::TypeBinding {
|
||||
fn clean(&self, cx: &DocContext) -> TypeBinding {
|
||||
TypeBinding {
|
||||
name: self.name.clean(cx),
|
||||
name: self.ident.name.clean(cx),
|
||||
ty: self.ty.clean(cx)
|
||||
}
|
||||
}
|
||||
@ -4427,7 +4427,7 @@ where F: Fn(DefId) -> Def {
|
||||
span: DUMMY_SP,
|
||||
def: def_ctor(def_id),
|
||||
segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment {
|
||||
name: ast::Name::intern(&s),
|
||||
ident: ast::Ident::from_str(&s),
|
||||
args: None,
|
||||
infer_types: false,
|
||||
}).collect())
|
||||
|
@ -718,13 +718,13 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
@ -7325,7 +7325,7 @@ impl<'a> Parser<'a> {
|
||||
match self.token {
|
||||
token::Ident(ident, false) if ident.name == keywords::Underscore.name() => {
|
||||
self.bump(); // `_`
|
||||
Ok(Some(Ident::new(ident.name.gensymed(), ident.span)))
|
||||
Ok(Some(ident.gensym()))
|
||||
}
|
||||
_ => self.parse_ident().map(Some),
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
use GLOBALS;
|
||||
use Span;
|
||||
use edition::Edition;
|
||||
use symbol::{Ident, Symbol};
|
||||
use symbol::Symbol;
|
||||
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
use std::collections::HashMap;
|
||||
@ -190,7 +190,6 @@ pub struct HygieneData {
|
||||
marks: Vec<MarkData>,
|
||||
syntax_contexts: Vec<SyntaxContextData>,
|
||||
markings: HashMap<(SyntaxContext, Mark), SyntaxContext>,
|
||||
gensym_to_ctxt: HashMap<Symbol, Span>,
|
||||
default_edition: Edition,
|
||||
}
|
||||
|
||||
@ -211,7 +210,6 @@ impl HygieneData {
|
||||
modern: SyntaxContext(0),
|
||||
}],
|
||||
markings: HashMap::new(),
|
||||
gensym_to_ctxt: HashMap::new(),
|
||||
default_edition: Edition::Edition2015,
|
||||
}
|
||||
}
|
||||
@ -559,22 +557,3 @@ impl Decodable for SyntaxContext {
|
||||
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),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,11 @@ impl Ident {
|
||||
Ident::new(Symbol::intern(self.as_str().trim_left_matches('\'')), self.span)
|
||||
}
|
||||
|
||||
/// "Normalize" ident for use in comparisons using "item hygiene".
|
||||
/// Identifiers with same string value become same if they came from the same "modern" macro
|
||||
/// (e.g. `macro` item, but not `macro_rules` item) and stay different if they came from
|
||||
/// different "modern" macros.
|
||||
/// Technically, this operation strips all non-opaque marks from ident's syntactic context.
|
||||
pub fn modern(self) -> Ident {
|
||||
Ident::new(self.name, self.span.modern())
|
||||
}
|
||||
@ -70,6 +75,10 @@ impl Ident {
|
||||
pub fn as_str(self) -> LocalInternedString {
|
||||
self.name.as_str()
|
||||
}
|
||||
|
||||
pub fn as_interned_str(self) -> InternedString {
|
||||
self.name.as_interned_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Ident {
|
||||
|
Loading…
Reference in New Issue
Block a user