/// Contains data for specific types of import directives.
enum ImportDirectiveSubclass {
- SingleImport(Ident /* target */, Ident /* source */),
+ SingleImport(Name /* target */, Name /* source */),
GlobImport
}
/// One import directive.
struct ImportDirective {
- module_path: Vec<Ident>,
+ module_path: Vec<Name>,
subclass: ImportDirectiveSubclass,
span: Span,
id: NodeId,
}
impl ImportDirective {
- fn new(module_path: Vec<Ident> ,
+ fn new(module_path: Vec<Name> ,
subclass: ImportDirectiveSubclass,
span: Span,
id: NodeId,
#[deriving(Clone)]
enum ParentLink {
NoParentLink,
- ModuleParentLink(Weak<Module>, Ident),
+ ModuleParentLink(Weak<Module>, Name),
BlockParentLink(Weak<Module>, NodeId)
}
* a block, fails.
*/
fn add_child(&self,
- name: Ident,
+ name: Name,
reduced_graph_parent: ReducedGraphParent,
duplicate_checking_mode: DuplicateCheckingMode,
// For printing errors
let module_ = reduced_graph_parent.module();
self.check_for_conflicts_between_external_crates_and_items(&*module_,
- name.name,
+ name,
sp);
// Add or reuse the child.
- let child = module_.children.borrow().find_copy(&name.name);
+ let child = module_.children.borrow().find_copy(&name);
match child {
None => {
let child = Rc::new(NameBindings::new());
- module_.children.borrow_mut().insert(name.name, child.clone());
+ module_.children.borrow_mut().insert(name, child.clone());
child
}
Some(child) => {
self.resolve_error(sp,
format!("duplicate definition of {} `{}`",
namespace_error_to_string(duplicate_type),
- token::get_ident(name)).as_slice());
+ token::get_name(name)).as_slice());
{
let r = child.span_for_namespace(ns);
for sp in r.iter() {
self.session.span_note(*sp,
format!("first definition of {} `{}` here",
namespace_error_to_string(duplicate_type),
- token::get_ident(name)).as_slice());
+ token::get_name(name)).as_slice());
}
}
}
return false;
}
- fn get_parent_link(&mut self, parent: ReducedGraphParent, name: Ident)
+ fn get_parent_link(&mut self, parent: ReducedGraphParent, name: Name)
-> ParentLink {
match parent {
ModuleReducedGraphParent(module_) => {
parent: ReducedGraphParent)
-> ReducedGraphParent
{
- let ident = item.ident;
+ let name = item.ident.name;
let sp = item.span;
let is_public = item.vis == ast::Public;
match item.node {
ItemMod(..) => {
let name_bindings =
- self.add_child(ident, parent.clone(), ForbidDuplicateModules, sp);
+ self.add_child(name, parent.clone(), ForbidDuplicateModules, sp);
- let parent_link = self.get_parent_link(parent, ident);
+ let parent_link = self.get_parent_link(parent, name);
let def_id = DefId { krate: 0, node: item.id };
name_bindings.define_module(parent_link,
Some(def_id),
// These items live in the value namespace.
ItemStatic(_, m, _) => {
let name_bindings =
- self.add_child(ident, parent.clone(), ForbidDuplicateValues, sp);
+ self.add_child(name, parent.clone(), ForbidDuplicateValues, sp);
let mutbl = m == ast::MutMutable;
name_bindings.define_value
parent
}
ItemConst(_, _) => {
- self.add_child(ident, parent.clone(), ForbidDuplicateValues, sp)
+ self.add_child(name, parent.clone(), ForbidDuplicateValues, sp)
.define_value(DefConst(local_def(item.id)),
sp, is_public);
parent
}
ItemFn(_, fn_style, _, _, _) => {
let name_bindings =
- self.add_child(ident, parent.clone(), ForbidDuplicateValues, sp);
+ self.add_child(name, parent.clone(), ForbidDuplicateValues, sp);
let def = DefFn(local_def(item.id), fn_style, false);
name_bindings.define_value(def, sp, is_public);
// These items live in the type namespace.
ItemTy(..) => {
let name_bindings =
- self.add_child(ident,
+ self.add_child(name,
parent.clone(),
ForbidDuplicateTypesAndModules,
sp);
ItemEnum(ref enum_definition, _) => {
let name_bindings =
- self.add_child(ident,
+ self.add_child(name,
parent.clone(),
ForbidDuplicateTypesAndModules,
sp);
None => (ForbidDuplicateTypesAndModules, None)
};
- let name_bindings = self.add_child(ident, parent.clone(), forbid, sp);
+ let name_bindings = self.add_child(name, parent.clone(), forbid, sp);
// Define a name in the type namespace.
name_bindings.define_type(DefTy(local_def(item.id), false), sp, is_public);
// Create the module and add all methods.
match ty.node {
TyPath(ref path, _, _) if path.segments.len() == 1 => {
- let name = path.segments.last().unwrap().identifier;
+ let mod_name = path.segments.last().unwrap().identifier.name;
let parent_opt = parent.module().children.borrow()
- .find_copy(&name.name);
+ .find_copy(&mod_name);
let new_parent = match parent_opt {
// It already exists
Some(ref child) if child.get_module_if_available()
// Create the module
_ => {
let name_bindings =
- self.add_child(name,
+ self.add_child(mod_name,
parent.clone(),
ForbidDuplicateModules,
sp);
let parent_link =
- self.get_parent_link(parent.clone(), ident);
+ self.get_parent_link(parent.clone(), name);
let def_id = local_def(item.id);
let ns = TypeNS;
let is_public =
match *impl_item {
MethodImplItem(ref method) => {
// Add the method to the module.
- let ident = method.pe_ident();
+ let name = method.pe_ident().name;
let method_name_bindings =
- self.add_child(ident,
+ self.add_child(name,
new_parent.clone(),
ForbidDuplicateValues,
method.span);
}
TypeImplItem(ref typedef) => {
// Add the typedef to the module.
- let ident = typedef.ident;
+ let name = typedef.ident.name;
let typedef_name_bindings =
self.add_child(
- ident,
+ name,
new_parent.clone(),
ForbidDuplicateTypesAndModules,
typedef.span);
ItemTrait(_, _, _, ref methods) => {
let name_bindings =
- self.add_child(ident,
+ self.add_child(name,
parent.clone(),
ForbidDuplicateTypesAndModules,
sp);
// Add all the methods within to a new module.
- let parent_link = self.get_parent_link(parent.clone(), ident);
+ let parent_link = self.get_parent_link(parent.clone(), name);
name_bindings.define_module(parent_link,
Some(local_def(item.id)),
TraitModuleKind,
// Add the names of all the methods to the trait info.
for method in methods.iter() {
- let (ident, kind) = match *method {
+ let (name, kind) = match *method {
ast::RequiredMethod(_) |
ast::ProvidedMethod(_) => {
let ty_m =
ast_util::trait_item_to_ty_method(method);
- let ident = ty_m.ident;
+ let name = ty_m.ident.name;
// Add it as a name in the trait module.
let (def, static_flag) = match ty_m.explicit_self
};
let method_name_bindings =
- self.add_child(ident,
+ self.add_child(name,
module_parent.clone(),
ForbidDuplicateTypesAndValues,
ty_m.span);
ty_m.span,
true);
- (ident, static_flag)
+ (name, static_flag)
}
ast::TypeTraitItem(ref associated_type) => {
let def = DefAssociatedTy(local_def(
associated_type.id));
let name_bindings =
- self.add_child(associated_type.ident,
+ self.add_child(associated_type.ident.name,
module_parent.clone(),
ForbidDuplicateTypesAndValues,
associated_type.span);
associated_type.span,
true);
- (associated_type.ident, TypeTraitItemKind)
+ (associated_type.ident.name, TypeTraitItemKind)
}
};
- self.trait_item_map.insert((ident.name, def_id), kind);
+ self.trait_item_map.insert((name, def_id), kind);
}
name_bindings.define_type(DefTrait(def_id), sp, is_public);
item_id: DefId,
parent: ReducedGraphParent,
is_public: bool) {
- let ident = variant.node.name;
+ let name = variant.node.name.name;
let is_exported = match variant.node.kind {
TupleVariantKind(_) => false,
StructVariantKind(_) => {
}
};
- let child = self.add_child(ident, parent,
+ let child = self.add_child(name, parent,
ForbidDuplicateTypesAndValues,
variant.span);
child.define_value(DefVariant(item_id,
ViewPathSimple(_, ref full_path, _) => {
full_path.segments
.as_slice().init()
- .iter().map(|ident| ident.identifier)
+ .iter().map(|ident| ident.identifier.name)
.collect()
}
ViewPathGlob(ref module_ident_path, _) |
ViewPathList(ref module_ident_path, _, _) => {
module_ident_path.segments
- .iter().map(|ident| ident.identifier).collect()
+ .iter().map(|ident| ident.identifier.name).collect()
}
};
view_item.attrs
.iter()
.any(|attr| {
- attr.name() == token::get_ident(
- special_idents::prelude_import)
+ attr.name() == token::get_name(
+ special_idents::prelude_import.name)
});
match view_path.node {
ViewPathSimple(binding, ref full_path, id) => {
- let source_ident =
- full_path.segments.last().unwrap().identifier;
- if token::get_ident(source_ident).get() == "mod" {
+ let source_name =
+ full_path.segments.last().unwrap().identifier.name;
+ if token::get_name(source_name).get() == "mod" {
self.resolve_error(view_path.span,
"`mod` imports are only allowed within a { } list");
}
- let subclass = SingleImport(binding,
- source_ident);
+ let subclass = SingleImport(binding.name,
+ source_name);
self.build_import_directive(&*module_,
module_path,
subclass,
for source_item in source_items.iter() {
let (module_path, name) = match source_item.node {
PathListIdent { name, .. } =>
- (module_path.clone(), name),
+ (module_path.clone(), name.name),
PathListMod { .. } => {
let name = match module_path.last() {
- Some(ident) => ident.clone(),
+ Some(name) => *name,
None => {
self.resolve_error(source_item.span,
"`mod` import can only appear in an import list \
let def_id = DefId { krate: crate_id, node: 0 };
self.external_exports.insert(def_id);
let parent_link =
- ModuleParentLink(parent.module().downgrade(), name);
+ ModuleParentLink(parent.module().downgrade(), name.name);
let external_module = Rc::new(Module::new(parent_link,
Some(def_id),
NormalModuleKind,
foreign_item: &ForeignItem,
parent: ReducedGraphParent,
f: |&mut Resolver|) {
- let name = foreign_item.ident;
+ let name = foreign_item.ident.name;
let is_public = foreign_item.vis == ast::Public;
let name_bindings =
self.add_child(name, parent, ForbidDuplicateValues,
vis: Visibility,
child_name_bindings: &NameBindings,
final_ident: &str,
- ident: Ident,
+ name: Name,
new_parent: ReducedGraphParent) {
debug!("(building reduced graph for \
external crate) building external def, priv {}",
debug!("(building reduced graph for \
external crate) building module \
{}", final_ident);
- let parent_link = self.get_parent_link(new_parent.clone(), ident);
+ let parent_link = self.get_parent_link(new_parent.clone(), name);
child_name_bindings.define_module(parent_link,
Some(def_id),
debug!("(building reduced graph for external crate) ... \
adding trait item '{}'",
- token::get_ident(trait_item_name));
+ token::get_name(trait_item_name));
- self.trait_item_map.insert((trait_item_name.name, def_id), trait_item_kind);
+ self.trait_item_map.insert((trait_item_name, def_id), trait_item_kind);
if is_exported {
self.external_exports
child_name_bindings.define_type(def, DUMMY_SP, is_public);
// Define a module if necessary.
- let parent_link = self.get_parent_link(new_parent, ident);
+ let parent_link = self.get_parent_link(new_parent, name);
child_name_bindings.set_module_kind(parent_link,
Some(def_id),
TraitModuleKind,
fn build_reduced_graph_for_external_crate_def(&mut self,
root: Rc<Module>,
def_like: DefLike,
- ident: Ident,
+ name: Name,
visibility: Visibility) {
match def_like {
DlDef(def) => {
csearch::each_child_of_item(&self.session.cstore,
def_id,
|def_like,
- child_ident,
+ child_name,
vis| {
self.build_reduced_graph_for_external_crate_def(
root.clone(),
def_like,
- child_ident,
+ child_name,
vis)
});
}
_ => {
let child_name_bindings =
- self.add_child(ident,
+ self.add_child(name,
ModuleReducedGraphParent(root.clone()),
OverwriteDuplicates,
DUMMY_SP);
self.handle_external_def(def,
visibility,
&*child_name_bindings,
- token::get_ident(ident).get(),
- ident,
+ token::get_name(name).get(),
+ name,
ModuleReducedGraphParent(root));
}
}
// We only process static methods of impls here.
match csearch::get_type_name_if_impl(&self.session.cstore, def) {
None => {}
- Some(final_ident) => {
+ Some(final_name) => {
let static_methods_opt =
csearch::get_static_methods_if_impl(&self.session.cstore, def);
match static_methods_opt {
debug!("(building reduced graph for \
external crate) processing \
static methods for type name {}",
- token::get_ident(final_ident));
+ token::get_name(final_name));
let child_name_bindings =
self.add_child(
- final_ident,
+ final_name,
ModuleReducedGraphParent(root.clone()),
OverwriteDuplicates,
DUMMY_SP);
Some(_) | None => {
let parent_link =
self.get_parent_link(ModuleReducedGraphParent(root),
- final_ident);
+ final_name);
child_name_bindings.define_module(
parent_link,
Some(def),
ModuleReducedGraphParent(type_module);
for static_method_info in
static_methods.iter() {
- let ident = static_method_info.ident;
+ let name = static_method_info.name;
debug!("(building reduced graph for \
external crate) creating \
static method '{}'",
- token::get_ident(ident));
+ token::get_name(name));
let method_name_bindings =
- self.add_child(ident,
+ self.add_child(name,
new_parent.clone(),
OverwriteDuplicates,
DUMMY_SP);
csearch::each_child_of_item(&self.session.cstore,
def_id,
- |def_like, child_ident, visibility| {
+ |def_like, child_name, visibility| {
debug!("(populating external module) ... found ident: {}",
- token::get_ident(child_ident));
+ token::get_name(child_name));
self.build_reduced_graph_for_external_crate_def(module.clone(),
def_like,
- child_ident,
+ child_name,
visibility)
});
module.populated.set(true)
.get()
.unwrap()
.krate,
- |def_like, ident, visibility| {
+ |def_like, name, visibility| {
self.build_reduced_graph_for_external_crate_def(root.clone(),
def_like,
- ident,
+ name,
visibility)
});
}
/// Creates and adds an import directive to the given module.
fn build_import_directive(&mut self,
module_: &Module,
- module_path: Vec<Ident> ,
+ module_path: Vec<Name>,
subclass: ImportDirectiveSubclass,
span: Span,
id: NodeId,
SingleImport(target, _) => {
debug!("(building import directive) building import \
directive: {}::{}",
- self.idents_to_string(module_.imports.borrow().last().unwrap()
+ self.names_to_string(module_.imports.borrow().last().unwrap()
.module_path.as_slice()),
- token::get_ident(target));
+ token::get_name(target));
let mut import_resolutions = module_.import_resolutions
.borrow_mut();
- match import_resolutions.find_mut(&target.name) {
+ match import_resolutions.find_mut(&target) {
Some(resolution) => {
debug!("(building import directive) bumping \
reference");
debug!("(building import directive) creating new");
let mut resolution = ImportResolution::new(id, is_public);
resolution.outstanding_references = 1;
- import_resolutions.insert(target.name, resolution);
+ import_resolutions.insert(target, resolution);
}
GlobImport => {
// Set the glob flag. This tells us that we don't know the
}
}
- fn idents_to_string(&self, idents: &[Ident]) -> String {
+ fn names_to_string(&self, names: &[Name]) -> String {
let mut first = true;
let mut result = String::new();
- for ident in idents.iter() {
+ for name in names.iter() {
if first {
first = false
} else {
result.push_str("::")
}
- result.push_str(token::get_ident(*ident).get());
+ result.push_str(token::get_name(*name).get());
};
result
}
- fn path_idents_to_string(&self, path: &Path) -> String {
- let identifiers: Vec<ast::Ident> = path.segments
- .iter()
- .map(|seg| seg.identifier)
- .collect();
- self.idents_to_string(identifiers.as_slice())
+ fn path_names_to_string(&self, path: &Path) -> String {
+ let names: Vec<ast::Name> = path.segments
+ .iter()
+ .map(|seg| seg.identifier.name)
+ .collect();
+ self.names_to_string(names.as_slice())
}
fn import_directive_subclass_to_string(&mut self,
-> String {
match subclass {
SingleImport(_, source) => {
- token::get_ident(source).get().to_string()
+ token::get_name(source).get().to_string()
}
GlobImport => "*".to_string()
}
}
fn import_path_to_string(&mut self,
- idents: &[Ident],
+ names: &[Name],
subclass: ImportDirectiveSubclass)
-> String {
- if idents.is_empty() {
+ if names.is_empty() {
self.import_directive_subclass_to_string(subclass)
} else {
(format!("{}::{}",
- self.idents_to_string(idents),
+ self.names_to_string(names),
self.import_directive_subclass_to_string(
subclass))).to_string()
}
debug!("(resolving import for module) resolving import `{}::...` in \
`{}`",
- self.idents_to_string(module_path.as_slice()),
+ self.names_to_string(module_path.as_slice()),
self.module_to_string(&*module_));
// First, resolve the module path for the directive, if necessary.
fn resolve_single_import(&mut self,
module_: &Module,
containing_module: Rc<Module>,
- target: Ident,
- source: Ident,
+ target: Name,
+ source: Name,
directive: &ImportDirective,
lp: LastPrivate)
-> ResolveResult<()> {
debug!("(resolving single import) resolving `{}` = `{}::{}` from \
`{}` id {}, last private {}",
- token::get_ident(target),
+ token::get_name(target),
self.module_to_string(&*containing_module),
- token::get_ident(source),
+ token::get_name(source),
self.module_to_string(module_),
directive.id,
lp);
// Search for direct children of the containing module.
self.populate_module_if_necessary(&containing_module);
- match containing_module.children.borrow().find(&source.name) {
+ match containing_module.children.borrow().find(&source) {
None => {
// Continue.
}
}
// Now search the exported imports within the containing module.
- match containing_module.import_resolutions.borrow().find(&source.name) {
+ match containing_module.import_resolutions.borrow().find(&source) {
None => {
debug!("(resolving single import) no import");
// The containing module definitely doesn't have an
BoundResult(..) => {}
_ => {
match containing_module.external_module_children.borrow_mut()
- .find_copy(&source.name) {
+ .find_copy(&source) {
None => {} // Continue.
Some(module) => {
debug!("(resolving single import) found external \
// We've successfully resolved the import. Write the results in.
let mut import_resolutions = module_.import_resolutions.borrow_mut();
- let import_resolution = import_resolutions.get_mut(&target.name);
+ let import_resolution = import_resolutions.get_mut(&target);
match value_result {
BoundResult(ref target_module, ref name_bindings) => {
self.check_for_conflicting_import(
&import_resolution.value_target,
directive.span,
- target.name,
+ target,
ValueNS);
import_resolution.value_target =
self.check_for_conflicting_import(
&import_resolution.type_target,
directive.span,
- target.name,
+ target,
TypeNS);
import_resolution.type_target =
module_,
import_resolution,
directive.span,
- target.name);
+ target);
if value_result.is_unbound() && type_result.is_unbound() {
let msg = format!("There is no `{}` in `{}`",
- token::get_ident(source),
+ token::get_name(source),
self.module_to_string(&*containing_module));
return Failed(Some((directive.span, msg)));
}
/// Resolves the given module path from the given root `module_`.
fn resolve_module_path_from_root(&mut self,
module_: Rc<Module>,
- module_path: &[Ident],
+ module_path: &[Name],
index: uint,
span: Span,
name_search_type: NameSearchType,
while index < module_path_len {
let name = module_path[index];
match self.resolve_name_in_module(search_module.clone(),
- name.name,
+ name,
TypeNS,
name_search_type,
false) {
Failed(None) => {
- let segment_name = token::get_ident(name);
+ let segment_name = token::get_name(name);
let module_name = self.module_to_string(&*search_module);
let mut span = span;
let msg = if "???" == module_name.as_slice() {
span.hi = span.lo + Pos::from_uint(segment_name.get().len());
- match search_parent_externals(name.name,
+ match search_parent_externals(name,
&self.current_module) {
Some(module) => {
- let path_str = self.idents_to_string(module_path);
+ let path_str = self.names_to_string(module_path);
let target_mod_str = self.module_to_string(&*module);
let current_mod_str =
self.module_to_string(&*self.current_module);
Indeterminate => {
debug!("(resolving module path for import) module \
resolution is indeterminate: {}",
- token::get_ident(name));
+ token::get_name(name));
return Indeterminate;
}
Success((target, used_proxy)) => {
match type_def.module_def {
None => {
let msg = format!("Not a module `{}`",
- token::get_ident(name));
+ token::get_name(name));
return Failed(Some((span, msg)));
}
None => {
// There are no type bindings at all.
let msg = format!("Not a module `{}`",
- token::get_ident(name));
+ token::get_name(name));
return Failed(Some((span, msg)));
}
}
/// module found to the destination when resolving this path.
fn resolve_module_path(&mut self,
module_: Rc<Module>,
- module_path: &[Ident],
+ module_path: &[Name],
use_lexical_scope: UseLexicalScopeFlag,
span: Span,
name_search_type: NameSearchType)
debug!("(resolving module path for import) processing `{}` rooted at \
`{}`",
- self.idents_to_string(module_path),
+ self.names_to_string(module_path),
self.module_to_string(&*module_));
// Resolve the module prefix, if any.
let last_private;
match module_prefix_result {
Failed(None) => {
- let mpath = self.idents_to_string(module_path);
+ let mpath = self.names_to_string(module_path);
let mpath = mpath.as_slice();
match mpath.rfind(':') {
Some(idx) => {
/// import resolution.
fn resolve_item_in_lexical_scope(&mut self,
module_: Rc<Module>,
- name: Ident,
+ name: Name,
namespace: Namespace)
-> ResolveResult<(Target, bool)> {
debug!("(resolving item in lexical scope) resolving `{}` in \
namespace {} in `{}`",
- token::get_ident(name),
+ token::get_name(name),
namespace,
self.module_to_string(&*module_));
// its immediate children.
self.populate_module_if_necessary(&module_);
- match module_.children.borrow().find(&name.name) {
+ match module_.children.borrow().find(&name) {
Some(name_bindings)
if name_bindings.defined_in_namespace(namespace) => {
debug!("top name bindings succeeded");
// all its imports in the usual way; this is because chains of
// adjacent import statements are processed as though they mutated the
// current scope.
- match module_.import_resolutions.borrow().find(&name.name) {
+ match module_.import_resolutions.borrow().find(&name) {
None => {
// Not found; continue.
}
// Search for external modules.
if namespace == TypeNS {
- match module_.external_module_children.borrow().find_copy(&name.name) {
+ match module_.external_module_children.borrow().find_copy(&name) {
None => {}
Some(module) => {
let name_bindings =
// Resolve the name in the parent module.
match self.resolve_name_in_module(search_module.clone(),
- name.name,
+ name,
namespace,
PathSearch,
true) {
/// Resolves a module name in the current lexical scope.
fn resolve_module_in_lexical_scope(&mut self,
module_: Rc<Module>,
- name: Ident)
+ name: Name)
-> ResolveResult<Rc<Module>> {
// If this module is an anonymous module, resolve the item in the
// lexical scope. Otherwise, resolve the item from the crate root.
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
fn resolve_module_prefix(&mut self,
module_: Rc<Module>,
- module_path: &[Ident])
+ module_path: &[Name])
-> ResolveResult<ModulePrefixResult> {
// Start at the current module if we see `self` or `super`, or at the
// top of the crate otherwise.
let mut containing_module;
let mut i;
- let first_module_path_string = token::get_ident(module_path[0]);
+ let first_module_path_string = token::get_name(module_path[0]);
if "self" == first_module_path_string.get() {
containing_module =
self.get_nearest_normal_module_parent_or_self(module_);
// Now loop through all the `super`s we find.
while i < module_path.len() {
- let string = token::get_ident(module_path[i]);
+ let string = token::get_name(module_path[i]);
if "super" != string.get() {
break
}
// generate a fake "implementation scope" containing all the
// implementations thus found, for compatibility with old resolve pass.
- fn with_scope(&mut self, name: Option<Ident>, f: |&mut Resolver|) {
+ fn with_scope(&mut self, name: Option<Name>, f: |&mut Resolver|) {
let orig_module = self.current_module.clone();
// Move down in the graph.
Some(name) => {
self.populate_module_if_necessary(&orig_module);
- match orig_module.children.borrow().find(&name.name) {
+ match orig_module.children.borrow().find(&name) {
None => {
debug!("!!! (with scope) didn't find `{}` in `{}`",
- token::get_ident(name),
+ token::get_name(name),
self.module_to_string(&*orig_module));
}
Some(name_bindings) => {
None => {
debug!("!!! (with scope) didn't find module \
for `{}` in `{}`",
- token::get_ident(name),
+ token::get_name(name),
self.module_to_string(&*orig_module));
}
Some(module_) => {
}
fn resolve_item(&mut self, item: &Item) {
+ let name = item.ident.name;
+
debug!("(resolving item) resolving {}",
- token::get_ident(item.ident));
+ token::get_name(name));
match item.node {
}
ItemMod(ref module_) => {
- self.with_scope(Some(item.ident), |this| {
- this.resolve_module(module_, item.span, item.ident,
+ self.with_scope(Some(name), |this| {
+ this.resolve_module(module_, item.span, name,
item.id);
});
}
ItemForeignMod(ref foreign_module) => {
- self.with_scope(Some(item.ident), |this| {
+ self.with_scope(Some(name), |this| {
for foreign_item in foreign_module.items.iter() {
match foreign_item.node {
ForeignItemFn(_, ref generics) => {
let mut function_type_rib = Rib::new(rib_kind);
let mut seen_bindings = HashSet::new();
for (index, type_parameter) in generics.ty_params.iter().enumerate() {
- let ident = type_parameter.ident;
+ let name = type_parameter.ident.name;
debug!("with_type_parameter_rib: {} {}", node_id,
type_parameter.id);
- if seen_bindings.contains(&ident) {
+ if seen_bindings.contains(&name) {
self.resolve_error(type_parameter.span,
format!("the name `{}` is already \
used for a type \
parameter in this type \
parameter list",
- token::get_ident(
- ident)).as_slice())
+ token::get_name(
+ name)).as_slice())
}
- seen_bindings.insert(ident);
+ seen_bindings.insert(name);
let def_like = DlDef(DefTyParam(space,
local_def(type_parameter.id),
self.record_def(type_parameter.id,
(DefTyParamBinder(node_id), LastMod(AllPublic)));
// plain insert (no renaming)
- function_type_rib.bindings.insert(ident.name, def_like);
+ function_type_rib.bindings.insert(name, def_like);
}
self.type_ribs.push(function_type_rib);
}
TypeNS,
true) {
None => {
- let path_str = self.path_idents_to_string(
+ let path_str = self.path_names_to_string(
&unboxed_function.path);
self.resolve_error(unboxed_function.path.span,
format!("unresolved trait `{}`",
_ => {
let msg =
format!("`{}` is not a trait",
- self.path_idents_to_string(
+ self.path_names_to_string(
&unboxed_function.path));
self.resolve_error(unboxed_function.path.span,
msg.as_slice());
reference_type: TraitReferenceType) {
match self.resolve_path(id, &trait_reference.path, TypeNS, true) {
None => {
- let path_str = self.path_idents_to_string(&trait_reference.path);
+ let path_str = self.path_names_to_string(&trait_reference.path);
let usage_str = match reference_type {
TraitBoundingTypeParameter => "bound type parameter with",
TraitImplementation => "implement",
(def, _) => {
self.resolve_error(trait_reference.path.span,
format!("`{}` is not a trait",
- self.path_idents_to_string(
+ self.path_names_to_string(
&trait_reference.path)));
// If it's a typedef, give a note
MethodImplItem(ref method) => {
// If this is a trait impl, ensure the method
// exists in trait
- this.check_trait_item(method.pe_ident(),
+ this.check_trait_item(method.pe_ident().name,
method.span);
// We also need a new scope for the method-
TypeImplItem(ref typedef) => {
// If this is a trait impl, ensure the method
// exists in trait
- this.check_trait_item(typedef.ident,
+ this.check_trait_item(typedef.ident.name,
typedef.span);
this.resolve_type(&*typedef.typ);
}
}
- fn check_trait_item(&self, ident: Ident, span: Span) {
+ fn check_trait_item(&self, name: Name, span: Span) {
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
for &(did, ref trait_ref) in self.current_trait_ref.iter() {
- let method_name = ident.name;
-
- if self.trait_item_map.find(&(method_name, did)).is_none() {
- let path_str = self.path_idents_to_string(&trait_ref.path);
+ if self.trait_item_map.find(&(name, did)).is_none() {
+ let path_str = self.path_names_to_string(&trait_ref.path);
self.resolve_error(span,
format!("method `{}` is not a member of trait `{}`",
- token::get_name(method_name),
+ token::get_name(name),
path_str).as_slice());
}
}
}
fn resolve_module(&mut self, module: &Mod, _span: Span,
- _name: Ident, id: NodeId) {
+ _name: Name, id: NodeId) {
// Write the implementations in scope into the module metadata.
debug!("(resolving module) resolving module ID {}", id);
visit::walk_mod(self, module);
// Write the result into the def map.
debug!("(resolving type) writing resolution for `{}` \
(id {})",
- self.path_idents_to_string(path),
+ self.path_names_to_string(path),
path_id);
self.record_def(path_id, def);
}
None => {
let msg = format!("use of undeclared type name `{}`",
- self.path_idents_to_string(path));
+ self.path_names_to_string(path));
self.resolve_error(ty.span, msg.as_slice());
}
}
self.resolve_type(&*qpath.for_type);
let current_module = self.current_module.clone();
- let module_path_idents: Vec<_> =
+ let module_path: Vec<_> =
qpath.trait_name
.segments
.iter()
- .map(|ps| ps.identifier)
+ .map(|ps| ps.identifier.name)
.collect();
match self.resolve_module_path(
current_module,
- module_path_idents.as_slice(),
+ module_path.as_slice(),
UseLexicalScope,
qpath.trait_name.span,
PathSearch) {
mode: PatternBindingMode,
// Maps idents to the node ID for the (outermost)
// pattern that binds them
- bindings_list: &mut HashMap<Name,NodeId>) {
+ bindings_list: &mut HashMap<Name, NodeId>) {
let pat_id = pattern.id;
walk_pat(pattern, |pattern| {
match pattern.node {
let ident = path1.node;
let renamed = mtwt::resolve(ident);
- match self.resolve_bare_identifier_pattern(ident, pattern.span) {
+ match self.resolve_bare_identifier_pattern(ident.name, pattern.span) {
FoundStructOrEnumVariant(ref def, lp)
if mode == RefutableMode => {
debug!("(resolving pattern) resolving `{}` to \
debug!("(resolving pattern) didn't find struct \
def: {}", result);
let msg = format!("`{}` does not name a structure",
- self.path_idents_to_string(path));
+ self.path_names_to_string(path));
self.resolve_error(path.span, msg.as_slice());
}
}
});
}
- fn resolve_bare_identifier_pattern(&mut self, name: Ident, span: Span)
+ fn resolve_bare_identifier_pattern(&mut self, name: Name, span: Span)
-> BareIdentifierPatternResolution {
let module = self.current_module.clone();
match self.resolve_item_in_lexical_scope(module,
Success((target, _)) => {
debug!("(resolve bare identifier pattern) succeeded in \
finding {} at {}",
- token::get_ident(name),
+ token::get_name(name),
target.bindings.value_def.borrow());
match *target.bindings.value_def.borrow() {
None => {
}
debug!("(resolve bare identifier pattern) failed to find {}",
- token::get_ident(name));
+ token::get_name(name));
return BareIdentifierPatternUnresolved;
}
}
}
}
- return self.resolve_item_by_identifier_in_lexical_scope(identifier,
- namespace);
+ return self.resolve_item_by_name_in_lexical_scope(identifier.name, namespace);
}
// FIXME #4952: Merge me with resolve_name_in_module?
path: &Path,
namespace: Namespace)
-> Option<(Def, LastPrivate)> {
- let module_path_idents = path.segments.init().iter()
- .map(|ps| ps.identifier)
- .collect::<Vec<_>>();
+ let module_path = path.segments.init().iter()
+ .map(|ps| ps.identifier.name)
+ .collect::<Vec<_>>();
let containing_module;
let last_private;
let module = self.current_module.clone();
match self.resolve_module_path(module,
- module_path_idents.as_slice(),
+ module_path.as_slice(),
UseLexicalScope,
path.span,
PathSearch) {
Some((span, msg)) => (span, msg),
None => {
let msg = format!("Use of undeclared module `{}`",
- self.idents_to_string(
- module_path_idents.as_slice()));
+ self.names_to_string(
+ module_path.as_slice()));
(path.span, msg)
}
};
}
}
- let ident = path.segments.last().unwrap().identifier;
+ let name = path.segments.last().unwrap().identifier.name;
let def = match self.resolve_definition_of_name_in_module(containing_module.clone(),
- ident.name,
+ name,
namespace) {
NoNameDefinition => {
// We failed to resolve the name. Report an error.
path: &Path,
namespace: Namespace)
-> Option<(Def, LastPrivate)> {
- let module_path_idents = path.segments.init().iter()
- .map(|ps| ps.identifier)
- .collect::<Vec<_>>();
+ let module_path = path.segments.init().iter()
+ .map(|ps| ps.identifier.name)
+ .collect::<Vec<_>>();
let root_module = self.graph_root.get_module();
let containing_module;
let last_private;
match self.resolve_module_path_from_root(root_module,
- module_path_idents.as_slice(),
+ module_path.as_slice(),
0,
path.span,
PathSearch,
Some((span, msg)) => (span, msg),
None => {
let msg = format!("Use of undeclared module `::{}`",
- self.idents_to_string(
- module_path_idents.as_slice()));
+ self.names_to_string(module_path.as_slice()));
(path.span, msg)
}
};
}
}
- fn resolve_item_by_identifier_in_lexical_scope(&mut self,
- ident: Ident,
- namespace: Namespace)
- -> Option<(Def, LastPrivate)> {
+ fn resolve_item_by_name_in_lexical_scope(&mut self,
+ name: Name,
+ namespace: Namespace)
+ -> Option<(Def, LastPrivate)> {
// Check the items.
let module = self.current_module.clone();
match self.resolve_item_in_lexical_scope(module,
- ident,
+ name,
namespace) {
Success((target, _)) => {
match (*target.bindings).def_for_namespace(namespace) {
// found a module instead. Modules don't have defs.
debug!("(resolving item path by identifier in lexical \
scope) failed to resolve {} after success...",
- token::get_ident(ident));
+ token::get_name(name));
return None;
}
Some(def) => {
debug!("(resolving item path in lexical scope) \
resolved `{}` to item",
- token::get_ident(ident));
+ token::get_name(name));
// This lookup is "all public" because it only searched
// for one identifier in the current module (couldn't
// have passed through reexports or anything like that.
}
debug!("(resolving item path by identifier in lexical scope) \
- failed to resolve {}", token::get_ident(ident));
+ failed to resolve {}", token::get_name(name));
return None;
}
}
}
}
- fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident])
+ fn get_module(this: &mut Resolver, span: Span, name_path: &[ast::Name])
-> Option<Rc<Module>> {
let root = this.current_module.clone();
- let last_name = ident_path.last().unwrap().name;
+ let last_name = name_path.last().unwrap();
- if ident_path.len() == 1 {
- match this.primitive_type_table.primitive_types.find(&last_name) {
+ if name_path.len() == 1 {
+ match this.primitive_type_table.primitive_types.find(last_name) {
Some(_) => None,
None => {
- match this.current_module.children.borrow().find(&last_name) {
+ match this.current_module.children.borrow().find(last_name) {
Some(child) => child.get_module_if_available(),
None => None
}
}
} else {
match this.resolve_module_path(root,
- ident_path.as_slice(),
+ name_path.as_slice(),
UseLexicalScope,
span,
PathSearch) {
}
}
- let ident_path = path.segments.iter().map(|seg| seg.identifier).collect::<Vec<_>>();
+ let name_path = path.segments.iter().map(|seg| seg.identifier.name).collect::<Vec<_>>();
// Look for a method in the current self type's impl module.
- match get_module(self, path.span, ident_path.as_slice()) {
+ match get_module(self, path.span, name_path.as_slice()) {
Some(module) => match module.children.borrow().find(&name) {
Some(binding) => {
- let p_str = self.path_idents_to_string(&path);
+ let p_str = self.path_names_to_string(&path);
match binding.def_for_namespace(ValueNS) {
Some(DefStaticMethod(_, provenance, _)) => {
match provenance {
// Look for a method in the current trait.
match self.current_trait_ref {
Some((did, ref trait_ref)) => {
- let path_str = self.path_idents_to_string(&trait_ref.path);
+ let path_str = self.path_names_to_string(&trait_ref.path);
match self.trait_item_map.find(&(name, did)) {
Some(&StaticMethodTraitItemKind) => {
Some(def) => {
// Write the result into the def map.
debug!("(resolving expr) resolved `{}`",
- self.path_idents_to_string(path));
+ self.path_names_to_string(path));
+
self.record_def(expr.id, def);
}
None => {
- let wrong_name = self.path_idents_to_string(path);
+ let wrong_name = self.path_names_to_string(path);
// Be helpful if the name refers to a struct
// (The pattern matching def_tys where the id is in self.structs
// matches on regular structs while excluding tuple- and enum-like
debug!("(resolving expression) didn't find struct \
def: {}", result);
let msg = format!("`{}` does not name a structure",
- self.path_idents_to_string(path));
+ self.path_names_to_string(path));
self.resolve_error(path.span, msg.as_slice());
}
}
/// A somewhat inefficient routine to obtain the name of a module.
fn module_to_string(&self, module: &Module) -> String {
- let mut idents = Vec::new();
+ let mut names = Vec::new();
- fn collect_mod(idents: &mut Vec<ast::Ident>, module: &Module) {
+ fn collect_mod(names: &mut Vec<ast::Name>, module: &Module) {
match module.parent_link {
NoParentLink => {}
ModuleParentLink(ref module, name) => {
- idents.push(name);
- collect_mod(idents, &*module.upgrade().unwrap());
+ names.push(name);
+ collect_mod(names, &*module.upgrade().unwrap());
}
BlockParentLink(ref module, _) => {
// danger, shouldn't be ident?
- idents.push(special_idents::opaque);
- collect_mod(idents, &*module.upgrade().unwrap());
+ names.push(special_idents::opaque.name);
+ collect_mod(names, &*module.upgrade().unwrap());
}
}
}
- collect_mod(&mut idents, module);
+ collect_mod(&mut names, module);
- if idents.len() == 0 {
+ if names.len() == 0 {
return "???".to_string();
}
- self.idents_to_string(idents.into_iter().rev()
- .collect::<Vec<ast::Ident>>()
- .as_slice())
+ self.names_to_string(names.into_iter().rev()
+ .collect::<Vec<ast::Name>>()
+ .as_slice())
}
#[allow(dead_code)] // useful for debugging