Refactor record_used: bool
-> record_used: Option<Span>
.
This commit is contained in:
parent
75c3fd89d4
commit
05afe15d1f
2 changed files with 22 additions and 17 deletions
|
@ -1246,7 +1246,7 @@ impl<'a> Resolver<'a> {
|
||||||
-> ResolveResult<Module<'a>> {
|
-> ResolveResult<Module<'a>> {
|
||||||
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
|
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
|
||||||
-> Option<Module<'a>> {
|
-> Option<Module<'a>> {
|
||||||
match this.resolve_name_in_module(module, needle, TypeNS, false, false) {
|
match this.resolve_name_in_module(module, needle, TypeNS, false, None) {
|
||||||
Success(binding) if binding.is_extern_crate() => Some(module),
|
Success(binding) if binding.is_extern_crate() => Some(module),
|
||||||
_ => match module.parent_link {
|
_ => match module.parent_link {
|
||||||
ModuleParentLink(ref parent, _) => {
|
ModuleParentLink(ref parent, _) => {
|
||||||
|
@ -1265,7 +1265,7 @@ impl<'a> Resolver<'a> {
|
||||||
// modules as we go.
|
// modules as we go.
|
||||||
while index < module_path_len {
|
while index < module_path_len {
|
||||||
let name = module_path[index];
|
let name = module_path[index];
|
||||||
match self.resolve_name_in_module(search_module, name, TypeNS, false, true) {
|
match self.resolve_name_in_module(search_module, name, TypeNS, false, Some(span)) {
|
||||||
Failed(None) => {
|
Failed(None) => {
|
||||||
let segment_name = name.as_str();
|
let segment_name = name.as_str();
|
||||||
let module_name = module_to_string(search_module);
|
let module_name = module_to_string(search_module);
|
||||||
|
@ -1361,7 +1361,7 @@ impl<'a> Resolver<'a> {
|
||||||
// first component of the path in the current lexical
|
// first component of the path in the current lexical
|
||||||
// scope and then proceed to resolve below that.
|
// scope and then proceed to resolve below that.
|
||||||
let ident = ast::Ident::with_empty_ctxt(module_path[0]);
|
let ident = ast::Ident::with_empty_ctxt(module_path[0]);
|
||||||
match self.resolve_ident_in_lexical_scope(ident, TypeNS, true)
|
match self.resolve_ident_in_lexical_scope(ident, TypeNS, Some(span))
|
||||||
.and_then(LexicalScopeBinding::module) {
|
.and_then(LexicalScopeBinding::module) {
|
||||||
None => return Failed(None),
|
None => return Failed(None),
|
||||||
Some(containing_module) => {
|
Some(containing_module) => {
|
||||||
|
@ -1404,7 +1404,7 @@ impl<'a> Resolver<'a> {
|
||||||
fn resolve_ident_in_lexical_scope(&mut self,
|
fn resolve_ident_in_lexical_scope(&mut self,
|
||||||
mut ident: ast::Ident,
|
mut ident: ast::Ident,
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
record_used: bool)
|
record_used: Option<Span>)
|
||||||
-> Option<LexicalScopeBinding<'a>> {
|
-> Option<LexicalScopeBinding<'a>> {
|
||||||
if ns == TypeNS {
|
if ns == TypeNS {
|
||||||
ident = ast::Ident::with_empty_ctxt(ident.name);
|
ident = ast::Ident::with_empty_ctxt(ident.name);
|
||||||
|
@ -1432,7 +1432,7 @@ impl<'a> Resolver<'a> {
|
||||||
if module.def.is_some() {
|
if module.def.is_some() {
|
||||||
return match self.prelude {
|
return match self.prelude {
|
||||||
Some(prelude) if !module.no_implicit_prelude.get() => {
|
Some(prelude) if !module.no_implicit_prelude.get() => {
|
||||||
self.resolve_name_in_module(prelude, name, ns, false, false).success()
|
self.resolve_name_in_module(prelude, name, ns, false, None).success()
|
||||||
.map(LexicalScopeBinding::Item)
|
.map(LexicalScopeBinding::Item)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -2287,7 +2287,7 @@ impl<'a> Resolver<'a> {
|
||||||
PatKind::Ident(bmode, ref ident, ref opt_pat) => {
|
PatKind::Ident(bmode, ref ident, ref opt_pat) => {
|
||||||
// First try to resolve the identifier as some existing
|
// First try to resolve the identifier as some existing
|
||||||
// entity, then fall back to a fresh binding.
|
// entity, then fall back to a fresh binding.
|
||||||
let binding = self.resolve_ident_in_lexical_scope(ident.node, ValueNS, false)
|
let binding = self.resolve_ident_in_lexical_scope(ident.node, ValueNS, None)
|
||||||
.and_then(LexicalScopeBinding::item);
|
.and_then(LexicalScopeBinding::item);
|
||||||
let resolution = binding.and_then(NameBinding::def).and_then(|def| {
|
let resolution = binding.and_then(NameBinding::def).and_then(|def| {
|
||||||
let always_binding = !pat_src.is_refutable() || opt_pat.is_some() ||
|
let always_binding = !pat_src.is_refutable() || opt_pat.is_some() ||
|
||||||
|
@ -2454,11 +2454,11 @@ impl<'a> Resolver<'a> {
|
||||||
//
|
//
|
||||||
// Such behavior is required for backward compatibility.
|
// Such behavior is required for backward compatibility.
|
||||||
// The same fallback is used when `a` resolves to nothing.
|
// The same fallback is used when `a` resolves to nothing.
|
||||||
let def = resolve_identifier_with_fallback(self, true).ok_or(false);
|
let def = resolve_identifier_with_fallback(self, Some(span)).ok_or(false);
|
||||||
return def.and_then(|def| self.adjust_local_def(def, span).ok_or(true)).map(mk_res);
|
return def.and_then(|def| self.adjust_local_def(def, span).ok_or(true)).map(mk_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
let unqualified_def = resolve_identifier_with_fallback(self, false);
|
let unqualified_def = resolve_identifier_with_fallback(self, None);
|
||||||
let qualified_binding = self.resolve_module_relative_path(span, segments, namespace);
|
let qualified_binding = self.resolve_module_relative_path(span, segments, namespace);
|
||||||
match (qualified_binding, unqualified_def) {
|
match (qualified_binding, unqualified_def) {
|
||||||
(Ok(binding), Some(ref ud)) if binding.def().unwrap() == ud.def => {
|
(Ok(binding), Some(ref ud)) if binding.def().unwrap() == ud.def => {
|
||||||
|
@ -2478,7 +2478,7 @@ impl<'a> Resolver<'a> {
|
||||||
fn resolve_identifier(&mut self,
|
fn resolve_identifier(&mut self,
|
||||||
identifier: ast::Ident,
|
identifier: ast::Ident,
|
||||||
namespace: Namespace,
|
namespace: Namespace,
|
||||||
record_used: bool)
|
record_used: Option<Span>)
|
||||||
-> Option<LocalDef> {
|
-> Option<LocalDef> {
|
||||||
if identifier.name == keywords::Invalid.name() {
|
if identifier.name == keywords::Invalid.name() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -2613,7 +2613,8 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = segments.last().unwrap().identifier.name;
|
let name = segments.last().unwrap().identifier.name;
|
||||||
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
|
let result =
|
||||||
|
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
|
||||||
result.success().map(|binding| {
|
result.success().map(|binding| {
|
||||||
self.check_privacy(name, binding, span);
|
self.check_privacy(name, binding, span);
|
||||||
binding
|
binding
|
||||||
|
@ -2657,7 +2658,8 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = segments.last().unwrap().name();
|
let name = segments.last().unwrap().name();
|
||||||
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
|
let result =
|
||||||
|
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
|
||||||
result.success().map(|binding| {
|
result.success().map(|binding| {
|
||||||
self.check_privacy(name, binding, span);
|
self.check_privacy(name, binding, span);
|
||||||
binding
|
binding
|
||||||
|
|
|
@ -149,7 +149,7 @@ impl<'a> Resolver<'a> {
|
||||||
name: Name,
|
name: Name,
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
allow_private_imports: bool,
|
allow_private_imports: bool,
|
||||||
record_used: bool)
|
record_used: Option<Span>)
|
||||||
-> ResolveResult<&'a NameBinding<'a>> {
|
-> ResolveResult<&'a NameBinding<'a>> {
|
||||||
self.populate_module_if_necessary(module);
|
self.populate_module_if_necessary(module);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ impl<'a> Resolver<'a> {
|
||||||
if !allow_private_imports && binding.is_import() && !binding.is_pseudo_public() {
|
if !allow_private_imports && binding.is_import() && !binding.is_pseudo_public() {
|
||||||
return Failed(None);
|
return Failed(None);
|
||||||
}
|
}
|
||||||
if record_used {
|
if record_used.is_some() {
|
||||||
self.record_use(name, ns, binding);
|
self.record_use(name, ns, binding);
|
||||||
}
|
}
|
||||||
Success(binding)
|
Success(binding)
|
||||||
|
@ -176,7 +176,7 @@ impl<'a> Resolver<'a> {
|
||||||
for directive in module.globs.borrow().iter() {
|
for directive in module.globs.borrow().iter() {
|
||||||
if !allow_private_imports && directive.vis != ty::Visibility::Public { continue }
|
if !allow_private_imports && directive.vis != ty::Visibility::Public { continue }
|
||||||
if let Some(target_module) = directive.target_module.get() {
|
if let Some(target_module) = directive.target_module.get() {
|
||||||
let result = self.resolve_name_in_module(target_module, name, ns, false, false);
|
let result = self.resolve_name_in_module(target_module, name, ns, false, None);
|
||||||
if let Indeterminate = result {
|
if let Indeterminate = result {
|
||||||
return Indeterminate;
|
return Indeterminate;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ impl<'a> Resolver<'a> {
|
||||||
SingleImport { source, .. } => source,
|
SingleImport { source, .. } => source,
|
||||||
GlobImport { .. } => unreachable!(),
|
GlobImport { .. } => unreachable!(),
|
||||||
};
|
};
|
||||||
match self.resolve_name_in_module(target_module, name, ns, false, false) {
|
match self.resolve_name_in_module(target_module, name, ns, false, None) {
|
||||||
Failed(_) => {}
|
Failed(_) => {}
|
||||||
_ => return Some(Indeterminate),
|
_ => return Some(Indeterminate),
|
||||||
}
|
}
|
||||||
|
@ -495,8 +495,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// We need to resolve both namespaces for this to succeed.
|
// We need to resolve both namespaces for this to succeed.
|
||||||
let value_result = self.resolve_name_in_module(target_module, source, ValueNS, false, true);
|
let span = directive.span;
|
||||||
let type_result = self.resolve_name_in_module(target_module, source, TypeNS, false, true);
|
let value_result =
|
||||||
|
self.resolve_name_in_module(target_module, source, ValueNS, false, Some(span));
|
||||||
|
let type_result =
|
||||||
|
self.resolve_name_in_module(target_module, source, TypeNS, false, Some(span));
|
||||||
|
|
||||||
let mut privacy_error = true;
|
let mut privacy_error = true;
|
||||||
for &(ns, result, determined) in &[(ValueNS, &value_result, value_determined),
|
for &(ns, result, determined) in &[(ValueNS, &value_result, value_determined),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue