Skip to content

Commit

Permalink
Auto merge of #56032 - petrochenkov:stabecip, r=nikomatsakis
Browse files Browse the repository at this point in the history
Stabilize `extern_crate_item_prelude`

Closes #55599
  • Loading branch information
bors committed Nov 21, 2018
2 parents f1e2fa8 + d4934c7 commit 780658a
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 151 deletions.
12 changes: 2 additions & 10 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
use syntax::ext::base::SyntaxExtension;
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
use syntax::ext::base::MacroKind;
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::symbol::{Symbol, keywords};
use syntax::util::lev_distance::find_best_match_for_name;

Expand Down Expand Up @@ -2115,7 +2114,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {

if !module.no_implicit_prelude {
if ns == TypeNS {
if let Some(binding) = self.extern_prelude_get(ident, !record_used, false) {
if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
return Some(LexicalScopeBinding::Item(binding));
}
}
Expand Down Expand Up @@ -5022,21 +5021,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
self.name_already_seen.insert(name, span);
}

fn extern_prelude_get(&mut self, ident: Ident, speculative: bool, skip_feature_gate: bool)
fn extern_prelude_get(&mut self, ident: Ident, speculative: bool)
-> Option<&'a NameBinding<'a>> {
if ident.is_path_segment_keyword() {
// Make sure `self`, `super` etc produce an error when passed to here.
return None;
}
self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| {
if let Some(binding) = entry.extern_crate_item {
if !speculative && !skip_feature_gate && entry.introduced_by_item &&
!self.session.features_untracked().extern_crate_item_prelude {
emit_feature_err(&self.session.parse_sess, "extern_crate_item_prelude",
ident.span, GateIssue::Language,
"use of extern prelude names introduced \
with `extern crate` items is unstable");
}
Some(binding)
} else {
let crate_id = if !speculative {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}
WhereToResolve::ExternPrelude => {
if use_prelude {
match self.extern_prelude_get(ident, !record_used,
innermost_result.is_some()) {
match self.extern_prelude_get(ident, !record_used) {
Some(binding) => Ok((binding, Flags::PRELUDE)),
None => Err(Determinacy::determined(
self.graph_root.unresolved_invocations.borrow().is_empty()
Expand Down Expand Up @@ -906,7 +905,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
// but its `Def` should coincide with a crate passed with `--extern`
// (otherwise there would be ambiguity) and we can skip feature error in this case.
if ns != TypeNS || !use_prelude ||
self.extern_prelude_get(ident, true, false).is_none() {
self.extern_prelude_get(ident, true).is_none() {
let msg = "imports can only refer to extern crate names \
passed with `--extern` on stable channel";
let mut err = feature_err(&self.session.parse_sess, "uniform_paths",
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
assert!(!restricted_shadowing);
match uniform_root_kind {
UniformRootKind::ExternPrelude => {
return if let Some(binding) =
self.extern_prelude_get(ident, !record_used, false) {
return if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
Ok(binding)
} else if !self.graph_root.unresolved_invocations.borrow().is_empty() {
// Macro-expanded `extern crate` items can add names to extern prelude.
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,6 @@ declare_features! (
// Allows `const _: TYPE = VALUE`
(active, underscore_const_names, "1.31.0", Some(54912), None),

// `extern crate foo as bar;` puts `bar` into extern prelude.
(active, extern_crate_item_prelude, "1.31.0", Some(55599), None),

// `reason = ` in lint attributes and `expect` lint attribute
(active, lint_reasons, "1.31.0", Some(54503), None),
);
Expand Down Expand Up @@ -691,6 +688,8 @@ declare_features! (
// impl<I:Iterator> Iterator for &mut Iterator
// impl Debug for Foo<'_>
(accepted, impl_header_lifetime_elision, "1.31.0", Some(15872), None),
// `extern crate foo as bar;` puts `bar` into extern prelude.
(accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None),
);

// If you change this, please modify src/doc/unstable-book as well. You must
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// compile-pass
// edition:2018

#![feature(extern_crate_item_prelude)]

extern crate proc_macro;
use proc_macro::TokenStream; // OK

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// compile-pass
// edition:2018

#![feature(extern_crate_item_prelude)]

macro_rules! define_iso { () => {
extern crate std as iso;
}}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/imports/extern-prelude-extern-crate-cfg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// compile-pass
// compile-flags:--cfg my_feature

#![feature(extern_crate_item_prelude)]
#![no_std]

#[cfg(my_feature)]
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/imports/extern-prelude-extern-crate-pass.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// compile-pass
// aux-build:two_macros.rs

#![feature(extern_crate_item_prelude)]

extern crate two_macros;

mod m {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// aux-build:two_macros.rs

#![feature(extern_crate_item_prelude)]

macro_rules! define_vec {
() => {
extern crate std as Vec;
Expand All @@ -16,4 +14,13 @@ mod m {
}
}

macro_rules! define_other_core {
() => {
extern crate std as core;
//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
}
}

define_other_core!();

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:19:9
|
LL | extern crate std as core;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_other_core!();
| --------------------- in this macro invocation

error[E0659]: `Vec` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:15:9
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:13:9
|
LL | Vec::panic!(); //~ ERROR `Vec` is ambiguous
| ^^^ ambiguous name
|
= note: `Vec` could refer to a struct from prelude
note: `Vec` could also refer to the extern crate imported here
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:7:9
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:5:9
|
LL | extern crate std as Vec;
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_vec!();
| -------------- in this macro invocation

error: aborting due to previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0659`.
12 changes: 12 additions & 0 deletions src/test/ui/imports/extern-prelude-extern-crate-shadowing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// compile-pass
// aux-build:two_macros.rs

extern crate two_macros as core;

mod m {
fn check() {
core::m!(); // OK
}
}

fn main() {}

0 comments on commit 780658a

Please sign in to comment.