Skip to content

Commit 94a07b6

Browse files
committed
Fix leaking non-public 'use' statements with glob imports
1 parent e1d3a4f commit 94a07b6

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/librustc/middle/resolve.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ pub impl Resolver {
24802480

24812481
// Here we merge two import resolutions.
24822482
match module_.import_resolutions.find(&ident) {
2483-
None => {
2483+
None if target_import_resolution.privacy == Public => {
24842484
// Simple: just copy the old import resolution.
24852485
let new_import_resolution =
24862486
@mut ImportResolution(privacy,
@@ -2494,6 +2494,7 @@ pub impl Resolver {
24942494
module_.import_resolutions.insert
24952495
(ident, new_import_resolution);
24962496
}
2497+
None => { /* continue ... */ }
24972498
Some(dest_import_resolution) => {
24982499
// Merge the two import resolutions at a finer-grained
24992500
// level.
@@ -2756,6 +2757,8 @@ pub impl Resolver {
27562757
namespace);
27572758
}
27582759
Some(target) => {
2760+
debug!("(resolving item in lexical scope) using \
2761+
import resolution");
27592762
import_resolution.state.used = true;
27602763
return Success(copy target);
27612764
}

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

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// regression test for issue 4366
12+
13+
// ensures that 'use foo:*' doesn't import non-public 'use' statements in the
14+
// module 'foo'
15+
16+
mod foo {
17+
pub fn foo() {}
18+
}
19+
mod a {
20+
pub mod b {
21+
use foo::foo;
22+
type bar = int;
23+
}
24+
pub mod sub {
25+
use a::b::*;
26+
fn sub() -> bar { foo(); 1 } //~ ERROR: unresolved name: foo
27+
//~^ ERROR: unresolved name: bar
28+
}
29+
}
30+
31+
mod m1 {
32+
fn foo() {}
33+
}
34+
use m1::*;
35+
36+
fn main() {
37+
foo(); //~ ERROR: unresolved name: foo
38+
}
39+

0 commit comments

Comments
 (0)