1
Fork 0

Feature gate extern prelude additions from extern crate items

Fix rustdoc and fulldeps tests
This commit is contained in:
Vadim Petrochenkov 2018-10-20 20:26:24 +03:00
parent 0f625ac48d
commit faefc83a7a
13 changed files with 143 additions and 9 deletions

View file

@ -58,6 +58,7 @@ use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
use syntax::ext::base::SyntaxExtension; use syntax::ext::base::SyntaxExtension;
use syntax::ext::base::Determinacy::{self, Determined, Undetermined}; use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
use syntax::ext::base::MacroKind; use syntax::ext::base::MacroKind;
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::symbol::{Symbol, keywords}; use syntax::symbol::{Symbol, keywords};
use syntax::util::lev_distance::find_best_match_for_name; use syntax::util::lev_distance::find_best_match_for_name;
@ -1971,7 +1972,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
if !module.no_implicit_prelude { if !module.no_implicit_prelude {
if ns == TypeNS { if ns == TypeNS {
if let Some(binding) = self.extern_prelude_get(ident, !record_used) { if let Some(binding) = self.extern_prelude_get(ident, !record_used, false) {
return Some(LexicalScopeBinding::Item(binding)); return Some(LexicalScopeBinding::Item(binding));
} }
} }
@ -4820,10 +4821,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
self.name_already_seen.insert(name, span); self.name_already_seen.insert(name, span);
} }
fn extern_prelude_get(&mut self, ident: Ident, speculative: bool) fn extern_prelude_get(&mut self, ident: Ident, speculative: bool, skip_feature_gate: bool)
-> Option<&'a NameBinding<'a>> { -> Option<&'a NameBinding<'a>> {
self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| { self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| {
if let Some(binding) = entry.extern_crate_item { 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) Some(binding)
} else { } else {
let crate_id = if !speculative { let crate_id = if !speculative {

View file

@ -693,7 +693,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
WhereToResolve::ExternPrelude => { WhereToResolve::ExternPrelude => {
let mut result = Err(Determinacy::Determined); let mut result = Err(Determinacy::Determined);
if use_prelude { if use_prelude {
if let Some(binding) = self.extern_prelude_get(ident, !record_used) { if let Some(binding) = self.extern_prelude_get(ident, !record_used,
innermost_result.is_some()) {
result = Ok((binding, Flags::PRELUDE, Flags::empty())); result = Ok((binding, Flags::PRELUDE, Flags::empty()));
} }
} }

View file

@ -222,7 +222,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
ns == TypeNS && ns == TypeNS &&
!ident.is_path_segment_keyword() !ident.is_path_segment_keyword()
{ {
if let Some(binding) = self.extern_prelude_get(ident, !record_used) { if let Some(binding) = self.extern_prelude_get(ident, !record_used, false) {
let module = self.get_module(binding.def().def_id()); let module = self.get_module(binding.def().def_id());
self.populate_module_if_necessary(module); self.populate_module_if_necessary(module);
return Ok(binding); return Ok(binding);
@ -742,7 +742,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
for ((span, _, ns), results) in uniform_paths_canaries { for ((span, _, ns), results) in uniform_paths_canaries {
let name = results.name; let name = results.name;
let external_crate = if ns == TypeNS { let external_crate = if ns == TypeNS {
self.extern_prelude_get(Ident::with_empty_ctxt(name), true) self.extern_prelude_get(Ident::with_empty_ctxt(name), true, false)
.map(|binding| binding.def()) .map(|binding| binding.def())
} else { } else {
None None
@ -1023,6 +1023,13 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
Some(this.dummy_binding); Some(this.dummy_binding);
} }
} }
if record_used && ns == TypeNS {
if let ModuleOrUniformRoot::UniformRoot(..) = module {
// Make sure single-segment import is resolved non-speculatively
// at least once to report the feature error.
this.extern_prelude_get(ident, false, false);
}
}
} }
}); });

View file

@ -476,7 +476,9 @@ pub fn run_core(search_paths: SearchPaths,
trait_map: resolver.trait_map.clone(), trait_map: resolver.trait_map.clone(),
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports.clone(), maybe_unused_trait_imports: resolver.maybe_unused_trait_imports.clone(),
maybe_unused_extern_crates: resolver.maybe_unused_extern_crates.clone(), maybe_unused_extern_crates: resolver.maybe_unused_extern_crates.clone(),
extern_prelude: resolver.extern_prelude.clone(), extern_prelude: resolver.extern_prelude.iter().map(|(ident, entry)| {
(ident.name, entry.introduced_by_item)
}).collect(),
}; };
let analysis = ty::CrateAnalysis { let analysis = ty::CrateAnalysis {
access_levels: Lrc::new(AccessLevels::default()), access_levels: Lrc::new(AccessLevels::default()),

View file

@ -501,6 +501,9 @@ declare_features! (
// Allows `const _: TYPE = VALUE` // Allows `const _: TYPE = VALUE`
(active, underscore_const_names, "1.31.0", Some(54912), None), (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(54658), None),
); );
declare_features! ( declare_features! (

View file

@ -1,6 +1,8 @@
// compile-pass // compile-pass
// edition:2018 // edition:2018
#![feature(extern_crate_item_prelude)]
extern crate proc_macro; extern crate proc_macro;
use proc_macro::TokenStream; // OK use proc_macro::TokenStream; // OK

View file

@ -20,7 +20,7 @@ error: cannot find derive macro `attr_proc_macra` in this scope
--> $DIR/resolve-error.rs:54:10 --> $DIR/resolve-error.rs:54:10
| |
LL | #[derive(attr_proc_macra)] LL | #[derive(attr_proc_macra)]
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro`
error: cannot find macro `FooWithLongNama!` in this scope error: cannot find macro `FooWithLongNama!` in this scope
--> $DIR/resolve-error.rs:59:5 --> $DIR/resolve-error.rs:59:5

View file

@ -0,0 +1,39 @@
// edition:2018
#![feature(alloc)]
extern crate alloc;
mod in_scope {
fn check() {
let v = alloc::vec![0];
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
type A = alloc::boxed::Box<u8>;
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
}
}
mod absolute {
fn check() {
let v = ::alloc::vec![0];
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
type A = ::alloc::boxed::Box<u8>;
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
}
}
mod import_in_scope {
use alloc;
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
use alloc::boxed;
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
}
mod import_absolute {
use ::alloc;
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
use ::alloc::boxed;
//~^ ERROR use of extern prelude names introduced with `extern crate` items is unstable
}
fn main() {}

View file

@ -0,0 +1,67 @@
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:26:9
|
LL | use alloc;
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:28:9
|
LL | use alloc::boxed;
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:33:11
|
LL | use ::alloc;
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:35:11
|
LL | use ::alloc::boxed;
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:9:17
|
LL | let v = alloc::vec![0];
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:11:18
|
LL | type A = alloc::boxed::Box<u8>;
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:18:19
|
LL | let v = ::alloc::vec![0];
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658)
--> $DIR/feature-gate-extern_crate_item_prelude.rs:20:20
|
LL | type A = ::alloc::boxed::Box<u8>;
| ^^^^^
|
= help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,6 +1,7 @@
// compile-pass // compile-pass
// compile-flags:--cfg my_feature // compile-flags:--cfg my_feature
#![feature(extern_crate_item_prelude)]
#![no_std] #![no_std]
#[cfg(my_feature)] #[cfg(my_feature)]

View file

@ -1,6 +1,8 @@
// compile-pass // compile-pass
// aux-build:two_macros.rs // aux-build:two_macros.rs
#![feature(extern_crate_item_prelude)]
extern crate two_macros; extern crate two_macros;
mod m { mod m {

View file

@ -1,5 +1,7 @@
// aux-build:two_macros.rs // aux-build:two_macros.rs
#![feature(extern_crate_item_prelude)]
macro_rules! define_vec { macro_rules! define_vec {
() => { () => {
extern crate std as Vec; extern crate std as Vec;

View file

@ -1,11 +1,11 @@
error[E0659]: `Vec` is ambiguous error[E0659]: `Vec` is ambiguous
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:13:9 --> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:15:9
| |
LL | Vec::panic!(); //~ ERROR `Vec` is ambiguous LL | Vec::panic!(); //~ ERROR `Vec` is ambiguous
| ^^^ ambiguous name | ^^^ ambiguous name
| |
note: `Vec` could refer to the name defined here note: `Vec` could refer to the name defined here
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:5:9 --> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:7:9
| |
LL | extern crate std as Vec; LL | extern crate std as Vec;
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^