Skip to content

Commit 5680ec0

Browse files
committed
auto merge of #5113 : alexcrichton/rust/issue-4366, r=catamorphism
The first two commits are the actual fix going into place, and the last is just dealing with the fallout in the rest of the compiler. The test added in the first two commits had 0 failures before this patch, and if the glob imports were changed to explicit imports then the errors showed up. Due to this behavior, I figured that the desired behavior was for glob imports to not accidentally leak a lot of non-public imports/functions/types into other modules. There was quite a lot of fallout, and it all passes `make check` locally, but I doubt that it will pass on all platforms because there's probably some guarded off thing I missed. I plan on making another patch soon which changes the default level of `unused_imports` to `warn` which will hopefully reduce a lot of the `use` noise throughout. In conjunction with #5104, and a few minor fixes, I think that the default level of `warn` is actually really usable.
2 parents 0d30af1 + 2df07dd commit 5680ec0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+547
-293
lines changed

src/libcore/hashmap.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
//! Sendable hash maps.
1212
13-
use container::{Container, Mutable, Map, Set};
14-
use cmp::Eq;
15-
use hash::Hash;
16-
use to_bytes::IterBytes;
17-
1813
/// Open addressing with linear probing.
1914
pub mod linear {
20-
use super::*;
15+
use container::{Container, Mutable, Map, Set};
16+
use cmp::Eq;
17+
use hash::Hash;
18+
use to_bytes::IterBytes;
2119
use iter::BaseIter;
2220
use hash::Hash;
2321
use iter;
@@ -752,7 +750,8 @@ mod test_map {
752750

753751
#[test]
754752
mod test_set {
755-
use super::*;
753+
use hashmap::linear;
754+
use container::{Container, Mutable, Map, Set};
756755
use vec;
757756

758757
#[test]

src/libcore/os.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1021,10 +1021,10 @@ extern {
10211021
pub mod consts {
10221022
10231023
#[cfg(unix)]
1024-
use os::consts::unix::*;
1024+
pub use os::consts::unix::*;
10251025
10261026
#[cfg(windows)]
1027-
use os::consts::windows::*;
1027+
pub use os::consts::windows::*;
10281028
10291029
pub mod unix {
10301030
pub const FAMILY: &str = "unix";
@@ -1035,19 +1035,19 @@ pub mod consts {
10351035
}
10361036
10371037
#[cfg(target_os = "macos")]
1038-
use os::consts::macos::*;
1038+
pub use os::consts::macos::*;
10391039
10401040
#[cfg(target_os = "freebsd")]
1041-
use os::consts::freebsd::*;
1041+
pub use os::consts::freebsd::*;
10421042
10431043
#[cfg(target_os = "linux")]
1044-
use os::consts::linux::*;
1044+
pub use os::consts::linux::*;
10451045
10461046
#[cfg(target_os = "android")]
1047-
use os::consts::android::*;
1047+
pub use os::consts::android::*;
10481048
10491049
#[cfg(target_os = "win32")]
1050-
use os::consts::win32::*;
1050+
pub use os::consts::win32::*;
10511051
10521052
pub mod macos {
10531053
pub const SYSNAME: &str = "macos";
@@ -1086,13 +1086,13 @@ pub mod consts {
10861086
10871087
10881088
#[cfg(target_arch = "x86")]
1089-
use os::consts::x86::*;
1089+
pub use os::consts::x86::*;
10901090
10911091
#[cfg(target_arch = "x86_64")]
1092-
use os::consts::x86_64::*;
1092+
pub use os::consts::x86_64::*;
10931093
10941094
#[cfg(target_arch = "arm")]
1095-
use os::consts::arm::*;
1095+
pub use os::consts::arm::*;
10961096
10971097
pub mod x86 {
10981098
pub const ARCH: &str = "x86";

src/libcore/str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,7 @@ impl OwnedStr for ~str {
23752375
#[cfg(test)]
23762376
mod tests {
23772377
use char;
2378+
use option::Some;
23782379
use debug;
23792380
use libc::c_char;
23802381
use libc;

src/libcore/vec.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ pub fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
14441444
* The total number of permutations produced is `len(v)!`. If `v` contains
14451445
* repeated elements, then some permutations are repeated.
14461446
*/
1447-
pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
1447+
pub pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
14481448
let ln = len(v);
14491449
if ln <= 1 {
14501450
put(v);
@@ -2427,6 +2427,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
24272427
mod tests {
24282428
use option::{None, Option, Some};
24292429
use option;
2430+
use sys;
24302431
use vec::*;
24312432

24322433
fn square(n: uint) -> uint { return n * n; }

src/librustc/middle/borrowck/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ use middle::liveness;
230230
use middle::mem_categorization::*;
231231
use middle::region;
232232
use middle::ty;
233+
use middle::typeck;
233234
use middle::moves;
234235
use util::common::{indenter, stmt_set};
235236
use util::ppaux::{expr_repr, note_and_explain_region};
@@ -239,6 +240,7 @@ use core::cmp;
239240
use core::dvec::DVec;
240241
use core::io;
241242
use core::result::{Result, Ok, Err};
243+
use core::to_bytes;
242244
use std::list::{List, Cons, Nil};
243245
use std::list;
244246
use std::oldmap::{HashMap, Set};

src/librustc/middle/resolve.rs

+19-4
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 => {
@@ -2480,7 +2493,7 @@ pub impl Resolver {
24802493

24812494
// Here we merge two import resolutions.
24822495
match module_.import_resolutions.find(&ident) {
2483-
None => {
2496+
None if target_import_resolution.privacy == Public => {
24842497
// Simple: just copy the old import resolution.
24852498
let new_import_resolution =
24862499
@mut ImportResolution(privacy,
@@ -2494,6 +2507,7 @@ pub impl Resolver {
24942507
module_.import_resolutions.insert
24952508
(ident, new_import_resolution);
24962509
}
2510+
None => { /* continue ... */ }
24972511
Some(dest_import_resolution) => {
24982512
// Merge the two import resolutions at a finer-grained
24992513
// level.
@@ -2537,7 +2551,6 @@ pub impl Resolver {
25372551
}
25382552
}
25392553

2540-
25412554
debug!("(resolving glob import) writing resolution `%s` in `%s` \
25422555
to `%s`, privacy=%?",
25432556
*self.session.str_of(ident),
@@ -2546,12 +2559,12 @@ pub impl Resolver {
25462559
dest_import_resolution.privacy);
25472560

25482561
// Merge the child item into the import resolution.
2549-
if (*name_bindings).defined_in_namespace(ValueNS) {
2562+
if (*name_bindings).defined_in_public_namespace(ValueNS) {
25502563
debug!("(resolving glob import) ... for value target");
25512564
dest_import_resolution.value_target =
25522565
Some(Target(containing_module, name_bindings));
25532566
}
2554-
if (*name_bindings).defined_in_namespace(TypeNS) {
2567+
if (*name_bindings).defined_in_public_namespace(TypeNS) {
25552568
debug!("(resolving glob import) ... for type target");
25562569
dest_import_resolution.type_target =
25572570
Some(Target(containing_module, name_bindings));
@@ -2756,6 +2769,8 @@ pub impl Resolver {
27562769
namespace);
27572770
}
27582771
Some(target) => {
2772+
debug!("(resolving item in lexical scope) using \
2773+
import resolution");
27592774
import_resolution.state.used = true;
27602775
return Success(copy target);
27612776
}

src/librustc/middle/trans/_match.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@
145145
use core::prelude::*;
146146

147147
use back::abi;
148-
use lib::llvm::llvm;
149-
use lib::llvm::{ValueRef, BasicBlockRef};
148+
use lib;
149+
use lib::llvm::{llvm, ValueRef, BasicBlockRef};
150150
use middle::const_eval;
151+
use middle::borrowck::root_map_key;
151152
use middle::pat_util::*;
152153
use middle::resolve::DefMap;
153154
use middle::trans::base::*;
@@ -156,20 +157,26 @@ use middle::trans::callee;
156157
use middle::trans::common::*;
157158
use middle::trans::consts;
158159
use middle::trans::controlflow;
160+
use middle::trans::datum;
159161
use middle::trans::datum::*;
160162
use middle::trans::expr::Dest;
161163
use middle::trans::expr;
162164
use middle::trans::glue;
165+
use middle::trans::tvec;
166+
use middle::trans::type_of;
167+
use middle::ty;
163168
use util::common::indenter;
164169

165170
use core::dvec::DVec;
166171
use core::dvec;
172+
use core::libc::c_ulonglong;
167173
use std::oldmap::HashMap;
168174
use syntax::ast::def_id;
169175
use syntax::ast;
170-
use syntax::ast_util::{dummy_sp, path_to_ident};
176+
use syntax::ast::ident;
177+
use syntax::ast_util::path_to_ident;
171178
use syntax::ast_util;
172-
use syntax::codemap::span;
179+
use syntax::codemap::{span, dummy_sp};
173180
use syntax::print::pprust::pat_to_str;
174181

175182
// An option identifying a literal: either a unit-like struct or an

src/librustc/middle/trans/base.rs

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use middle::borrowck::RootInfo;
4444
use middle::pat_util::*;
4545
use middle::resolve;
4646
use middle::trans::_match;
47+
use middle::trans::base;
4748
use middle::trans::build::*;
4849
use middle::trans::callee;
4950
use middle::trans::common::*;
@@ -56,12 +57,15 @@ use middle::trans::foreign;
5657
use middle::trans::glue;
5758
use middle::trans::inline;
5859
use middle::trans::machine;
60+
use middle::trans::machine::llsize_of;
5961
use middle::trans::meth;
6062
use middle::trans::monomorphize;
6163
use middle::trans::reachable;
6264
use middle::trans::shape::*;
6365
use middle::trans::tvec;
66+
use middle::trans::type_of;
6467
use middle::trans::type_of::*;
68+
use middle::ty;
6569
use middle::ty::arg;
6670
use util::common::indenter;
6771
use util::ppaux::{ty_to_str, ty_to_short_str};
@@ -77,6 +81,7 @@ use core::option;
7781
use core::uint;
7882
use std::oldmap::HashMap;
7983
use std::{oldmap, time, list};
84+
use syntax::ast::ident;
8085
use syntax::ast_map::{path, path_elt_to_str, path_mod, path_name};
8186
use syntax::ast_util::{def_id_of_def, local_def, path_to_ident};
8287
use syntax::attr;

src/librustc/middle/trans/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use codemap::span;
13+
use lib;
1314
use lib::llvm::llvm;
1415
use lib::llvm::{CallConv, TypeKind, AtomicBinOp, AtomicOrdering};
1516
use lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False};
@@ -18,9 +19,12 @@ use libc::{c_uint, c_int, c_ulonglong};
1819
use middle::trans::common::*;
1920
use middle::trans::machine::llsize_of_real;
2021

22+
use core::prelude::*;
2123
use core::cast::transmute;
2224
use core::cast;
2325
use core::libc;
26+
use core::option::Some;
27+
use core::ptr;
2428
use core::str;
2529
use core::vec;
2630
use std::oldmap::HashMap;

src/librustc/middle/trans/cabi.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ use middle::trans::base::*;
1313
use middle::trans::build::*;
1414
use middle::trans::common::*;
1515

16+
use core::libc::c_uint;
17+
use core::option;
18+
use core::vec;
19+
1620
pub trait ABIInfo {
1721
fn compute_info(&self,
1822
atys: &[TypeRef],
@@ -28,7 +32,7 @@ pub struct LLVMType {
2832
pub struct FnType {
2933
arg_tys: ~[LLVMType],
3034
ret_ty: LLVMType,
31-
attrs: ~[Option<Attribute>],
35+
attrs: ~[option::Option<Attribute>],
3236
sret: bool
3337
}
3438

@@ -93,7 +97,7 @@ pub impl FnType {
9397
llargbundle: ValueRef, llretval: ValueRef) {
9498
for vec::eachi(self.attrs) |i, a| {
9599
match *a {
96-
Some(attr) => {
100+
option::Some(attr) => {
97101
unsafe {
98102
llvm::LLVMAddInstrAttribute(
99103
llretval, (i + 1u) as c_uint,

src/librustc/middle/trans/cabi_x86_64.rs

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ use lib::llvm::struct_tys;
1818
use middle::trans::common::*;
1919
use middle::trans::cabi::*;
2020

21+
use core::cmp;
22+
use core::libc::c_uint;
23+
use core::option;
24+
use core::option::Option;
25+
use core::ptr;
26+
use core::uint;
27+
use core::vec;
28+
2129
enum x86_64_reg_class {
2230
no_class,
2331
integer_class,

src/librustc/middle/trans/callee.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,33 @@
1818

1919
use core::prelude::*;
2020

21-
use lib::llvm::ValueRef;
22-
use middle::trans::base::{get_item_val, trans_external_path};
21+
use back::abi;
22+
use driver::session;
23+
use lib;
24+
use lib::llvm::{ValueRef, TypeRef};
25+
use lib::llvm::llvm;
26+
use metadata::csearch;
27+
use middle::trans::base;
28+
use middle::trans::base::*;
2329
use middle::trans::build::*;
2430
use middle::trans::callee;
2531
use middle::trans::closure;
26-
use middle::trans::common::{block, node_id_type_params};
32+
use middle::trans::common;
33+
use middle::trans::common::*;
2734
use middle::trans::datum::*;
2835
use middle::trans::datum::Datum;
36+
use middle::trans::expr;
37+
use middle::trans::glue;
2938
use middle::trans::inline;
3039
use middle::trans::meth;
3140
use middle::trans::monomorphize;
41+
use middle::trans::type_of;
42+
use middle::ty;
3243
use middle::typeck;
3344
use util::common::indenter;
3445

3546
use syntax::ast;
47+
use syntax::ast_map;
3648
use syntax::print::pprust::{expr_to_str, stmt_to_str, path_to_str};
3749
use syntax::visit;
3850

0 commit comments

Comments
 (0)