Skip to content

Commit 7b81106

Browse files
committed
Use Idents instead of Names in ImportDirective's paths.
1 parent 6a6ef91 commit 7b81106

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

src/librustc_resolve/build_reduced_graph.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,22 @@ impl<'b> Resolver<'b> {
9595
// Extract and intern the module part of the path. For
9696
// globs and lists, the path is found directly in the AST;
9797
// for simple paths we have to munge the path a little.
98-
let module_path: Vec<Name> = match view_path.node {
98+
let module_path: Vec<_> = match view_path.node {
9999
ViewPathSimple(_, ref full_path) => {
100100
full_path.segments
101101
.split_last()
102102
.unwrap()
103103
.1
104104
.iter()
105-
.map(|seg| seg.identifier.name)
105+
.map(|seg| seg.identifier)
106106
.collect()
107107
}
108108

109109
ViewPathGlob(ref module_ident_path) |
110110
ViewPathList(ref module_ident_path, _) => {
111111
module_ident_path.segments
112112
.iter()
113-
.map(|seg| seg.identifier.name)
113+
.map(|seg| seg.identifier)
114114
.collect()
115115
}
116116
};
@@ -159,7 +159,7 @@ impl<'b> Resolver<'b> {
159159
(module_path.clone(), node.name.name, rename)
160160
} else {
161161
let name = match module_path.last() {
162-
Some(name) => *name,
162+
Some(ident) => ident.name,
163163
None => {
164164
resolve_error(
165165
self,

src/librustc_resolve/lib.rs

+29-36
Original file line numberDiff line numberDiff line change
@@ -1178,18 +1178,18 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
11781178
}
11791179

11801180
trait Named {
1181-
fn name(&self) -> Name;
1181+
fn ident(&self) -> Ident;
11821182
}
11831183

11841184
impl Named for ast::PathSegment {
1185-
fn name(&self) -> Name {
1186-
self.identifier.name
1185+
fn ident(&self) -> Ident {
1186+
self.identifier
11871187
}
11881188
}
11891189

11901190
impl Named for hir::PathSegment {
1191-
fn name(&self) -> Name {
1192-
self.name
1191+
fn ident(&self) -> Ident {
1192+
Ident::with_empty_ctxt(self.name)
11931193
}
11941194
}
11951195

@@ -1364,7 +1364,7 @@ impl<'a> Resolver<'a> {
13641364
/// Resolves the given module path from the given root `search_module`.
13651365
fn resolve_module_path_from_root(&mut self,
13661366
mut search_module: Module<'a>,
1367-
module_path: &[Name],
1367+
module_path: &[Ident],
13681368
index: usize,
13691369
span: Option<Span>)
13701370
-> ResolveResult<Module<'a>> {
@@ -1387,7 +1387,7 @@ impl<'a> Resolver<'a> {
13871387
// upward though scope chains; we simply resolve names directly in
13881388
// modules as we go.
13891389
while index < module_path_len {
1390-
let name = module_path[index];
1390+
let name = module_path[index].name;
13911391
match self.resolve_name_in_module(search_module, name, TypeNS, false, span) {
13921392
Failed(_) => {
13931393
let segment_name = name.as_str();
@@ -1441,7 +1441,7 @@ impl<'a> Resolver<'a> {
14411441
/// Attempts to resolve the module part of an import directive or path
14421442
/// rooted at the given module.
14431443
fn resolve_module_path(&mut self,
1444-
module_path: &[Name],
1444+
module_path: &[Ident],
14451445
use_lexical_scope: UseLexicalScopeFlag,
14461446
span: Option<Span>)
14471447
-> ResolveResult<Module<'a>> {
@@ -1479,7 +1479,7 @@ impl<'a> Resolver<'a> {
14791479
// This is not a crate-relative path. We resolve the
14801480
// first component of the path in the current lexical
14811481
// scope and then proceed to resolve below that.
1482-
let ident = Ident::with_empty_ctxt(module_path[0]);
1482+
let ident = module_path[0];
14831483
let lexical_binding =
14841484
self.resolve_ident_in_lexical_scope(ident, TypeNS, span);
14851485
if let Some(binding) = lexical_binding.and_then(LexicalScopeBinding::item) {
@@ -1577,11 +1577,11 @@ impl<'a> Resolver<'a> {
15771577
/// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
15781578
/// (b) some chain of `super::`.
15791579
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
1580-
fn resolve_module_prefix(&mut self, module_path: &[Name], span: Option<Span>)
1580+
fn resolve_module_prefix(&mut self, module_path: &[Ident], span: Option<Span>)
15811581
-> ResolveResult<ModulePrefixResult<'a>> {
15821582
// Start at the current module if we see `self` or `super`, or at the
15831583
// top of the crate otherwise.
1584-
let mut i = match &*module_path[0].as_str() {
1584+
let mut i = match &*module_path[0].name.as_str() {
15851585
"self" => 1,
15861586
"super" => 0,
15871587
_ => return Success(NoPrefixFound),
@@ -1591,7 +1591,7 @@ impl<'a> Resolver<'a> {
15911591
self.module_map[&self.current_module.normal_ancestor_id.unwrap()];
15921592

15931593
// Now loop through all the `super`s we find.
1594-
while i < module_path.len() && "super" == module_path[i].as_str() {
1594+
while i < module_path.len() && "super" == module_path[i].name.as_str() {
15951595
debug!("(resolving module prefix) resolving `super` at {}",
15961596
module_to_string(&containing_module));
15971597
if let Some(parent) = containing_module.parent {
@@ -2681,12 +2681,8 @@ impl<'a> Resolver<'a> {
26812681
namespace: Namespace)
26822682
-> Result<&'a NameBinding<'a>,
26832683
bool /* true if an error was reported */> {
2684-
let module_path = segments.split_last()
2685-
.unwrap()
2686-
.1
2687-
.iter()
2688-
.map(|ps| ps.identifier.name)
2689-
.collect::<Vec<_>>();
2684+
let module_path =
2685+
segments.split_last().unwrap().1.iter().map(|ps| ps.identifier).collect::<Vec<_>>();
26902686

26912687
let containing_module;
26922688
match self.resolve_module_path(&module_path, UseLexicalScope, Some(span)) {
@@ -2715,7 +2711,7 @@ impl<'a> Resolver<'a> {
27152711
bool /* true if an error was reported */>
27162712
where T: Named,
27172713
{
2718-
let module_path = segments.split_last().unwrap().1.iter().map(T::name).collect::<Vec<_>>();
2714+
let module_path = segments.split_last().unwrap().1.iter().map(T::ident).collect::<Vec<_>>();
27192715
let root_module = self.graph_root;
27202716

27212717
let containing_module;
@@ -2734,7 +2730,7 @@ impl<'a> Resolver<'a> {
27342730
}
27352731
}
27362732

2737-
let name = segments.last().unwrap().name();
2733+
let name = segments.last().unwrap().ident().name;
27382734
let result =
27392735
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
27402736
result.success().ok_or(false)
@@ -2976,9 +2972,8 @@ impl<'a> Resolver<'a> {
29762972
msg = format!("did you mean {}?", msg);
29772973
} else {
29782974
// we display a help message if this is a module
2979-
let name_path = path.segments.iter()
2980-
.map(|seg| seg.identifier.name)
2981-
.collect::<Vec<_>>();
2975+
let name_path: Vec<_> =
2976+
path.segments.iter().map(|seg| seg.identifier).collect();
29822977

29832978
match self.resolve_module_path(&name_path[..],
29842979
UseLexicalScope,
@@ -3317,7 +3312,7 @@ impl<'a> Resolver<'a> {
33173312
}
33183313
};
33193314

3320-
let segments: Vec<_> = path.segments.iter().map(|seg| seg.identifier.name).collect();
3315+
let segments: Vec<_> = path.segments.iter().map(|seg| seg.identifier).collect();
33213316
let mut path_resolution = err_path_resolution();
33223317
let vis = match self.resolve_module_path(&segments, DontUseLexicalScope, Some(path.span)) {
33233318
Success(module) => {
@@ -3469,26 +3464,24 @@ impl<'a> Resolver<'a> {
34693464
}
34703465
}
34713466

3472-
fn names_to_string(names: &[Name]) -> String {
3467+
fn names_to_string(names: &[Ident]) -> String {
34733468
let mut first = true;
34743469
let mut result = String::new();
3475-
for name in names {
3470+
for ident in names {
34763471
if first {
34773472
first = false
34783473
} else {
34793474
result.push_str("::")
34803475
}
3481-
result.push_str(&name.as_str());
3476+
result.push_str(&ident.name.as_str());
34823477
}
34833478
result
34843479
}
34853480

34863481
fn path_names_to_string(path: &Path, depth: usize) -> String {
3487-
let names: Vec<ast::Name> = path.segments[..path.segments.len() - depth]
3488-
.iter()
3489-
.map(|seg| seg.identifier.name)
3490-
.collect();
3491-
names_to_string(&names[..])
3482+
let names: Vec<_> =
3483+
path.segments[..path.segments.len() - depth].iter().map(|seg| seg.identifier).collect();
3484+
names_to_string(&names)
34923485
}
34933486

34943487
/// When an entity with a given name is not available in scope, we search for
@@ -3551,15 +3544,15 @@ fn show_candidates(session: &mut DiagnosticBuilder,
35513544
fn module_to_string(module: Module) -> String {
35523545
let mut names = Vec::new();
35533546

3554-
fn collect_mod(names: &mut Vec<ast::Name>, module: Module) {
3547+
fn collect_mod(names: &mut Vec<Ident>, module: Module) {
35553548
if let ModuleKind::Def(_, name) = module.kind {
35563549
if let Some(parent) = module.parent {
3557-
names.push(name);
3550+
names.push(Ident::with_empty_ctxt(name));
35583551
collect_mod(names, parent);
35593552
}
35603553
} else {
35613554
// danger, shouldn't be ident?
3562-
names.push(token::intern("<opaque>"));
3555+
names.push(token::str_to_ident("<opaque>"));
35633556
collect_mod(names, module.parent.unwrap());
35643557
}
35653558
}
@@ -3568,7 +3561,7 @@ fn module_to_string(module: Module) -> String {
35683561
if names.is_empty() {
35693562
return "???".to_string();
35703563
}
3571-
names_to_string(&names.into_iter().rev().collect::<Vec<ast::Name>>())
3564+
names_to_string(&names.into_iter().rev().collect::<Vec<_>>())
35723565
}
35733566

35743567
fn err_path_resolution() -> PathResolution {

src/librustc_resolve/resolve_imports.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::ty;
2424
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
2525
use rustc::hir::def::*;
2626

27-
use syntax::ast::{NodeId, Name};
27+
use syntax::ast::{Ident, NodeId, Name};
2828
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
2929
use syntax::util::lev_distance::find_best_match_for_name;
3030
use syntax_pos::Span;
@@ -69,7 +69,7 @@ impl<'a> ImportDirectiveSubclass<'a> {
6969
pub struct ImportDirective<'a> {
7070
pub id: NodeId,
7171
parent: Module<'a>,
72-
module_path: Vec<Name>,
72+
module_path: Vec<Ident>,
7373
imported_module: Cell<Option<Module<'a>>>, // the resolution of `module_path`
7474
subclass: ImportDirectiveSubclass<'a>,
7575
span: Span,
@@ -252,7 +252,7 @@ impl<'a> Resolver<'a> {
252252

253253
// Add an import directive to the current module.
254254
pub fn add_import_directive(&mut self,
255-
module_path: Vec<Name>,
255+
module_path: Vec<Ident>,
256256
subclass: ImportDirectiveSubclass<'a>,
257257
span: Span,
258258
id: NodeId,
@@ -816,7 +816,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
816816
}
817817
}
818818

819-
fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) -> String {
819+
fn import_path_to_string(names: &[Ident], subclass: &ImportDirectiveSubclass) -> String {
820820
if names.is_empty() {
821821
import_directive_subclass_to_string(subclass)
822822
} else {

0 commit comments

Comments
 (0)