Skip to content

Commit 05afe15

Browse files
committed
Refactor record_used: bool -> record_used: Option<Span>.
1 parent 75c3fd8 commit 05afe15

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/librustc_resolve/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ impl<'a> Resolver<'a> {
12461246
-> ResolveResult<Module<'a>> {
12471247
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
12481248
-> Option<Module<'a>> {
1249-
match this.resolve_name_in_module(module, needle, TypeNS, false, false) {
1249+
match this.resolve_name_in_module(module, needle, TypeNS, false, None) {
12501250
Success(binding) if binding.is_extern_crate() => Some(module),
12511251
_ => match module.parent_link {
12521252
ModuleParentLink(ref parent, _) => {
@@ -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, true) {
1268+
match self.resolve_name_in_module(search_module, name, TypeNS, false, Some(span)) {
12691269
Failed(None) => {
12701270
let segment_name = name.as_str();
12711271
let module_name = module_to_string(search_module);
@@ -1361,7 +1361,7 @@ impl<'a> Resolver<'a> {
13611361
// first component of the path in the current lexical
13621362
// scope and then proceed to resolve below that.
13631363
let ident = ast::Ident::with_empty_ctxt(module_path[0]);
1364-
match self.resolve_ident_in_lexical_scope(ident, TypeNS, true)
1364+
match self.resolve_ident_in_lexical_scope(ident, TypeNS, Some(span))
13651365
.and_then(LexicalScopeBinding::module) {
13661366
None => return Failed(None),
13671367
Some(containing_module) => {
@@ -1404,7 +1404,7 @@ impl<'a> Resolver<'a> {
14041404
fn resolve_ident_in_lexical_scope(&mut self,
14051405
mut ident: ast::Ident,
14061406
ns: Namespace,
1407-
record_used: bool)
1407+
record_used: Option<Span>)
14081408
-> Option<LexicalScopeBinding<'a>> {
14091409
if ns == TypeNS {
14101410
ident = ast::Ident::with_empty_ctxt(ident.name);
@@ -1432,7 +1432,7 @@ impl<'a> Resolver<'a> {
14321432
if module.def.is_some() {
14331433
return match self.prelude {
14341434
Some(prelude) if !module.no_implicit_prelude.get() => {
1435-
self.resolve_name_in_module(prelude, name, ns, false, false).success()
1435+
self.resolve_name_in_module(prelude, name, ns, false, None).success()
14361436
.map(LexicalScopeBinding::Item)
14371437
}
14381438
_ => None,
@@ -2287,7 +2287,7 @@ impl<'a> Resolver<'a> {
22872287
PatKind::Ident(bmode, ref ident, ref opt_pat) => {
22882288
// First try to resolve the identifier as some existing
22892289
// entity, then fall back to a fresh binding.
2290-
let binding = self.resolve_ident_in_lexical_scope(ident.node, ValueNS, false)
2290+
let binding = self.resolve_ident_in_lexical_scope(ident.node, ValueNS, None)
22912291
.and_then(LexicalScopeBinding::item);
22922292
let resolution = binding.and_then(NameBinding::def).and_then(|def| {
22932293
let always_binding = !pat_src.is_refutable() || opt_pat.is_some() ||
@@ -2454,11 +2454,11 @@ impl<'a> Resolver<'a> {
24542454
//
24552455
// Such behavior is required for backward compatibility.
24562456
// The same fallback is used when `a` resolves to nothing.
2457-
let def = resolve_identifier_with_fallback(self, true).ok_or(false);
2457+
let def = resolve_identifier_with_fallback(self, Some(span)).ok_or(false);
24582458
return def.and_then(|def| self.adjust_local_def(def, span).ok_or(true)).map(mk_res);
24592459
}
24602460

2461-
let unqualified_def = resolve_identifier_with_fallback(self, false);
2461+
let unqualified_def = resolve_identifier_with_fallback(self, None);
24622462
let qualified_binding = self.resolve_module_relative_path(span, segments, namespace);
24632463
match (qualified_binding, unqualified_def) {
24642464
(Ok(binding), Some(ref ud)) if binding.def().unwrap() == ud.def => {
@@ -2478,7 +2478,7 @@ impl<'a> Resolver<'a> {
24782478
fn resolve_identifier(&mut self,
24792479
identifier: ast::Ident,
24802480
namespace: Namespace,
2481-
record_used: bool)
2481+
record_used: Option<Span>)
24822482
-> Option<LocalDef> {
24832483
if identifier.name == keywords::Invalid.name() {
24842484
return None;
@@ -2613,7 +2613,8 @@ impl<'a> Resolver<'a> {
26132613
}
26142614

26152615
let name = segments.last().unwrap().identifier.name;
2616-
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
2616+
let result =
2617+
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
26172618
result.success().map(|binding| {
26182619
self.check_privacy(name, binding, span);
26192620
binding
@@ -2657,7 +2658,8 @@ impl<'a> Resolver<'a> {
26572658
}
26582659

26592660
let name = segments.last().unwrap().name();
2660-
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
2661+
let result =
2662+
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
26612663
result.success().map(|binding| {
26622664
self.check_privacy(name, binding, span);
26632665
binding

src/librustc_resolve/resolve_imports.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a> Resolver<'a> {
149149
name: Name,
150150
ns: Namespace,
151151
allow_private_imports: bool,
152-
record_used: bool)
152+
record_used: Option<Span>)
153153
-> ResolveResult<&'a NameBinding<'a>> {
154154
self.populate_module_if_necessary(module);
155155

@@ -165,7 +165,7 @@ impl<'a> Resolver<'a> {
165165
if !allow_private_imports && binding.is_import() && !binding.is_pseudo_public() {
166166
return Failed(None);
167167
}
168-
if record_used {
168+
if record_used.is_some() {
169169
self.record_use(name, ns, binding);
170170
}
171171
Success(binding)
@@ -176,7 +176,7 @@ impl<'a> Resolver<'a> {
176176
for directive in module.globs.borrow().iter() {
177177
if !allow_private_imports && directive.vis != ty::Visibility::Public { continue }
178178
if let Some(target_module) = directive.target_module.get() {
179-
let result = self.resolve_name_in_module(target_module, name, ns, false, false);
179+
let result = self.resolve_name_in_module(target_module, name, ns, false, None);
180180
if let Indeterminate = result {
181181
return Indeterminate;
182182
}
@@ -222,7 +222,7 @@ impl<'a> Resolver<'a> {
222222
SingleImport { source, .. } => source,
223223
GlobImport { .. } => unreachable!(),
224224
};
225-
match self.resolve_name_in_module(target_module, name, ns, false, false) {
225+
match self.resolve_name_in_module(target_module, name, ns, false, None) {
226226
Failed(_) => {}
227227
_ => return Some(Indeterminate),
228228
}
@@ -495,8 +495,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
495495
};
496496

497497
// We need to resolve both namespaces for this to succeed.
498-
let value_result = self.resolve_name_in_module(target_module, source, ValueNS, false, true);
499-
let type_result = self.resolve_name_in_module(target_module, source, TypeNS, false, true);
498+
let span = directive.span;
499+
let value_result =
500+
self.resolve_name_in_module(target_module, source, ValueNS, false, Some(span));
501+
let type_result =
502+
self.resolve_name_in_module(target_module, source, TypeNS, false, Some(span));
500503

501504
let mut privacy_error = true;
502505
for &(ns, result, determined) in &[(ValueNS, &value_result, value_determined),

0 commit comments

Comments
 (0)