Skip to content

Commit

Permalink
auto merge of #5113 : alexcrichton/rust/issue-4366, r=catamorphism
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Feb 28, 2013
2 parents 0d30af1 + 2df07dd commit 5680ec0
Show file tree
Hide file tree
Showing 72 changed files with 547 additions and 293 deletions.
13 changes: 6 additions & 7 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

//! Sendable hash maps.
use container::{Container, Mutable, Map, Set};
use cmp::Eq;
use hash::Hash;
use to_bytes::IterBytes;

/// Open addressing with linear probing.
pub mod linear {
use super::*;
use container::{Container, Mutable, Map, Set};
use cmp::Eq;
use hash::Hash;
use to_bytes::IterBytes;
use iter::BaseIter;
use hash::Hash;
use iter;
Expand Down Expand Up @@ -752,7 +750,8 @@ mod test_map {

#[test]
mod test_set {
use super::*;
use hashmap::linear;
use container::{Container, Mutable, Map, Set};
use vec;

#[test]
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,10 +1021,10 @@ extern {
pub mod consts {
#[cfg(unix)]
use os::consts::unix::*;
pub use os::consts::unix::*;
#[cfg(windows)]
use os::consts::windows::*;
pub use os::consts::windows::*;
pub mod unix {
pub const FAMILY: &str = "unix";
Expand All @@ -1035,19 +1035,19 @@ pub mod consts {
}
#[cfg(target_os = "macos")]
use os::consts::macos::*;
pub use os::consts::macos::*;
#[cfg(target_os = "freebsd")]
use os::consts::freebsd::*;
pub use os::consts::freebsd::*;
#[cfg(target_os = "linux")]
use os::consts::linux::*;
pub use os::consts::linux::*;
#[cfg(target_os = "android")]
use os::consts::android::*;
pub use os::consts::android::*;
#[cfg(target_os = "win32")]
use os::consts::win32::*;
pub use os::consts::win32::*;
pub mod macos {
pub const SYSNAME: &str = "macos";
Expand Down Expand Up @@ -1086,13 +1086,13 @@ pub mod consts {
#[cfg(target_arch = "x86")]
use os::consts::x86::*;
pub use os::consts::x86::*;
#[cfg(target_arch = "x86_64")]
use os::consts::x86_64::*;
pub use os::consts::x86_64::*;
#[cfg(target_arch = "arm")]
use os::consts::arm::*;
pub use os::consts::arm::*;
pub mod x86 {
pub const ARCH: &str = "x86";
Expand Down
1 change: 1 addition & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,7 @@ impl OwnedStr for ~str {
#[cfg(test)]
mod tests {
use char;
use option::Some;
use debug;
use libc::c_char;
use libc;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ pub fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
* The total number of permutations produced is `len(v)!`. If `v` contains
* repeated elements, then some permutations are repeated.
*/
pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
pub pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
let ln = len(v);
if ln <= 1 {
put(v);
Expand Down Expand Up @@ -2427,6 +2427,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
mod tests {
use option::{None, Option, Some};
use option;
use sys;
use vec::*;

fn square(n: uint) -> uint { return n * n; }
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ use middle::liveness;
use middle::mem_categorization::*;
use middle::region;
use middle::ty;
use middle::typeck;
use middle::moves;
use util::common::{indenter, stmt_set};
use util::ppaux::{expr_repr, note_and_explain_region};
Expand All @@ -239,6 +240,7 @@ use core::cmp;
use core::dvec::DVec;
use core::io;
use core::result::{Result, Ok, Err};
use core::to_bytes;
use std::list::{List, Cons, Nil};
use std::list;
use std::oldmap::{HashMap, Set};
Expand Down
23 changes: 19 additions & 4 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,19 @@ pub impl NameBindings {
}
}
fn defined_in_public_namespace(namespace: Namespace) -> bool {
match namespace {
TypeNS => match self.type_def {
Some(def) => def.privacy != Private,
None => false
},
ValueNS => match self.value_def {
Some(def) => def.privacy != Private,
None => false
}
}
}
fn def_for_namespace(namespace: Namespace) -> Option<def> {
match namespace {
TypeNS => {
Expand Down Expand Up @@ -2480,7 +2493,7 @@ pub impl Resolver {

// Here we merge two import resolutions.
match module_.import_resolutions.find(&ident) {
None => {
None if target_import_resolution.privacy == Public => {
// Simple: just copy the old import resolution.
let new_import_resolution =
@mut ImportResolution(privacy,
Expand All @@ -2494,6 +2507,7 @@ pub impl Resolver {
module_.import_resolutions.insert
(ident, new_import_resolution);
}
None => { /* continue ... */ }
Some(dest_import_resolution) => {
// Merge the two import resolutions at a finer-grained
// level.
Expand Down Expand Up @@ -2537,7 +2551,6 @@ pub impl Resolver {
}
}


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

// Merge the child item into the import resolution.
if (*name_bindings).defined_in_namespace(ValueNS) {
if (*name_bindings).defined_in_public_namespace(ValueNS) {
debug!("(resolving glob import) ... for value target");
dest_import_resolution.value_target =
Some(Target(containing_module, name_bindings));
}
if (*name_bindings).defined_in_namespace(TypeNS) {
if (*name_bindings).defined_in_public_namespace(TypeNS) {
debug!("(resolving glob import) ... for type target");
dest_import_resolution.type_target =
Some(Target(containing_module, name_bindings));
Expand Down Expand Up @@ -2756,6 +2769,8 @@ pub impl Resolver {
namespace);
}
Some(target) => {
debug!("(resolving item in lexical scope) using \
import resolution");
import_resolution.state.used = true;
return Success(copy target);
}
Expand Down
15 changes: 11 additions & 4 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@
use core::prelude::*;

use back::abi;
use lib::llvm::llvm;
use lib::llvm::{ValueRef, BasicBlockRef};
use lib;
use lib::llvm::{llvm, ValueRef, BasicBlockRef};
use middle::const_eval;
use middle::borrowck::root_map_key;
use middle::pat_util::*;
use middle::resolve::DefMap;
use middle::trans::base::*;
Expand All @@ -156,20 +157,26 @@ use middle::trans::callee;
use middle::trans::common::*;
use middle::trans::consts;
use middle::trans::controlflow;
use middle::trans::datum;
use middle::trans::datum::*;
use middle::trans::expr::Dest;
use middle::trans::expr;
use middle::trans::glue;
use middle::trans::tvec;
use middle::trans::type_of;
use middle::ty;
use util::common::indenter;

use core::dvec::DVec;
use core::dvec;
use core::libc::c_ulonglong;
use std::oldmap::HashMap;
use syntax::ast::def_id;
use syntax::ast;
use syntax::ast_util::{dummy_sp, path_to_ident};
use syntax::ast::ident;
use syntax::ast_util::path_to_ident;
use syntax::ast_util;
use syntax::codemap::span;
use syntax::codemap::{span, dummy_sp};
use syntax::print::pprust::pat_to_str;

// An option identifying a literal: either a unit-like struct or an
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use middle::borrowck::RootInfo;
use middle::pat_util::*;
use middle::resolve;
use middle::trans::_match;
use middle::trans::base;
use middle::trans::build::*;
use middle::trans::callee;
use middle::trans::common::*;
Expand All @@ -56,12 +57,15 @@ use middle::trans::foreign;
use middle::trans::glue;
use middle::trans::inline;
use middle::trans::machine;
use middle::trans::machine::llsize_of;
use middle::trans::meth;
use middle::trans::monomorphize;
use middle::trans::reachable;
use middle::trans::shape::*;
use middle::trans::tvec;
use middle::trans::type_of;
use middle::trans::type_of::*;
use middle::ty;
use middle::ty::arg;
use util::common::indenter;
use util::ppaux::{ty_to_str, ty_to_short_str};
Expand All @@ -77,6 +81,7 @@ use core::option;
use core::uint;
use std::oldmap::HashMap;
use std::{oldmap, time, list};
use syntax::ast::ident;
use syntax::ast_map::{path, path_elt_to_str, path_mod, path_name};
use syntax::ast_util::{def_id_of_def, local_def, path_to_ident};
use syntax::attr;
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


use codemap::span;
use lib;
use lib::llvm::llvm;
use lib::llvm::{CallConv, TypeKind, AtomicBinOp, AtomicOrdering};
use lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False};
Expand All @@ -18,9 +19,12 @@ use libc::{c_uint, c_int, c_ulonglong};
use middle::trans::common::*;
use middle::trans::machine::llsize_of_real;

use core::prelude::*;
use core::cast::transmute;
use core::cast;
use core::libc;
use core::option::Some;
use core::ptr;
use core::str;
use core::vec;
use std::oldmap::HashMap;
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/trans/cabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use middle::trans::base::*;
use middle::trans::build::*;
use middle::trans::common::*;

use core::libc::c_uint;
use core::option;
use core::vec;

pub trait ABIInfo {
fn compute_info(&self,
atys: &[TypeRef],
Expand All @@ -28,7 +32,7 @@ pub struct LLVMType {
pub struct FnType {
arg_tys: ~[LLVMType],
ret_ty: LLVMType,
attrs: ~[Option<Attribute>],
attrs: ~[option::Option<Attribute>],
sret: bool
}

Expand Down Expand Up @@ -93,7 +97,7 @@ pub impl FnType {
llargbundle: ValueRef, llretval: ValueRef) {
for vec::eachi(self.attrs) |i, a| {
match *a {
Some(attr) => {
option::Some(attr) => {
unsafe {
llvm::LLVMAddInstrAttribute(
llretval, (i + 1u) as c_uint,
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/middle/trans/cabi_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ use lib::llvm::struct_tys;
use middle::trans::common::*;
use middle::trans::cabi::*;

use core::cmp;
use core::libc::c_uint;
use core::option;
use core::option::Option;
use core::ptr;
use core::uint;
use core::vec;

enum x86_64_reg_class {
no_class,
integer_class,
Expand Down
18 changes: 15 additions & 3 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,33 @@

use core::prelude::*;

use lib::llvm::ValueRef;
use middle::trans::base::{get_item_val, trans_external_path};
use back::abi;
use driver::session;
use lib;
use lib::llvm::{ValueRef, TypeRef};
use lib::llvm::llvm;
use metadata::csearch;
use middle::trans::base;
use middle::trans::base::*;
use middle::trans::build::*;
use middle::trans::callee;
use middle::trans::closure;
use middle::trans::common::{block, node_id_type_params};
use middle::trans::common;
use middle::trans::common::*;
use middle::trans::datum::*;
use middle::trans::datum::Datum;
use middle::trans::expr;
use middle::trans::glue;
use middle::trans::inline;
use middle::trans::meth;
use middle::trans::monomorphize;
use middle::trans::type_of;
use middle::ty;
use middle::typeck;
use util::common::indenter;

use syntax::ast;
use syntax::ast_map;
use syntax::print::pprust::{expr_to_str, stmt_to_str, path_to_str};
use syntax::visit;

Expand Down
Loading

0 comments on commit 5680ec0

Please sign in to comment.