Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement RFC 1560. #32213

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl<H> Default for BuildHasherDefault<H> {
//////////////////////////////////////////////////////////////////////////////

mod impls {
#[allow(unused_imports)]
use prelude::v1::*;

use mem;
Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use std::prelude::v1::*;
use std::{i16, f64};
use super::super::*;
#[allow(unused_imports)]
use core::num::flt2dec::*;
use core::num::bignum::Big32x40 as Big;
use core::num::flt2dec::strategy::dragon::*;
Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use std::{i16, f64};
use super::super::*;
#[allow(unused_imports)]
use core::num::flt2dec::*;
use core::num::flt2dec::strategy::grisu::*;

Expand Down
2 changes: 2 additions & 0 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
// except according to those terms.

use super::*;
#[allow(unused_imports)]
use super::MapEntry::*;

#[allow(unused_imports)]
use hir::*;
use hir::intravisit::Visitor;
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rustc_const_eval as const_eval;
use rustc::middle::region::CodeExtent;
use rustc::hir::pat_util;
use rustc::ty::{self, VariantDef, Ty};
#[allow(unused_imports)]
use rustc::mir::repr::*;
use rustc::hir;
use syntax::ptr::P;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/hair/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

use hair::*;
#[allow(unused_imports)]
use rustc::mir::repr::*;

use rustc::middle::const_val::ConstVal;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/hair/cx/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_const_eval as const_eval;
use rustc::hir::def::Def;
use rustc::hir::pat_util::{pat_is_resolved_const, pat_is_binding};
use rustc::ty::{self, Ty};
#[allow(unused_imports)]
use rustc::mir::repr::*;
use rustc::hir::{self, PatKind};
use syntax::ast;
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
match use_lexical_scope {
true => module.resolve_name_in_lexical_scope(name, namespace)
.map(Success).unwrap_or(Failed(None)),
false => module.resolve_name(name, namespace, false),
false => {
let allow_private_imports = module.is_ancestor_of(self.current_module);
module.resolve_name(name, namespace, allow_private_imports)
}
}.and_then(|binding| {
if record_used {
self.record_use(name, namespace, binding);
Expand Down
50 changes: 27 additions & 23 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ impl<'a> ImportDirective<'a> {
// this returns the binding for the name this directive defines in that namespace.
fn import(&self, binding: &'a NameBinding<'a>, privacy_error: Option<Box<PrivacyError<'a>>>)
-> NameBinding<'a> {
let mut modifiers = match self.is_public {
let mut modifiers = match self.is_public && binding.is_public() {
true => DefModifiers::PUBLIC | DefModifiers::IMPORTABLE,
false => DefModifiers::empty(),
false => DefModifiers::IMPORTABLE,
};
if let GlobImport = self.subclass {
modifiers = modifiers | DefModifiers::GLOB_IMPORTED;
} else if self.is_public && binding.is_extern_crate() {
// `pub` single imports of private extern crates are public (see #31362).
modifiers = modifiers | DefModifiers::PUBLIC;
}

NameBinding {
Expand Down Expand Up @@ -143,10 +146,18 @@ impl<'a> NameResolution<'a> {
fn try_define(&mut self, binding: &'a NameBinding<'a>) -> Result<(), &'a NameBinding<'a>> {
if let Some(old_binding) = self.binding {
if binding.defined_with(DefModifiers::GLOB_IMPORTED) {
self.duplicate_globs.push(binding);
if binding.def().unwrap() != old_binding.def().unwrap() {
self.duplicate_globs.push(binding);
} else if old_binding.defined_with(DefModifiers::GLOB_IMPORTED) &&
old_binding.is_public() < binding.is_public() {
// We are glob-importing the same item but with greater visibility.
self.binding = Some(binding);
}
} else if old_binding.defined_with(DefModifiers::GLOB_IMPORTED) {
self.duplicate_globs.push(old_binding);
self.binding = Some(binding);
if binding.def().unwrap() != old_binding.def().unwrap() {
self.duplicate_globs.push(old_binding);
}
} else {
return Err(old_binding);
}
Expand Down Expand Up @@ -207,22 +218,15 @@ impl<'a> NameResolution<'a> {
self.binding.map(Success)
}

fn report_conflicts<F: FnMut(&NameBinding, &NameBinding)>(&self, mut report: F) {
fn report_conflicts<F: FnMut(&NameBinding, &NameBinding)>(&mut self, mut _report: F) {
let binding = match self.binding {
Some(binding) => binding,
None => return,
};

for duplicate_glob in self.duplicate_globs.iter() {
// FIXME #31337: We currently allow items to shadow glob-imported re-exports.
if !binding.is_import() {
if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
if binding.is_import() { continue }
}
}

report(duplicate_glob, binding);
}
if !binding.defined_with(DefModifiers::GLOB_IMPORTED) { return }
let binding = &mut self.binding;
self.duplicate_globs.iter().next().map(|_| *binding = None);
}
}

Expand Down Expand Up @@ -321,11 +325,7 @@ impl<'a> ::ModuleS<'a> {
// where it might end up getting re-defined via a glob cycle.
let (new_binding, t) = {
let mut resolution = &mut *self.resolution(name, ns).borrow_mut();
let was_known = resolution.binding().is_some();

let t = update(resolution);

if was_known { return t; }
match resolution.binding() {
Some(binding) => (binding, t),
None => return t,
Expand All @@ -337,9 +337,11 @@ impl<'a> ::ModuleS<'a> {
}

fn define_in_glob_importers(&self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>) {
if !binding.defined_with(DefModifiers::PUBLIC | DefModifiers::IMPORTABLE) { return }
if !binding.defined_with(DefModifiers::IMPORTABLE) { return }
for &(importer, directive) in self.glob_importers.borrow_mut().iter() {
let _ = importer.try_define_child(name, ns, directive.import(binding, None));
if binding.is_public() || self.is_ancestor_of(importer) {
let _ = importer.try_define_child(name, ns, directive.import(binding, None));
}
}
}
}
Expand Down Expand Up @@ -661,8 +663,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
let bindings = target_module.resolutions.borrow().iter().filter_map(|(name, resolution)| {
resolution.borrow().binding().map(|binding| (*name, binding))
}).collect::<Vec<_>>();
let allow_private_names = target_module.is_ancestor_of(module_);
for ((name, ns), binding) in bindings {
if binding.defined_with(DefModifiers::IMPORTABLE | DefModifiers::PUBLIC) {
if !binding.defined_with(DefModifiers::IMPORTABLE) { continue }
if allow_private_names || binding.is_public() {
let _ = module_.try_define_child(name, ns, directive.import(binding, None));
}
}
Expand All @@ -688,7 +692,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {

let mut reexports = Vec::new();
for (&(name, ns), resolution) in module.resolutions.borrow().iter() {
let resolution = resolution.borrow();
let mut resolution = resolution.borrow_mut();
resolution.report_conflicts(|b1, b2| {
self.resolver.report_conflict(module, name, ns, b1, b2)
});
Expand Down
1 change: 1 addition & 0 deletions src/libstd/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ static ASCII_UPPERCASE_MAP: [u8; 256] = [

#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;
use super::*;
use char::from_u32;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ mod arch {

#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;
use super::*;

Expand Down
1 change: 1 addition & 0 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ impl<'a, T: ToSocketAddrs + ?Sized> ToSocketAddrs for &'a T {

#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;
use net::*;
use net::test::{tsa, sa6, sa4};
Expand Down
1 change: 1 addition & 0 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ impl From<[u8; 16]> for Ipv6Addr {
// Tests for this module
#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;
use net::*;
use net::Ipv6MulticastScope::*;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ impl fmt::Debug for TcpListener {

#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;

use io::ErrorKind;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ impl fmt::Debug for UdpSocket {

#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;

use io::ErrorKind;
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/common/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ pub mod test {

#[cfg(test)]
mod tests {
#[allow(unused_imports)]
use prelude::v1::*;
#[allow(unused_imports)]
use io::prelude::*;
use super::*;
use io;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/ext/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ impl IntoRawFd for UnixDatagram {

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use prelude::v1::*;
use thread;
use io;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ impl Process {
#[cfg(test)]
mod tests {
use super::*;
#[allow(unused_imports)]
use prelude::v1::*;

use ffi::OsStr;
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/issue_12612_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// except according to those terms.

pub mod bar {
pub fn foo() {}
fn foo() {}
}
26 changes: 0 additions & 26 deletions src/test/compile-fail/glob-cycles.rs

This file was deleted.

8 changes: 3 additions & 5 deletions src/test/compile-fail/import-shadow-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![no_implicit_prelude]

use foo::*;
use bar::*; //~ERROR a type named `Baz` has already been imported in this module
use bar::*;

mod foo {
pub type Baz = isize;
Expand All @@ -23,8 +23,6 @@ mod bar {
pub type Baz = isize;
}

mod qux {
pub use bar::Baz;
fn main() {
Baz; //~ ERROR
}

fn main() {}
30 changes: 0 additions & 30 deletions src/test/compile-fail/import-shadow-2.rs

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/compile-fail/import-shadow-3.rs

This file was deleted.

Loading