diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-08 15:10:41 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-10 15:22:01 -0700 |
| commit | 1f2c18a0afd55bf3a5319d9e3810ec1ac6b3e1bb (patch) | |
| tree | 7cae8ac126922eee38607c2a0032c85cdad7ba0d | |
| parent | df533c6e87f5052667b0c03c918f95b51439fdba (diff) | |
| download | rust-1f2c18a0afd55bf3a5319d9e3810ec1ac6b3e1bb.tar.gz rust-1f2c18a0afd55bf3a5319d9e3810ec1ac6b3e1bb.zip | |
rustc: Don't allow priv use to shadow pub use
Previously, a private use statement would shadow a public use statement, all of a sudden publicly exporting the privately used item. The correct behavior here is to only shadow the use for the module in question, but for now it just reverts the entire name to private so the pub use doesn't have much effect. The behavior isn't exactly what we want, but this no longer has backwards compatibility hazards.
| -rw-r--r-- | src/librustc/middle/resolve.rs | 1 | ||||
| -rw-r--r-- | src/libstd/io/test.rs | 1 | ||||
| -rw-r--r-- | src/test/compile-fail/resolve-priv-shadowing-pub.rs | 33 |
3 files changed, 34 insertions, 1 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 8240068979c..38eab354f2b 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1982,6 +1982,7 @@ impl<'a> Resolver<'a> { // the source of this name is different now resolution.type_id.set(id); resolution.value_id.set(id); + resolution.is_public.set(is_public); } None => { debug!("(building import directive) creating new"); diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index 14b9b5c1e06..dd874fecc52 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -39,7 +39,6 @@ macro_rules! iotest ( use io::process::*; use unstable::running_on_valgrind; use str; - use util; fn f() $b diff --git a/src/test/compile-fail/resolve-priv-shadowing-pub.rs b/src/test/compile-fail/resolve-priv-shadowing-pub.rs new file mode 100644 index 00000000000..0830722f969 --- /dev/null +++ b/src/test/compile-fail/resolve-priv-shadowing-pub.rs @@ -0,0 +1,33 @@ +// Copyright 2014 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. + +mod a { + pub fn foobar() -> int { 1 } +} + +mod b { + pub fn foobar() -> int { 2 } +} + +mod c { + // Technically the second use shadows the first, but in theory it should + // only be shadowed for this module. The implementation of resolve currently + // doesn't implement this, so this test is ensuring that using "c::foobar" + // is *not* getting b::foobar. Today it's an error, but perhaps one day it + // can correctly get a::foobar instead. + pub use a::foobar; + use b::foobar; +} + +fn main() { + assert_eq!(c::foobar(), 1); + //~^ ERROR: unresolved name `c::foobar` +} + |
