提交 fa2c2463 编写于 作者: E Eduard-Mihai Burtescu

Stabilize crate_in_paths, extern_absolute_paths and extern_prelude on all editions.

上级 c97b60ff
# `crate_in_paths`
The tracking issue for this feature is: [#44660]
[#44660]: https://github.com/rust-lang/rust/issues/44660
------------------------
The `crate_in_paths` feature allows to explicitly refer to the crate root in absolute paths
using keyword `crate`.
This feature is required in `feature(extern_absolute_paths)` mode to refer to any absolute path
in the local crate (absolute paths refer to extern crates by default in that mode), but can be
used without `feature(extern_absolute_paths)` as well.
```rust
#![feature(crate_in_paths)]
// Imports, `::` is added implicitly
use crate::m::f;
use crate as root;
mod m {
pub fn f() -> u8 { 1 }
pub fn g() -> u8 { 2 }
pub fn h() -> u8 { 3 }
// OK, visibilities implicitly add starting `::` as well, like imports
pub(in crate::m) struct S;
}
mod n
{
use crate::m::f;
use crate as root;
pub fn check() {
assert_eq!(f(), 1);
assert_eq!(crate::m::g(), 2);
assert_eq!(root::m::h(), 3);
}
}
fn main() {
assert_eq!(f(), 1);
assert_eq!(crate::m::g(), 2);
assert_eq!(root::m::h(), 3);
n::check();
}
```
# `extern_absolute_paths`
The tracking issue for this feature is: [#44660]
[#44660]: https://github.com/rust-lang/rust/issues/44660
------------------------
The `extern_absolute_paths` feature enables mode allowing to refer to names from other crates
"inline", without introducing `extern crate` items, using absolute paths like `::my_crate::a::b`.
`::my_crate::a::b` will resolve to path `a::b` in crate `my_crate`.
`feature(crate_in_paths)` can be used in `feature(extern_absolute_paths)` mode for referring
to absolute paths in the local crate (`crate::a::b`).
`feature(extern_in_paths)` provides the same effect by using keyword `extern` to refer to
paths from other crates (`extern::my_crate::a::b`).
```rust,ignore
#![feature(extern_absolute_paths)]
// Suppose we have a dependency crate `xcrate` available through `Cargo.toml`, or `--extern`
// options, or standard Rust distribution, or some other means.
use xcrate::Z;
fn f() {
use xcrate;
use xcrate as ycrate;
let s = xcrate::S;
assert_eq!(format!("{:?}", s), "S");
let z = ycrate::Z;
assert_eq!(format!("{:?}", z), "Z");
}
fn main() {
let s = ::xcrate::S;
assert_eq!(format!("{:?}", s), "S");
let z = Z;
assert_eq!(format!("{:?}", z), "Z");
}
```
......@@ -73,7 +73,7 @@
#![cfg_attr(not(stage0), feature(impl_header_lifetime_elision))]
#![feature(in_band_lifetimes)]
#![feature(macro_at_most_once_rep)]
#![feature(crate_in_paths)]
#![cfg_attr(stage0, feature(crate_in_paths))]
#![feature(crate_visibility_modifier)]
#![recursion_limit="512"]
......
......@@ -65,7 +65,6 @@
use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path};
use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind};
use syntax::feature_gate::{feature_err, GateIssue};
use syntax::ptr::P;
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
......@@ -1466,9 +1465,6 @@ pub struct Resolver<'a, 'b: 'a> {
current_type_ascription: Vec<Span>,
injected_crate: Option<Module<'a>>,
/// Only supposed to be used by rustdoc, otherwise should be false.
pub ignore_extern_prelude_feature: bool,
}
/// Nothing really interesting here, it just provides memory for the rest of the crate.
......@@ -1766,7 +1762,6 @@ pub fn new(session: &'a Session,
unused_macros: FxHashSet(),
current_type_ascription: Vec::new(),
injected_crate: None,
ignore_extern_prelude_feature: false,
}
}
......@@ -1969,13 +1964,6 @@ fn resolve_ident_in_lexical_scope(&mut self,
if !module.no_implicit_prelude {
// `record_used` means that we don't try to load crates during speculative resolution
if record_used && ns == TypeNS && self.extern_prelude.contains(&ident.name) {
if !self.session.features_untracked().extern_prelude &&
!self.ignore_extern_prelude_feature {
feature_err(&self.session.parse_sess, "extern_prelude",
ident.span, GateIssue::Language,
"access to extern crates through prelude is experimental").emit();
}
let crate_id = self.crate_loader.process_path_extern(ident.name, ident.span);
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
self.populate_module_if_necessary(&crate_root);
......@@ -3576,7 +3564,6 @@ fn resolve_path_with_parent_scope(
}
if name == keywords::Extern.name() ||
name == keywords::CrateRoot.name() &&
self.session.features_untracked().extern_absolute_paths &&
self.session.rust_2018() {
module = Some(ModuleOrUniformRoot::UniformRoot(name));
continue;
......@@ -3715,12 +3702,6 @@ fn lint_if_path_starts_with_module(
return
}
// In the 2015 edition there's no use in emitting lints unless the
// crate's already enabled the feature that we're going to suggest
if !self.session.features_untracked().crate_in_paths {
return
}
let (diag_id, diag_span) = match crate_lint {
CrateLint::No => return,
CrateLint::SimplePath(id) => (id, path_span),
......@@ -4417,7 +4398,7 @@ fn lookup_import_candidates<FilterFn>(&mut self,
)
);
if self.session.features_untracked().extern_prelude {
if self.session.rust_2018() {
let extern_prelude_names = self.extern_prelude.clone();
for &name in extern_prelude_names.iter() {
let ident = Ident::with_empty_ctxt(name);
......
......@@ -682,14 +682,6 @@ enum WhereToResolve<'a> {
}
WhereToResolve::ExternPrelude => {
if use_prelude && self.extern_prelude.contains(&ident.name) {
if !self.session.features_untracked().extern_prelude &&
!self.ignore_extern_prelude_feature {
feature_err(&self.session.parse_sess, "extern_prelude",
ident.span, GateIssue::Language,
"access to extern crates through prelude is experimental")
.emit();
}
let crate_id =
self.crate_loader.process_path_extern(ident.name, ident.span);
let crate_root =
......
......@@ -11,9 +11,9 @@
//! New recursive solver modeled on Chalk's recursive solver. Most of
//! the guts are broken up into modules; see the comments in those modules.
#![feature(crate_in_paths)]
#![cfg_attr(stage0, feature(crate_in_paths))]
#![feature(crate_visibility_modifier)]
#![feature(extern_prelude)]
#![cfg_attr(stage0, feature(extern_prelude))]
#![feature(in_band_lifetimes)]
#![cfg_attr(not(stage0), feature(nll))]
......
......@@ -455,12 +455,10 @@ pub fn run_core(search_paths: SearchPaths,
|_| Ok(()));
let driver::InnerExpansionResult {
mut hir_forest,
mut resolver,
resolver,
..
} = abort_on_err(result, &sess);
resolver.ignore_extern_prelude_feature = true;
// We need to hold on to the complete resolver, so we clone everything
// for the analysis passes to use. Suboptimal, but necessary in the
// current architecture.
......
......@@ -394,18 +394,12 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// Allows trait methods with arbitrary self types
(active, arbitrary_self_types, "1.23.0", Some(44874), None),
// `crate` in paths
(active, crate_in_paths, "1.23.0", Some(45477), Some(Edition::Edition2018)),
// In-band lifetime bindings (e.g. `fn foo(x: &'a u8) -> &'a u8`)
(active, in_band_lifetimes, "1.23.0", Some(44524), None),
// Generic associated types (RFC 1598)
(active, generic_associated_types, "1.23.0", Some(44265), None),
// Resolve absolute paths as paths from other crates
(active, extern_absolute_paths, "1.24.0", Some(44660), Some(Edition::Edition2018)),
// `extern` in paths
(active, extern_in_paths, "1.23.0", Some(44660), None),
......@@ -455,9 +449,6 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// #[doc(alias = "...")]
(active, doc_alias, "1.27.0", Some(50146), None),
// Access to crate names passed via `--extern` through prelude
(active, extern_prelude, "1.27.0", Some(44660), Some(Edition::Edition2018)),
// Scoped lints
(active, tool_lints, "1.28.0", Some(44690), None),
......@@ -683,7 +674,12 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
(accepted, panic_handler, "1.30.0", Some(44489), None),
// Used to preserve symbols (see llvm.used)
(accepted, used, "1.30.0", Some(40289), None),
// `crate` in paths
(accepted, crate_in_paths, "1.30.0", Some(45477), None),
// Resolve absolute paths as paths from other crates
(accepted, extern_absolute_paths, "1.30.0", Some(44660), None),
// Access to crate names passed via `--extern` through prelude
(accepted, extern_prelude, "1.30.0", Some(44660), None),
);
// If you change this, please modify src/doc/unstable-book as well. You must
......@@ -1892,10 +1888,7 @@ fn visit_path(&mut self, path: &'a ast::Path, _id: NodeId) {
// cannot be kept in identifiers, so it's kept in paths instead and we take it from
// there while keeping location info from the ident span.
let span = segment.ident.span.with_ctxt(path.span.ctxt());
if segment.ident.name == keywords::Crate.name() {
gate_feature_post!(&self, crate_in_paths, span,
"`crate` in paths is experimental");
} else if segment.ident.name == keywords::Extern.name() {
if segment.ident.name == keywords::Extern.name() {
gate_feature_post!(&self, extern_in_paths, span,
"`extern` in paths is experimental");
}
......
......@@ -7,6 +7,5 @@ all:
$(RUSTC) basic.rs --extern ep_lib=$(TMPDIR)/libep_lib.rlib
$(RUSTC) shadow-mod.rs --extern ep_lib=$(TMPDIR)/libep_lib.rlib
$(RUSTC) shadow-prelude.rs --extern Vec=$(TMPDIR)/libep_vec.rlib
$(RUSTC) feature-gate.rs --extern ep_lib=$(TMPDIR)/libep_lib.rlib 2>&1 | $(CGREP) "access to extern crates through prelude is experimental"
$(RUSTC) relative-only.rs --extern ep_lib=$(TMPDIR)/libep_lib.rlib 2>&1 | $(CGREP) "unresolved import"
$(RUSTC) relative-only.rs --extern ep_lib=$(TMPDIR)/libep_lib.rlib 2>&1 | $(CGREP) "failed to resolve"
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let s = ep_lib::S; // Feature error
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S;
fn main() {
let _ = crate::S; //~ ERROR `crate` in paths is experimental
}
error[E0658]: `crate` in paths is experimental (see issue #45477)
--> $DIR/feature-gate-crate_in_paths.rs:14:13
|
LL | let _ = crate::S; //~ ERROR `crate` in paths is experimental
| ^^^^^
|
= help: add #![feature(crate_in_paths)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.
warning: the feature `crate_in_paths` has been stable since 1.30.0 and no longer requires an attribute to enable
--> $DIR/dollar-crate-modern.rs:16:24
|
LL | #![feature(decl_macro, crate_in_paths)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
warning: the feature `extern_prelude` has been stable since 1.30.0 and no longer requires an attribute to enable
--> $DIR/macro-path-prelude-pass.rs:13:12
|
LL | #![feature(extern_prelude)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
warning: the feature `extern_prelude` has been stable since 1.30.0 and no longer requires an attribute to enable
--> $DIR/extern-prelude-core.rs:12:12
|
LL | #![feature(extern_prelude, lang_items, start, alloc)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
warning: the feature `extern_prelude` has been stable since 1.30.0 and no longer requires an attribute to enable
--> $DIR/extern-prelude-std.rs:12:12
|
LL | #![feature(extern_prelude)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
warning: the feature `crate_in_paths` has been stable since 1.30.0 and no longer requires an attribute to enable
--> $DIR/crate-path-absolute.rs:12:12
|
LL | #![feature(crate_in_paths)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
warning: the feature `crate_in_paths` has been stable since 1.30.0 and no longer requires an attribute to enable
--> $DIR/crate-path-visibility-ambiguity.rs:12:12
|
LL | #![feature(crate_in_paths)]
| ^^^^^^^^^^^^^^
|
= note: #[warn(stable_features)] on by default
Subproject commit b1e1d388ea09ecc27515345b180dd02263b087df
Subproject commit de314a8b2d45bce4958fc23939c5e4286e31621c
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册