mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
parent
a92b1a7981
commit
571010bb52
@ -1854,7 +1854,7 @@ impl<'a> LoweringContext<'a> {
|
||||
|
||||
let parent_def = self.parent_def;
|
||||
let def = self.resolver.definitions().map(|defs| {
|
||||
let def_path_data = DefPathData::Binding(name);
|
||||
let def_path_data = DefPathData::Binding(name.as_str());
|
||||
let def_index = defs.create_def_with_parent(parent_def, pat.id, def_path_data);
|
||||
Def::Local(DefId::local(def_index), pat.id)
|
||||
}).unwrap_or(Def::Err);
|
||||
|
@ -135,11 +135,11 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
DefPathData::Impl,
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
|
||||
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
|
||||
DefPathData::TypeNs(i.ident.name),
|
||||
ItemKind::Mod(..) => DefPathData::Module(i.ident.name),
|
||||
DefPathData::TypeNs(i.ident.name.as_str()),
|
||||
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
|
||||
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
|
||||
DefPathData::ValueNs(i.ident.name),
|
||||
ItemKind::Mac(..) => DefPathData::MacroDef(i.ident.name),
|
||||
DefPathData::ValueNs(i.ident.name.as_str()),
|
||||
ItemKind::Mac(..) => DefPathData::MacroDef(i.ident.name.as_str()),
|
||||
ItemKind::Use(..) => DefPathData::Misc,
|
||||
};
|
||||
let def = self.create_def(i.id, def_data);
|
||||
@ -150,12 +150,12 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
for v in &enum_definition.variants {
|
||||
let variant_def_index =
|
||||
this.create_def(v.node.data.id(),
|
||||
DefPathData::EnumVariant(v.node.name.name));
|
||||
DefPathData::EnumVariant(v.node.name.name.as_str()));
|
||||
this.with_parent(variant_def_index, |this| {
|
||||
for (index, field) in v.node.data.fields().iter().enumerate() {
|
||||
let name = field.ident.map(|ident| ident.name)
|
||||
.unwrap_or_else(|| token::intern(&index.to_string()));
|
||||
this.create_def(field.id, DefPathData::Field(name));
|
||||
this.create_def(field.id, DefPathData::Field(name.as_str()));
|
||||
}
|
||||
|
||||
if let Some(ref expr) = v.node.disr_expr {
|
||||
@ -172,8 +172,8 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
}
|
||||
|
||||
for (index, field) in struct_def.fields().iter().enumerate() {
|
||||
let name = field.ident.map(|ident| ident.name)
|
||||
.unwrap_or(token::intern(&index.to_string()));
|
||||
let name = field.ident.map(|ident| ident.name.as_str())
|
||||
.unwrap_or(token::intern(&index.to_string()).as_str());
|
||||
this.create_def(field.id, DefPathData::Field(name));
|
||||
}
|
||||
}
|
||||
@ -184,7 +184,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
|
||||
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.ident.name));
|
||||
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.ident.name.as_str()));
|
||||
|
||||
self.with_parent(def, |this| {
|
||||
visit::walk_foreign_item(this, foreign_item);
|
||||
@ -193,7 +193,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
|
||||
fn visit_generics(&mut self, generics: &Generics) {
|
||||
for ty_param in generics.ty_params.iter() {
|
||||
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name));
|
||||
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str()));
|
||||
}
|
||||
|
||||
visit::walk_generics(self, generics);
|
||||
@ -202,9 +202,9 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
fn visit_trait_item(&mut self, ti: &TraitItem) {
|
||||
let def_data = match ti.node {
|
||||
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ti.ident.name),
|
||||
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name),
|
||||
TraitItemKind::Macro(..) => DefPathData::MacroDef(ti.ident.name),
|
||||
DefPathData::ValueNs(ti.ident.name.as_str()),
|
||||
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
|
||||
TraitItemKind::Macro(..) => DefPathData::MacroDef(ti.ident.name.as_str()),
|
||||
};
|
||||
|
||||
let def = self.create_def(ti.id, def_data);
|
||||
@ -220,9 +220,9 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
fn visit_impl_item(&mut self, ii: &ImplItem) {
|
||||
let def_data = match ii.node {
|
||||
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ii.ident.name),
|
||||
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name),
|
||||
ImplItemKind::Macro(..) => DefPathData::MacroDef(ii.ident.name),
|
||||
DefPathData::ValueNs(ii.ident.name.as_str()),
|
||||
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
|
||||
ImplItemKind::Macro(..) => DefPathData::MacroDef(ii.ident.name.as_str()),
|
||||
};
|
||||
|
||||
let def = self.create_def(ii.id, def_data);
|
||||
@ -239,7 +239,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
let parent_def = self.parent_def;
|
||||
|
||||
if let PatKind::Ident(_, id, _) = pat.node {
|
||||
let def = self.create_def(pat.id, DefPathData::Binding(id.node.name));
|
||||
let def = self.create_def(pat.id, DefPathData::Binding(id.node.name.as_str()));
|
||||
self.parent_def = Some(def);
|
||||
}
|
||||
|
||||
@ -271,11 +271,11 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
|
||||
}
|
||||
|
||||
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
|
||||
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name));
|
||||
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &MacroDef) {
|
||||
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name));
|
||||
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name.as_str()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,9 +301,9 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemTrait(..) |
|
||||
hir::ItemExternCrate(..) | hir::ItemMod(..) | hir::ItemForeignMod(..) |
|
||||
hir::ItemTy(..) =>
|
||||
DefPathData::TypeNs(i.name),
|
||||
DefPathData::TypeNs(i.name.as_str()),
|
||||
hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) =>
|
||||
DefPathData::ValueNs(i.name),
|
||||
DefPathData::ValueNs(i.name.as_str()),
|
||||
hir::ItemUse(..) => DefPathData::Misc,
|
||||
};
|
||||
let def = self.create_def(i.id, def_data);
|
||||
@ -314,12 +314,12 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
for v in &enum_definition.variants {
|
||||
let variant_def_index =
|
||||
this.create_def(v.node.data.id(),
|
||||
DefPathData::EnumVariant(v.node.name));
|
||||
DefPathData::EnumVariant(v.node.name.as_str()));
|
||||
|
||||
this.with_parent(variant_def_index, |this| {
|
||||
for field in v.node.data.fields() {
|
||||
this.create_def(field.id,
|
||||
DefPathData::Field(field.name));
|
||||
DefPathData::Field(field.name.as_str()));
|
||||
}
|
||||
if let Some(ref expr) = v.node.disr_expr {
|
||||
this.visit_hir_const_integer(expr);
|
||||
@ -335,7 +335,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
}
|
||||
|
||||
for field in struct_def.fields() {
|
||||
this.create_def(field.id, DefPathData::Field(field.name));
|
||||
this.create_def(field.id, DefPathData::Field(field.name.as_str()));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -345,7 +345,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &'ast hir::ForeignItem) {
|
||||
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.name));
|
||||
let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.name.as_str()));
|
||||
|
||||
self.with_parent(def, |this| {
|
||||
intravisit::walk_foreign_item(this, foreign_item);
|
||||
@ -354,7 +354,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
|
||||
fn visit_generics(&mut self, generics: &'ast hir::Generics) {
|
||||
for ty_param in generics.ty_params.iter() {
|
||||
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.name));
|
||||
self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.name.as_str()));
|
||||
}
|
||||
|
||||
intravisit::walk_generics(self, generics);
|
||||
@ -363,8 +363,8 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
|
||||
let def_data = match ti.node {
|
||||
hir::MethodTraitItem(..) | hir::ConstTraitItem(..) =>
|
||||
DefPathData::ValueNs(ti.name),
|
||||
hir::TypeTraitItem(..) => DefPathData::TypeNs(ti.name),
|
||||
DefPathData::ValueNs(ti.name.as_str()),
|
||||
hir::TypeTraitItem(..) => DefPathData::TypeNs(ti.name.as_str()),
|
||||
};
|
||||
|
||||
let def = self.create_def(ti.id, def_data);
|
||||
@ -380,8 +380,8 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
|
||||
let def_data = match ii.node {
|
||||
hir::ImplItemKind::Method(..) | hir::ImplItemKind::Const(..) =>
|
||||
DefPathData::ValueNs(ii.name),
|
||||
hir::ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name),
|
||||
DefPathData::ValueNs(ii.name.as_str()),
|
||||
hir::ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name.as_str()),
|
||||
};
|
||||
|
||||
let def = self.create_def(ii.id, def_data);
|
||||
@ -398,7 +398,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
let parent_def = self.parent_def;
|
||||
|
||||
if let hir::PatKind::Binding(_, name, _) = pat.node {
|
||||
let def = self.create_def(pat.id, DefPathData::Binding(name.node));
|
||||
let def = self.create_def(pat.id, DefPathData::Binding(name.node.as_str()));
|
||||
self.parent_def = Some(def);
|
||||
}
|
||||
|
||||
@ -430,10 +430,10 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
|
||||
}
|
||||
|
||||
fn visit_lifetime_def(&mut self, def: &'ast hir::LifetimeDef) {
|
||||
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name));
|
||||
self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str()));
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'ast hir::MacroDef) {
|
||||
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name));
|
||||
self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name.as_str()));
|
||||
}
|
||||
}
|
||||
|
@ -177,31 +177,31 @@ pub enum DefPathData {
|
||||
/// An impl
|
||||
Impl,
|
||||
/// Something in the type NS
|
||||
TypeNs(ast::Name),
|
||||
TypeNs(InternedString),
|
||||
/// Something in the value NS
|
||||
ValueNs(ast::Name),
|
||||
ValueNs(InternedString),
|
||||
/// A module declaration
|
||||
Module(ast::Name),
|
||||
Module(InternedString),
|
||||
/// A macro rule
|
||||
MacroDef(ast::Name),
|
||||
MacroDef(InternedString),
|
||||
/// A closure expression
|
||||
ClosureExpr,
|
||||
|
||||
// Subportions of items
|
||||
/// A type parameter (generic parameter)
|
||||
TypeParam(ast::Name),
|
||||
TypeParam(InternedString),
|
||||
/// A lifetime definition
|
||||
LifetimeDef(ast::Name),
|
||||
LifetimeDef(InternedString),
|
||||
/// A variant of a enum
|
||||
EnumVariant(ast::Name),
|
||||
EnumVariant(InternedString),
|
||||
/// A struct field
|
||||
Field(ast::Name),
|
||||
Field(InternedString),
|
||||
/// Implicit ctor for a tuple-like struct
|
||||
StructCtor,
|
||||
/// Initializer for a const
|
||||
Initializer,
|
||||
/// Pattern binding
|
||||
Binding(ast::Name),
|
||||
Binding(InternedString),
|
||||
}
|
||||
|
||||
impl Definitions {
|
||||
@ -315,16 +315,16 @@ impl DefPathData {
|
||||
pub fn as_interned_str(&self) -> InternedString {
|
||||
use self::DefPathData::*;
|
||||
match *self {
|
||||
TypeNs(name) |
|
||||
ValueNs(name) |
|
||||
Module(name) |
|
||||
MacroDef(name) |
|
||||
TypeParam(name) |
|
||||
LifetimeDef(name) |
|
||||
EnumVariant(name) |
|
||||
Binding(name) |
|
||||
Field(name) => {
|
||||
name.as_str()
|
||||
TypeNs(ref name) |
|
||||
ValueNs(ref name) |
|
||||
Module(ref name) |
|
||||
MacroDef(ref name) |
|
||||
TypeParam(ref name) |
|
||||
LifetimeDef(ref name) |
|
||||
EnumVariant(ref name) |
|
||||
Binding(ref name) |
|
||||
Field(ref name) => {
|
||||
name.clone()
|
||||
}
|
||||
|
||||
Impl => {
|
||||
|
@ -1690,7 +1690,7 @@ fn item_def_key(item_doc: rbml::Doc) -> hir_map::DefKey {
|
||||
let mut decoder = reader::Decoder::new(def_key_doc);
|
||||
let simple_key = def_key::DefKey::decode(&mut decoder).unwrap();
|
||||
let name = reader::maybe_get_doc(item_doc, tag_paths_data_name).map(|name| {
|
||||
token::intern(name.as_str_slice())
|
||||
token::intern(name.as_str_slice()).as_str()
|
||||
});
|
||||
def_key::recover_def_key(simple_key, name)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
use rustc::hir::def_id::DefIndex;
|
||||
use rustc::hir::map as hir_map;
|
||||
use syntax::ast::Name;
|
||||
use syntax::parse::token::InternedString;
|
||||
|
||||
#[derive(RustcEncodable, RustcDecodable)]
|
||||
pub struct DefKey {
|
||||
@ -75,7 +75,7 @@ fn simplify_def_path_data(data: hir_map::DefPathData) -> DefPathData {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recover_def_key(key: DefKey, name: Option<Name>) -> hir_map::DefKey {
|
||||
pub fn recover_def_key(key: DefKey, name: Option<InternedString>) -> hir_map::DefKey {
|
||||
let data = hir_map::DisambiguatedDefPathData {
|
||||
data: recover_def_path_data(key.disambiguated_data.data, name),
|
||||
disambiguator: key.disambiguated_data.disambiguator,
|
||||
@ -86,7 +86,7 @@ pub fn recover_def_key(key: DefKey, name: Option<Name>) -> hir_map::DefKey {
|
||||
}
|
||||
}
|
||||
|
||||
fn recover_def_path_data(data: DefPathData, name: Option<Name>) -> hir_map::DefPathData {
|
||||
fn recover_def_path_data(data: DefPathData, name: Option<InternedString>) -> hir_map::DefPathData {
|
||||
match data {
|
||||
DefPathData::CrateRoot => hir_map::DefPathData::CrateRoot,
|
||||
DefPathData::Misc => hir_map::DefPathData::Misc,
|
||||
|
Loading…
Reference in New Issue
Block a user