Auto merge of #32227 - jseyfried:fix_import_resolution_bug, r=alexcrichton
Fix import resolution bug This fixes #32222, which was introduced in #31726.
This commit is contained in:
commit
d5880fff99
2 changed files with 61 additions and 22 deletions
|
@ -176,6 +176,25 @@ impl<'a> NameResolution<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn increment_outstanding_references(&mut self, is_public: bool) {
|
||||
self.outstanding_references += 1;
|
||||
if is_public {
|
||||
self.pub_outstanding_references += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn decrement_outstanding_references(&mut self, is_public: bool) {
|
||||
let decrement_references = |count: &mut _| {
|
||||
assert!(*count > 0);
|
||||
*count -= 1;
|
||||
};
|
||||
|
||||
decrement_references(&mut self.outstanding_references);
|
||||
if is_public {
|
||||
decrement_references(&mut self.pub_outstanding_references);
|
||||
}
|
||||
}
|
||||
|
||||
fn report_conflicts<F: FnMut(&NameBinding, &NameBinding)>(&self, mut report: F) {
|
||||
let binding = match self.binding {
|
||||
Some(binding) => binding,
|
||||
|
@ -253,26 +272,8 @@ impl<'a> ::ModuleS<'a> {
|
|||
}
|
||||
|
||||
pub fn increment_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) {
|
||||
let mut resolutions = self.resolutions.borrow_mut();
|
||||
let resolution = resolutions.entry((name, ns)).or_insert_with(Default::default);
|
||||
resolution.outstanding_references += 1;
|
||||
if is_public {
|
||||
resolution.pub_outstanding_references += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn decrement_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) {
|
||||
let decrement_references = |count: &mut _| {
|
||||
assert!(*count > 0);
|
||||
*count -= 1;
|
||||
};
|
||||
|
||||
self.update_resolution(name, ns, |resolution| {
|
||||
decrement_references(&mut resolution.outstanding_references);
|
||||
if is_public {
|
||||
decrement_references(&mut resolution.pub_outstanding_references);
|
||||
}
|
||||
})
|
||||
self.resolutions.borrow_mut().entry((name, ns)).or_insert_with(Default::default)
|
||||
.increment_outstanding_references(is_public);
|
||||
}
|
||||
|
||||
// Use `update` to mutate the resolution for the name.
|
||||
|
@ -477,7 +478,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
// Temporarily count the directive as determined so that the resolution fails
|
||||
// (as opposed to being indeterminate) when it can only be defined by the directive.
|
||||
if !determined {
|
||||
module_.decrement_outstanding_references_for(target, ns, directive.is_public)
|
||||
module_.resolutions.borrow_mut().get_mut(&(target, ns)).unwrap()
|
||||
.decrement_outstanding_references(directive.is_public);
|
||||
}
|
||||
let result =
|
||||
self.resolver.resolve_name_in_module(target_module, source, ns, false, true);
|
||||
|
@ -514,7 +516,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
self.report_conflict(target, ns, &directive.import(binding, None), old_binding);
|
||||
}
|
||||
}
|
||||
module_.decrement_outstanding_references_for(target, ns, directive.is_public);
|
||||
|
||||
module_.update_resolution(target, ns, |resolution| {
|
||||
resolution.decrement_outstanding_references(directive.is_public);
|
||||
})
|
||||
}
|
||||
|
||||
match (&value_result, &type_result) {
|
||||
|
|
34
src/test/compile-fail/issue-32222.rs
Normal file
34
src/test/compile-fail/issue-32222.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![allow(warnings)]
|
||||
|
||||
mod foo {
|
||||
pub fn bar() {}
|
||||
}
|
||||
|
||||
pub use foo::*;
|
||||
use b::bar;
|
||||
|
||||
mod foobar {
|
||||
use super::*;
|
||||
}
|
||||
|
||||
mod a {
|
||||
pub mod bar {}
|
||||
}
|
||||
|
||||
mod b {
|
||||
pub use a::bar;
|
||||
}
|
||||
|
||||
#[rustc_error]
|
||||
fn main() {} //~ ERROR compilation successful
|
Loading…
Add table
Add a link
Reference in a new issue