Skip to content

Commit 7608bbd

Browse files
committed
Refactor resolve_module_path to take an Option<Span> instead of a Span.
1 parent 05afe15 commit 7608bbd

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/librustc_resolve/lib.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ impl<'a> Resolver<'a> {
12421242
mut search_module: Module<'a>,
12431243
module_path: &[Name],
12441244
index: usize,
1245-
span: Span)
1245+
span: Option<Span>)
12461246
-> ResolveResult<Module<'a>> {
12471247
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
12481248
-> Option<Module<'a>> {
@@ -1265,7 +1265,7 @@ impl<'a> Resolver<'a> {
12651265
// modules as we go.
12661266
while index < module_path_len {
12671267
let name = module_path[index];
1268-
match self.resolve_name_in_module(search_module, name, TypeNS, false, Some(span)) {
1268+
match self.resolve_name_in_module(search_module, name, TypeNS, false, span) {
12691269
Failed(None) => {
12701270
let segment_name = name.as_str();
12711271
let module_name = module_to_string(search_module);
@@ -1291,7 +1291,7 @@ impl<'a> Resolver<'a> {
12911291
format!("Could not find `{}` in `{}`", segment_name, module_name)
12921292
};
12931293

1294-
return Failed(Some((span, msg)));
1294+
return Failed(span.map(|span| (span, msg)));
12951295
}
12961296
Failed(err) => return Failed(err),
12971297
Indeterminate => {
@@ -1304,11 +1304,13 @@ impl<'a> Resolver<'a> {
13041304
// Check to see whether there are type bindings, and, if
13051305
// so, whether there is a module within.
13061306
if let Some(module_def) = binding.module() {
1307-
self.check_privacy(name, binding, span);
1307+
if let Some(span) = span {
1308+
self.check_privacy(name, binding, span);
1309+
}
13081310
search_module = module_def;
13091311
} else {
13101312
let msg = format!("Not a module `{}`", name);
1311-
return Failed(Some((span, msg)));
1313+
return Failed(span.map(|span| (span, msg)));
13121314
}
13131315
}
13141316
}
@@ -1324,7 +1326,7 @@ impl<'a> Resolver<'a> {
13241326
fn resolve_module_path(&mut self,
13251327
module_path: &[Name],
13261328
use_lexical_scope: UseLexicalScopeFlag,
1327-
span: Span)
1329+
span: Option<Span>)
13281330
-> ResolveResult<Module<'a>> {
13291331
if module_path.len() == 0 {
13301332
return Success(self.graph_root) // Use the crate root
@@ -1361,7 +1363,7 @@ impl<'a> Resolver<'a> {
13611363
// first component of the path in the current lexical
13621364
// scope and then proceed to resolve below that.
13631365
let ident = ast::Ident::with_empty_ctxt(module_path[0]);
1364-
match self.resolve_ident_in_lexical_scope(ident, TypeNS, Some(span))
1366+
match self.resolve_ident_in_lexical_scope(ident, TypeNS, span)
13651367
.and_then(LexicalScopeBinding::module) {
13661368
None => return Failed(None),
13671369
Some(containing_module) => {
@@ -1378,10 +1380,7 @@ impl<'a> Resolver<'a> {
13781380
}
13791381
}
13801382

1381-
self.resolve_module_path_from_root(search_module,
1382-
module_path,
1383-
start_index,
1384-
span)
1383+
self.resolve_module_path_from_root(search_module, module_path, start_index, span)
13851384
}
13861385

13871386
/// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.
@@ -1485,7 +1484,7 @@ impl<'a> Resolver<'a> {
14851484
/// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
14861485
/// (b) some chain of `super::`.
14871486
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
1488-
fn resolve_module_prefix(&mut self, module_path: &[Name], span: Span)
1487+
fn resolve_module_prefix(&mut self, module_path: &[Name], span: Option<Span>)
14891488
-> ResolveResult<ModulePrefixResult<'a>> {
14901489
// Start at the current module if we see `self` or `super`, or at the
14911490
// top of the crate otherwise.
@@ -1504,7 +1503,7 @@ impl<'a> Resolver<'a> {
15041503
match self.get_nearest_normal_module_parent(containing_module) {
15051504
None => {
15061505
let msg = "There are too many initial `super`s.".into();
1507-
return Failed(Some((span, msg)));
1506+
return Failed(span.map(|span| (span, msg)));
15081507
}
15091508
Some(new_module) => {
15101509
containing_module = new_module;
@@ -2592,7 +2591,7 @@ impl<'a> Resolver<'a> {
25922591
.collect::<Vec<_>>();
25932592

25942593
let containing_module;
2595-
match self.resolve_module_path(&module_path, UseLexicalScope, span) {
2594+
match self.resolve_module_path(&module_path, UseLexicalScope, Some(span)) {
25962595
Failed(err) => {
25972596
let (span, msg) = match err {
25982597
Some((span, msg)) => (span, msg),
@@ -2632,10 +2631,7 @@ impl<'a> Resolver<'a> {
26322631
let root_module = self.graph_root;
26332632

26342633
let containing_module;
2635-
match self.resolve_module_path_from_root(root_module,
2636-
&module_path,
2637-
0,
2638-
span) {
2634+
match self.resolve_module_path_from_root(root_module, &module_path, 0, Some(span)) {
26392635
Failed(err) => {
26402636
let (span, msg) = match err {
26412637
Some((span, msg)) => (span, msg),
@@ -2915,7 +2911,7 @@ impl<'a> Resolver<'a> {
29152911

29162912
match self.resolve_module_path(&name_path[..],
29172913
UseLexicalScope,
2918-
expr.span) {
2914+
Some(expr.span)) {
29192915
Success(e) => {
29202916
if let Some(def_type) = e.def {
29212917
def = def_type;
@@ -3253,7 +3249,7 @@ impl<'a> Resolver<'a> {
32533249

32543250
let segments: Vec<_> = path.segments.iter().map(|seg| seg.identifier.name).collect();
32553251
let mut path_resolution = err_path_resolution();
3256-
let vis = match self.resolve_module_path(&segments, DontUseLexicalScope, path.span) {
3252+
let vis = match self.resolve_module_path(&segments, DontUseLexicalScope, Some(path.span)) {
32573253
Success(module) => {
32583254
let def = module.def.unwrap();
32593255
path_resolution = PathResolution::new(def);

src/librustc_resolve/resolve_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
480480
Some(module) => module,
481481
_ => match self.resolve_module_path(&directive.module_path,
482482
DontUseLexicalScope,
483-
directive.span) {
483+
Some(directive.span)) {
484484
Success(module) => module,
485485
Indeterminate => return Indeterminate,
486486
Failed(err) => return Failed(err),

0 commit comments

Comments
 (0)