Skip to content

Commit 780658a

Browse files
committed
Auto merge of rust-lang#56032 - petrochenkov:stabecip, r=nikomatsakis
Stabilize `extern_crate_item_prelude` Closes rust-lang#55599
2 parents f1e2fa8 + d4934c7 commit 780658a

13 files changed

+40
-151
lines changed

src/librustc_resolve/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
5858
use syntax::ext::base::SyntaxExtension;
5959
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
6060
use syntax::ext::base::MacroKind;
61-
use syntax::feature_gate::{emit_feature_err, GateIssue};
6261
use syntax::symbol::{Symbol, keywords};
6362
use syntax::util::lev_distance::find_best_match_for_name;
6463

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

21162115
if !module.no_implicit_prelude {
21172116
if ns == TypeNS {
2118-
if let Some(binding) = self.extern_prelude_get(ident, !record_used, false) {
2117+
if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
21192118
return Some(LexicalScopeBinding::Item(binding));
21202119
}
21212120
}
@@ -5022,21 +5021,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
50225021
self.name_already_seen.insert(name, span);
50235022
}
50245023

5025-
fn extern_prelude_get(&mut self, ident: Ident, speculative: bool, skip_feature_gate: bool)
5024+
fn extern_prelude_get(&mut self, ident: Ident, speculative: bool)
50265025
-> Option<&'a NameBinding<'a>> {
50275026
if ident.is_path_segment_keyword() {
50285027
// Make sure `self`, `super` etc produce an error when passed to here.
50295028
return None;
50305029
}
50315030
self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| {
50325031
if let Some(binding) = entry.extern_crate_item {
5033-
if !speculative && !skip_feature_gate && entry.introduced_by_item &&
5034-
!self.session.features_untracked().extern_crate_item_prelude {
5035-
emit_feature_err(&self.session.parse_sess, "extern_crate_item_prelude",
5036-
ident.span, GateIssue::Language,
5037-
"use of extern prelude names introduced \
5038-
with `extern crate` items is unstable");
5039-
}
50405032
Some(binding)
50415033
} else {
50425034
let crate_id = if !speculative {

src/librustc_resolve/macros.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
738738
}
739739
WhereToResolve::ExternPrelude => {
740740
if use_prelude {
741-
match self.extern_prelude_get(ident, !record_used,
742-
innermost_result.is_some()) {
741+
match self.extern_prelude_get(ident, !record_used) {
743742
Some(binding) => Ok((binding, Flags::PRELUDE)),
744743
None => Err(Determinacy::determined(
745744
self.graph_root.unresolved_invocations.borrow().is_empty()
@@ -906,7 +905,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
906905
// but its `Def` should coincide with a crate passed with `--extern`
907906
// (otherwise there would be ambiguity) and we can skip feature error in this case.
908907
if ns != TypeNS || !use_prelude ||
909-
self.extern_prelude_get(ident, true, false).is_none() {
908+
self.extern_prelude_get(ident, true).is_none() {
910909
let msg = "imports can only refer to extern crate names \
911910
passed with `--extern` on stable channel";
912911
let mut err = feature_err(&self.session.parse_sess, "uniform_paths",

src/librustc_resolve/resolve_imports.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
166166
assert!(!restricted_shadowing);
167167
match uniform_root_kind {
168168
UniformRootKind::ExternPrelude => {
169-
return if let Some(binding) =
170-
self.extern_prelude_get(ident, !record_used, false) {
169+
return if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
171170
Ok(binding)
172171
} else if !self.graph_root.unresolved_invocations.borrow().is_empty() {
173172
// Macro-expanded `extern crate` items can add names to extern prelude.

src/libsyntax/feature_gate.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,6 @@ declare_features! (
499499
// Allows `const _: TYPE = VALUE`
500500
(active, underscore_const_names, "1.31.0", Some(54912), None),
501501

502-
// `extern crate foo as bar;` puts `bar` into extern prelude.
503-
(active, extern_crate_item_prelude, "1.31.0", Some(55599), None),
504-
505502
// `reason = ` in lint attributes and `expect` lint attribute
506503
(active, lint_reasons, "1.31.0", Some(54503), None),
507504
);
@@ -691,6 +688,8 @@ declare_features! (
691688
// impl<I:Iterator> Iterator for &mut Iterator
692689
// impl Debug for Foo<'_>
693690
(accepted, impl_header_lifetime_elision, "1.31.0", Some(15872), None),
691+
// `extern crate foo as bar;` puts `bar` into extern prelude.
692+
(accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None),
694693
);
695694

696695
// If you change this, please modify src/doc/unstable-book as well. You must

src/test/ui-fulldeps/proc-macro/extern-prelude-extern-crate-proc-macro.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// compile-pass
22
// edition:2018
33

4-
#![feature(extern_crate_item_prelude)]
5-
64
extern crate proc_macro;
75
use proc_macro::TokenStream; // OK
86

src/test/ui/feature-gates/feature-gate-extern_crate_item_prelude.rs

-46
This file was deleted.

src/test/ui/feature-gates/feature-gate-extern_crate_item_prelude.stderr

-75
This file was deleted.

src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// compile-pass
22
// edition:2018
33

4-
#![feature(extern_crate_item_prelude)]
5-
64
macro_rules! define_iso { () => {
75
extern crate std as iso;
86
}}

src/test/ui/imports/extern-prelude-extern-crate-cfg.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// compile-pass
22
// compile-flags:--cfg my_feature
33

4-
#![feature(extern_crate_item_prelude)]
54
#![no_std]
65

76
#[cfg(my_feature)]

src/test/ui/imports/extern-prelude-extern-crate-pass.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// compile-pass
22
// aux-build:two_macros.rs
33

4-
#![feature(extern_crate_item_prelude)]
5-
64
extern crate two_macros;
75

86
mod m {

src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// aux-build:two_macros.rs
22

3-
#![feature(extern_crate_item_prelude)]
4-
53
macro_rules! define_vec {
64
() => {
75
extern crate std as Vec;
@@ -16,4 +14,13 @@ mod m {
1614
}
1715
}
1816

17+
macro_rules! define_other_core {
18+
() => {
19+
extern crate std as core;
20+
//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
21+
}
22+
}
23+
24+
define_other_core!();
25+
1926
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
2+
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:19:9
3+
|
4+
LL | extern crate std as core;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | define_other_core!();
8+
| --------------------- in this macro invocation
9+
110
error[E0659]: `Vec` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
2-
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:15:9
11+
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:13:9
312
|
413
LL | Vec::panic!(); //~ ERROR `Vec` is ambiguous
514
| ^^^ ambiguous name
615
|
716
= note: `Vec` could refer to a struct from prelude
817
note: `Vec` could also refer to the extern crate imported here
9-
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:7:9
18+
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:5:9
1019
|
1120
LL | extern crate std as Vec;
1221
| ^^^^^^^^^^^^^^^^^^^^^^^^
1322
...
1423
LL | define_vec!();
1524
| -------------- in this macro invocation
1625

17-
error: aborting due to previous error
26+
error: aborting due to 2 previous errors
1827

1928
For more information about this error, try `rustc --explain E0659`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-pass
2+
// aux-build:two_macros.rs
3+
4+
extern crate two_macros as core;
5+
6+
mod m {
7+
fn check() {
8+
core::m!(); // OK
9+
}
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)