From fa18403a2f4acf203964c2ea7c8660752ee99cc3 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 13 Mar 2016 09:59:16 +0000 Subject: [PATCH 1/3] Refactor out methods `NameResolution::increment_outstanding_references` and `NameResolution::decrement_outstanding_references`. --- src/librustc_resolve/resolve_imports.rs | 37 +++++++++++++++---------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index ea16211c40d06..89586db32bcee 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -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(&self, mut report: F) { let binding = match self.binding { Some(binding) => binding, @@ -253,25 +272,13 @@ 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; - } + self.resolutions.borrow_mut().entry((name, ns)).or_insert_with(Default::default) + .increment_outstanding_references(is_public); } 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); - } + resolution.decrement_outstanding_references(is_public); }) } From 9ca3ff16ad14e187b970ac1714b9e050ccbbf825 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 13 Mar 2016 10:31:40 +0000 Subject: [PATCH 2/3] Fixes #32222 --- src/librustc_resolve/resolve_imports.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 89586db32bcee..31524b9a12acc 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -276,12 +276,6 @@ impl<'a> ::ModuleS<'a> { .increment_outstanding_references(is_public); } - fn decrement_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) { - self.update_resolution(name, ns, |resolution| { - resolution.decrement_outstanding_references(is_public); - }) - } - // Use `update` to mutate the resolution for the name. // If the resolution becomes a success, define it in the module's glob importers. fn update_resolution(&self, name: Name, ns: Namespace, update: F) -> T @@ -485,7 +479,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); @@ -522,7 +517,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) { From d1020143b67a55d3c5733f735f82bd683b0e35be Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 13 Mar 2016 10:41:21 +0000 Subject: [PATCH 3/3] Add regression test for #32222 --- src/test/compile-fail/issue-32222.rs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/compile-fail/issue-32222.rs diff --git a/src/test/compile-fail/issue-32222.rs b/src/test/compile-fail/issue-32222.rs new file mode 100644 index 0000000000000..b3b34f4b0efda --- /dev/null +++ b/src/test/compile-fail/issue-32222.rs @@ -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 or the MIT license +// , 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