Skip to content

Commit f2837fa

Browse files
committed
Fix leaking immediate children and types via glob imports
1 parent 94a07b6 commit f2837fa

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/librustc/middle/resolve.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,19 @@ pub impl NameBindings {
622622
}
623623
}
624624
625+
fn defined_in_public_namespace(namespace: Namespace) -> bool {
626+
match namespace {
627+
TypeNS => match self.type_def {
628+
Some(def) => def.privacy != Private,
629+
None => false
630+
},
631+
ValueNS => match self.value_def {
632+
Some(def) => def.privacy != Private,
633+
None => false
634+
}
635+
}
636+
}
637+
625638
fn def_for_namespace(namespace: Namespace) -> Option<def> {
626639
match namespace {
627640
TypeNS => {
@@ -2538,7 +2551,6 @@ pub impl Resolver {
25382551
}
25392552
}
25402553

2541-
25422554
debug!("(resolving glob import) writing resolution `%s` in `%s` \
25432555
to `%s`, privacy=%?",
25442556
*self.session.str_of(ident),
@@ -2547,12 +2559,12 @@ pub impl Resolver {
25472559
dest_import_resolution.privacy);
25482560

25492561
// Merge the child item into the import resolution.
2550-
if (*name_bindings).defined_in_namespace(ValueNS) {
2562+
if (*name_bindings).defined_in_public_namespace(ValueNS) {
25512563
debug!("(resolving glob import) ... for value target");
25522564
dest_import_resolution.value_target =
25532565
Some(Target(containing_module, name_bindings));
25542566
}
2555-
if (*name_bindings).defined_in_namespace(TypeNS) {
2567+
if (*name_bindings).defined_in_public_namespace(TypeNS) {
25562568
debug!("(resolving glob import) ... for type target");
25572569
dest_import_resolution.type_target =
25582570
Some(Target(containing_module, name_bindings));

src/test/compile-fail/issue-4366.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ mod a {
2323
}
2424
pub mod sub {
2525
use a::b::*;
26-
fn sub() -> bar { foo(); 1 } //~ ERROR: unresolved name: foo
27-
//~^ ERROR: unresolved name: bar
26+
fn sub() -> bar { foo(); 1 } //~ ERROR: unresolved name: `foo`
27+
//~^ ERROR: use of undeclared type name `bar`
2828
}
2929
}
3030

@@ -34,6 +34,6 @@ mod m1 {
3434
use m1::*;
3535

3636
fn main() {
37-
foo(); //~ ERROR: unresolved name: foo
37+
foo(); //~ ERROR: unresolved name: `foo`
3838
}
3939

0 commit comments

Comments
 (0)