Write and use increment_outstanding_references_for and decrement_outstanding_references_for
This commit is contained in:
parent
96b4dc4b87
commit
16e7ff1bff
3 changed files with 27 additions and 19 deletions
|
@ -16,7 +16,6 @@
|
|||
use DefModifiers;
|
||||
use resolve_imports::ImportDirective;
|
||||
use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
|
||||
use resolve_imports::NameResolution;
|
||||
use Module;
|
||||
use Namespace::{self, TypeNS, ValueNS};
|
||||
use {NameBinding, NameBindingKind};
|
||||
|
@ -699,15 +698,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
|||
debug!("(building import directive) building import directive: {}::{}",
|
||||
names_to_string(&module_.imports.borrow().last().unwrap().module_path),
|
||||
target);
|
||||
|
||||
let mut import_resolutions = module_.import_resolutions.borrow_mut();
|
||||
for &ns in [TypeNS, ValueNS].iter() {
|
||||
let mut resolution = import_resolutions.entry((target, ns)).or_insert(
|
||||
NameResolution::default()
|
||||
);
|
||||
|
||||
resolution.outstanding_references += 1;
|
||||
}
|
||||
module_.increment_outstanding_references_for(target, ValueNS);
|
||||
module_.increment_outstanding_references_for(target, TypeNS);
|
||||
}
|
||||
GlobImport => {
|
||||
// Set the glob flag. This tells us that we don't know the
|
||||
|
|
|
@ -670,6 +670,13 @@ impl<T> ResolveResult<T> {
|
|||
Success(t) => f(t),
|
||||
}
|
||||
}
|
||||
|
||||
fn success(self) -> Option<T> {
|
||||
match self {
|
||||
Success(t) => Some(t),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum FallbackSuggestion {
|
||||
|
@ -870,6 +877,19 @@ impl<'a> ModuleS<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn increment_outstanding_references_for(&self, name: Name, ns: Namespace) {
|
||||
let mut resolutions = self.import_resolutions.borrow_mut();
|
||||
resolutions.entry((name, ns)).or_insert_with(Default::default).outstanding_references += 1;
|
||||
}
|
||||
|
||||
fn decrement_outstanding_references_for(&self, name: Name, ns: Namespace) {
|
||||
match self.import_resolutions.borrow_mut().get_mut(&(name, ns)).unwrap()
|
||||
.outstanding_references {
|
||||
0 => panic!("No more outstanding references!"),
|
||||
ref mut outstanding_references => { *outstanding_references -= 1; }
|
||||
}
|
||||
}
|
||||
|
||||
fn for_each_local_child<F: FnMut(Name, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
|
||||
for (&(name, ns), name_binding) in self.children.borrow().iter() {
|
||||
if !name_binding.is_extern_crate() {
|
||||
|
|
|
@ -511,9 +511,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
}
|
||||
|
||||
// We've successfully resolved the import. Write the results in.
|
||||
let mut import_resolutions = module_.import_resolutions.borrow_mut();
|
||||
|
||||
{
|
||||
let mut import_resolutions = module_.import_resolutions.borrow_mut();
|
||||
let mut check_and_write_import = |namespace, result| {
|
||||
let result: &ResolveResult<&NameBinding> = result;
|
||||
|
||||
|
@ -567,14 +567,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
}
|
||||
|
||||
let value_def_and_priv = {
|
||||
let import_resolution_value = import_resolutions.get_mut(&(target, ValueNS)).unwrap();
|
||||
assert!(import_resolution_value.outstanding_references >= 1);
|
||||
import_resolution_value.outstanding_references -= 1;
|
||||
module_.decrement_outstanding_references_for(target, ValueNS);
|
||||
|
||||
// Record what this import resolves to for later uses in documentation,
|
||||
// this may resolve to either a value or a type, but for documentation
|
||||
// purposes it's good enough to just favor one over the other.
|
||||
import_resolution_value.binding.as_ref().map(|binding| {
|
||||
value_result.success().map(|binding| {
|
||||
let def = binding.def().unwrap();
|
||||
let last_private = if binding.is_public() { lp } else { DependsOn(def.def_id()) };
|
||||
(def, last_private)
|
||||
|
@ -582,11 +580,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
};
|
||||
|
||||
let type_def_and_priv = {
|
||||
let import_resolution_type = import_resolutions.get_mut(&(target, TypeNS)).unwrap();
|
||||
assert!(import_resolution_type.outstanding_references >= 1);
|
||||
import_resolution_type.outstanding_references -= 1;
|
||||
module_.decrement_outstanding_references_for(target, TypeNS);
|
||||
|
||||
import_resolution_type.binding.as_ref().map(|binding| {
|
||||
type_result.success().map(|binding| {
|
||||
let def = binding.def().unwrap();
|
||||
let last_private = if binding.is_public() { lp } else { DependsOn(def.def_id()) };
|
||||
(def, last_private)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue