From eabf11b9cb1f1bddeb1208e5564e592d10e4b680 Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Mon, 16 Dec 2013 23:32:37 -0800 Subject: [PATCH] Don't allow impls to force public types This code in resolve accidentally forced all types with an impl to become public. This fixes it by default inheriting the privacy of what was previously there and then becoming `true` if nothing else exits. Closes #10545 --- src/libextra/bitv.rs | 3 ++- src/libextra/btree.rs | 2 +- src/libextra/sync.rs | 2 +- src/libextra/test.rs | 4 +--- src/libextra/treemap.rs | 2 +- src/librustc/middle/resolve.rs | 7 ++++++- src/librustc/middle/trans/base.rs | 2 +- src/libstd/hash.rs | 1 + src/libstd/rt/mpmc_bounded_queue.rs | 2 +- src/test/compile-fail/issue-10545.rs | 20 ++++++++++++++++++++ 10 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/test/compile-fail/issue-10545.rs diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 733a8932218..3b44ad50ad7 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -932,7 +932,8 @@ impl<'a> Iterator<uint> for BitvSetIterator<'a> { mod tests { use extra::test::BenchHarness; - use bitv::*; + use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn, + from_bytes}; use bitv; use std::uint; diff --git a/src/libextra/btree.rs b/src/libextra/btree.rs index 5a4547ffeb2..0f9eba2e9dc 100644 --- a/src/libextra/btree.rs +++ b/src/libextra/btree.rs @@ -407,7 +407,7 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BranchElt<K, V> { #[cfg(test)] mod test_btree{ - use super::*; + use super::{BTree, LeafElt}; ///Tests the functionality of the add methods (which are unfinished). #[test] diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 6e582982962..1546e9ca59c 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -329,7 +329,7 @@ impl Sem<~[WaitQueue]> { ****************************************************************************/ /// A counting, blocking, bounded-waiting semaphore. -struct Semaphore { priv sem: Sem<()> } +pub struct Semaphore { priv sem: Sem<()> } impl Clone for Semaphore { diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 974d4dc1dc5..8f0c4fe6d23 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -670,7 +670,6 @@ fn should_sort_failures_before_printing_them() { use std::io::Decorator; use std::io::mem::MemWriter; use std::str; - fn dummy() {} let test_a = TestDesc { name: StaticTestName("a"), @@ -1296,8 +1295,6 @@ mod tests { #[test] pub fn filter_for_ignored_option() { - fn dummy() {} - // When we run ignored tests the test filter should filter out all the // unignored tests and flip the ignore flag on the rest to false @@ -1441,6 +1438,7 @@ mod tests { assert_eq!(diff2.len(), 7); } + #[test] pub fn ratchet_test() { let dpth = TempDir::new("test-ratchet").expect("missing test for ratchet"); diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 7c411048149..1cf980b1059 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -884,7 +884,7 @@ impl<T: TotalOrd> Extendable<T> for TreeSet<T> { #[cfg(test)] mod test_treemap { - use super::*; + use super::{TreeMap, TreeNode}; use std::rand::Rng; use std::rand; diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 970b373f424..07bcba684ca 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1258,11 +1258,16 @@ impl Resolver { let parent_link = self.get_parent_link(new_parent, ident); let def_id = local_def(item.id); + let ns = TypeNS; + let is_public = + !name_bindings.defined_in_namespace(ns) || + name_bindings.defined_in_public_namespace(ns); + name_bindings.define_module(parent_link, Some(def_id), ImplModuleKind, false, - true, + is_public, sp); ModuleReducedGraphParent( diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index abb3e22edb7..c8be404f5ff 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -130,7 +130,7 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt { _InsnCtxt { _x: () } } -struct StatRecorder<'a> { +pub struct StatRecorder<'a> { ccx: @mut CrateContext, name: &'a str, start: u64, diff --git a/src/libstd/hash.rs b/src/libstd/hash.rs index a135d66141a..4782bb5dd13 100644 --- a/src/libstd/hash.rs +++ b/src/libstd/hash.rs @@ -303,6 +303,7 @@ impl Streaming for SipState { mod tests { use super::*; use prelude::*; + use super::SipState; // Hash just the bytes of the slice, without length prefix struct Bytes<'a>(&'a [u8]); diff --git a/src/libstd/rt/mpmc_bounded_queue.rs b/src/libstd/rt/mpmc_bounded_queue.rs index 1e04e5eb78d..25a3ba8ab48 100644 --- a/src/libstd/rt/mpmc_bounded_queue.rs +++ b/src/libstd/rt/mpmc_bounded_queue.rs @@ -51,7 +51,7 @@ struct State<T> { pad3: [u8, ..64], } -struct Queue<T> { +pub struct Queue<T> { priv state: UnsafeArc<State<T>>, } diff --git a/src/test/compile-fail/issue-10545.rs b/src/test/compile-fail/issue-10545.rs new file mode 100644 index 00000000000..f6c62bb8557 --- /dev/null +++ b/src/test/compile-fail/issue-10545.rs @@ -0,0 +1,20 @@ +// Copyright 2013 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 { + struct S; + impl S { } +} + +fn foo(_: a::S) { //~ ERROR: type `S` is private +} + +fn main() {}