Skip to content

Commit

Permalink
rustc: Don't allow priv use to shadow pub use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Apr 10, 2014
1 parent df533c6 commit 1f2c18a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ macro_rules! iotest (
use io::process::*;
use unstable::running_on_valgrind;
use str;
use util;

fn f() $b

Expand Down
33 changes: 33 additions & 0 deletions src/test/compile-fail/resolve-priv-shadowing-pub.rs
Original file line number Diff line number Diff line change
@@ -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`
}

5 comments on commit 1f2c18a

@bors
Copy link
Contributor

@bors bors commented on 1f2c18a Apr 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at alexcrichton@1f2c18a

@bors
Copy link
Contributor

@bors bors commented on 1f2c18a Apr 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/rollup = 1f2c18a into auto

@bors
Copy link
Contributor

@bors bors commented on 1f2c18a Apr 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/rollup = 1f2c18a merged ok, testing candidate = 0156af1

@bors
Copy link
Contributor

@bors bors commented on 1f2c18a Apr 11, 2014

@bors
Copy link
Contributor

@bors bors commented on 1f2c18a Apr 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 0156af1

Please sign in to comment.