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

Stabilize RFC 1560 #37127

Merged
merged 3 commits into from
Nov 21, 2016
Merged
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: 0 additions & 1 deletion src/libcoretest/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use std::prelude::v1::*;
use std::{i16, f64};
use super::super::*;
use core::num::flt2dec::*;
use core::num::bignum::Big32x40 as Big;
use core::num::flt2dec::strategy::dragon::*;

Expand Down
1 change: 0 additions & 1 deletion src/libcoretest/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use std::{i16, f64};
use super::super::*;
use core::num::flt2dec::*;
use core::num::flt2dec::strategy::grisu::*;

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

use super::*;
use super::MapEntry::*;

use hir::*;
use hir::intravisit::Visitor;
use hir::def_id::DefId;
use middle::cstore::InlinedItem;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::*;
use hir::map::definitions::*;

use hir;
use hir::intravisit;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#![feature(core_intrinsics)]
#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))]
#![feature(enumset)]
#![cfg_attr(stage0, feature(item_like_imports))]
#![feature(libc)]
#![feature(nonzero)]
#![feature(quote)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use rustc_const_eval as const_eval;
use rustc::middle::region::CodeExtent;
use rustc::ty::{self, AdtKind, VariantDef, Ty};
use rustc::ty::cast::CastKind as TyCastKind;
use rustc::mir::*;
use rustc::hir;
use syntax::ptr::P;

Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/hair/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

use hair::*;
use rustc::mir::*;
use rustc::mir::transform::MirSource;

use rustc::middle::const_val::ConstVal;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(associated_consts)]
#![feature(box_patterns)]
#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))]
#![cfg_attr(stage0, feature(item_like_imports))]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(staged_api)]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl<'b> Resolver<'b> {
});
} else {
for (name, span) in legacy_imports.imports {
let result = self.resolve_name_in_module(module, name, MacroNS, false, false, None);
let result = self.resolve_name_in_module(module, name, MacroNS, false, None);
if let Success(binding) = result {
self.legacy_import_macro(name, binding, span, allow_shadowing);
} else {
Expand All @@ -592,7 +592,7 @@ impl<'b> Resolver<'b> {
}
for (name, span) in legacy_imports.reexports {
self.used_crates.insert(module.def_id().unwrap().krate);
let result = self.resolve_name_in_module(module, name, MacroNS, false, false, None);
let result = self.resolve_name_in_module(module, name, MacroNS, false, None);
if let Success(binding) = result {
self.macro_exports.push(Export { name: name, def: binding.def() });
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ items under a new local name.

An example of this error:

```compile_fail
```ignore
use foo::baz;
use bar::*; // error, do `use foo::baz as quux` instead on the previous line

Expand Down
14 changes: 6 additions & 8 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,6 @@ pub struct Resolver<'a> {

arenas: &'a ResolverArenas<'a>,
dummy_binding: &'a NameBinding<'a>,
new_import_semantics: bool, // true if `#![feature(item_like_imports)]`
use_extern_macros: bool, // true if `#![feature(use_extern_macros)]`

pub exported_macros: Vec<ast::MacroDef>,
Expand Down Expand Up @@ -1333,7 +1332,6 @@ impl<'a> Resolver<'a> {
span: DUMMY_SP,
vis: ty::Visibility::Public,
}),
new_import_semantics: session.features.borrow().item_like_imports,
use_extern_macros: session.features.borrow().use_extern_macros,

exported_macros: Vec::new(),
Expand Down Expand Up @@ -1442,7 +1440,7 @@ impl<'a> Resolver<'a> {
-> ResolveResult<Module<'a>> {
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
-> Option<Module<'a>> {
match this.resolve_name_in_module(module, needle, TypeNS, false, false, None) {
match this.resolve_name_in_module(module, needle, TypeNS, false, None) {
Success(binding) if binding.is_extern_crate() => Some(module),
_ => if let (&ModuleKind::Def(..), Some(parent)) = (&module.kind, module.parent) {
search_parent_externals(this, needle, parent)
Expand All @@ -1460,7 +1458,7 @@ impl<'a> Resolver<'a> {
// modules as we go.
while index < module_path_len {
let name = module_path[index].name;
match self.resolve_name_in_module(search_module, name, TypeNS, false, false, span) {
match self.resolve_name_in_module(search_module, name, TypeNS, false, span) {
Failed(_) => {
let segment_name = name.as_str();
let module_name = module_to_string(search_module);
Expand Down Expand Up @@ -1617,7 +1615,7 @@ impl<'a> Resolver<'a> {

if let ModuleRibKind(module) = self.ribs[ns][i].kind {
let name = ident.name;
let item = self.resolve_name_in_module(module, name, ns, true, false, record_used);
let item = self.resolve_name_in_module(module, name, ns, false, record_used);
if let Success(binding) = item {
// The ident resolves to an item.
return Some(LexicalScopeBinding::Item(binding));
Expand All @@ -1626,7 +1624,7 @@ impl<'a> Resolver<'a> {
if let ModuleKind::Block(..) = module.kind { // We can see through blocks
} else if !module.no_implicit_prelude {
return self.prelude.and_then(|prelude| {
self.resolve_name_in_module(prelude, name, ns, false, false, None).success()
self.resolve_name_in_module(prelude, name, ns, false, None).success()
}).map(LexicalScopeBinding::Item)
} else {
return None;
Expand Down Expand Up @@ -2772,7 +2770,7 @@ impl<'a> Resolver<'a> {
};

let name = segments.last().unwrap().identifier.name;
let result = self.resolve_name_in_module(module, name, namespace, false, false, Some(span));
let result = self.resolve_name_in_module(module, name, namespace, false, Some(span));
result.success().ok_or(false)
}

Expand Down Expand Up @@ -2800,7 +2798,7 @@ impl<'a> Resolver<'a> {
};

let name = segments.last().unwrap().ident().name;
let result = self.resolve_name_in_module(module, name, namespace, false, false, Some(span));
let result = self.resolve_name_in_module(module, name, namespace, false, Some(span));
result.success().ok_or(false)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<'a> Resolver<'a> {
loop {
// Since expanded macros may not shadow the lexical scope (enforced below),
// we can ignore unresolved invocations (indicated by the penultimate argument).
match self.resolve_name_in_module(module, name, ns, true, true, record_used) {
match self.resolve_name_in_module(module, name, ns, true, record_used) {
Success(binding) => {
let span = match record_used {
Some(span) => span,
Expand Down
62 changes: 13 additions & 49 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub struct NameResolution<'a> {
single_imports: SingleImports<'a>,
/// The least shadowable known binding for this name, or None if there are no known bindings.
pub binding: Option<&'a NameBinding<'a>>,
duplicate_globs: Vec<&'a NameBinding<'a>>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -141,7 +140,6 @@ impl<'a> Resolver<'a> {
module: Module<'a>,
name: Name,
ns: Namespace,
allow_private_imports: bool,
ignore_unresolved_invocations: bool,
record_used: Option<Span>)
-> ResolveResult<&'a NameBinding<'a>> {
Expand All @@ -153,18 +151,8 @@ impl<'a> Resolver<'a> {
_ => return Failed(None), // This happens when there is a cycle of imports
};

let new_import_semantics = self.new_import_semantics;
let is_disallowed_private_import = |binding: &NameBinding| {
!new_import_semantics && !allow_private_imports && // disallowed
binding.vis != ty::Visibility::Public && binding.is_import() && // non-`pub` import
!binding.is_extern_crate() // not an `extern crate`
};

if let Some(span) = record_used {
if let Some(binding) = resolution.binding {
if is_disallowed_private_import(binding) {
return Failed(None);
}
if self.record_use(name, ns, binding, span) {
return Success(self.dummy_binding);
}
Expand All @@ -177,9 +165,8 @@ impl<'a> Resolver<'a> {
}

let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
let usable =
this.is_accessible(binding.vis) && !is_disallowed_private_import(binding) ||
binding.is_extern_crate(); // c.f. issue #37020
// `extern crate` are always usable for backwards compatability, see issue #37020.
let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
if usable { Success(binding) } else { Failed(None) }
};

Expand All @@ -202,7 +189,7 @@ impl<'a> Resolver<'a> {
SingleImport { source, .. } => source,
_ => unreachable!(),
};
match self.resolve_name_in_module(module, name, ns, true, false, None) {
match self.resolve_name_in_module(module, name, ns, false, None) {
Failed(_) => {}
_ => return Indeterminate,
}
Expand All @@ -224,7 +211,7 @@ impl<'a> Resolver<'a> {
for directive in module.globs.borrow().iter() {
if self.is_accessible(directive.vis.get()) {
if let Some(module) = directive.imported_module.get() {
let result = self.resolve_name_in_module(module, name, ns, true, false, None);
let result = self.resolve_name_in_module(module, name, ns, false, None);
if let Indeterminate = result {
return Indeterminate;
}
Expand Down Expand Up @@ -311,22 +298,17 @@ impl<'a> Resolver<'a> {
self.update_resolution(module, name, ns, |this, resolution| {
if let Some(old_binding) = resolution.binding {
if binding.is_glob_import() {
if !this.new_import_semantics {
resolution.duplicate_globs.push(binding);
} else if !old_binding.is_glob_import() &&
!(ns == MacroNS && old_binding.expansion != Mark::root()) {
if !old_binding.is_glob_import() &&
!(ns == MacroNS && old_binding.expansion != Mark::root()) {
} else if binding.def() != old_binding.def() {
resolution.binding = Some(this.ambiguity(old_binding, binding));
} else if !old_binding.vis.is_at_least(binding.vis, this) {
// We are glob-importing the same item but with greater visibility.
resolution.binding = Some(binding);
}
} else if old_binding.is_glob_import() {
if !this.new_import_semantics {
resolution.duplicate_globs.push(old_binding);
resolution.binding = Some(binding);
} else if ns == MacroNS && binding.expansion != Mark::root() &&
binding.def() != old_binding.def() {
if ns == MacroNS && binding.expansion != Mark::root() &&
binding.def() != old_binding.def() {
resolution.binding = Some(this.ambiguity(binding, old_binding));
} else {
resolution.binding = Some(binding);
Expand Down Expand Up @@ -366,7 +348,7 @@ impl<'a> Resolver<'a> {
let t = f(self, resolution);

match resolution.binding() {
_ if !self.new_import_semantics && old_binding.is_some() => return t,
_ if old_binding.is_some() => return t,
None => return t,
Some(binding) => match old_binding {
Some(old_binding) if old_binding as *const _ == binding as *const _ => return t,
Expand All @@ -377,10 +359,7 @@ impl<'a> Resolver<'a> {

// Define `binding` in `module`s glob importers.
for directive in module.glob_importers.borrow_mut().iter() {
if match self.new_import_semantics {
true => self.is_accessible_from(binding.vis, directive.parent),
false => binding.vis == ty::Visibility::Public,
} {
if self.is_accessible_from(binding.vis, directive.parent) {
let imported_binding = self.import(binding, directive);
let _ = self.try_define(directive.parent, name, ns, imported_binding);
}
Expand Down Expand Up @@ -528,7 +507,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
self.per_ns(|this, ns| {
if let Err(Undetermined) = result[ns].get() {
result[ns].set({
match this.resolve_name_in_module(module, source, ns, false, false, None) {
match this.resolve_name_in_module(module, source, ns, false, None) {
Success(binding) => Ok(binding),
Indeterminate => Err(Undetermined),
Failed(_) => Err(Determined),
Expand Down Expand Up @@ -624,7 +603,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
if all_ns_err {
let mut all_ns_failed = true;
self.per_ns(|this, ns| {
match this.resolve_name_in_module(module, name, ns, false, false, Some(span)) {
match this.resolve_name_in_module(module, name, ns, false, Some(span)) {
Success(_) => all_ns_failed = false,
_ => {}
}
Expand Down Expand Up @@ -729,8 +708,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
resolution.borrow().binding().map(|binding| (*name, binding))
}).collect::<Vec<_>>();
for ((name, ns), binding) in bindings {
if binding.pseudo_vis() == ty::Visibility::Public ||
self.new_import_semantics && self.is_accessible(binding.vis) {
if binding.pseudo_vis() == ty::Visibility::Public || self.is_accessible(binding.vis) {
let imported_binding = self.import(binding, directive);
let _ = self.try_define(directive.parent, name, ns, imported_binding);
}
Expand Down Expand Up @@ -761,20 +739,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
None => continue,
};

// Report conflicts
if !self.new_import_semantics {
for duplicate_glob in resolution.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 }
}
}

self.report_conflict(module, name, ns, duplicate_glob, binding);
}
}

if binding.vis == ty::Visibility::Public &&
(binding.is_import() || binding.is_extern_crate()) {
let def = binding.def();
Expand Down
4 changes: 1 addition & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ declare_features! (
// instead of just the platforms on which it is the C ABI
(active, abi_sysv64, "1.13.0", Some(36167)),

// Use the import semantics from RFC 1560.
(active, item_like_imports, "1.13.0", Some(35120)),

// Macros 1.1
(active, proc_macro, "1.13.0", Some(35900)),

Expand Down Expand Up @@ -362,6 +359,7 @@ declare_features! (
(accepted, question_mark, "1.13.0", Some(31436)),
// Allows `..` in tuple (struct) patterns
(accepted, dotdot_in_tuple_patterns, "1.14.0", Some(33627)),
(accepted, item_like_imports, "1.14.0", Some(35120)),
);
// (changing above list without updating src/doc/reference.md makes @cmr sad)

Expand Down
13 changes: 0 additions & 13 deletions src/test/compile-fail/auxiliary/issue_12612_1.rs

This file was deleted.

Loading