Skip to content

Commit

Permalink
Rollup merge of rust-lang#57572 - Centril:unaccept-extern-in-path, r=…
Browse files Browse the repository at this point in the history
…petrochenkov

Unaccept `extern_in_paths`

Based on completed fcp-close in rust-lang#55600, this removes `extern_in_path` (e.g. `extern::foo::bar`) from the language. The changes are primarily reversing rust-lang@32db83b.

Closes rust-lang#55600

r? @petrochenkov
  • Loading branch information
Centril committed Jan 14, 2019
2 parents 64c9015 + c4f6ef2 commit 9f52fbb
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 233 deletions.
40 changes: 0 additions & 40 deletions src/doc/unstable-book/src/language-features/extern-in-paths.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/librustc/middle/cstore.rs
Expand Up @@ -140,7 +140,7 @@ pub enum ExternCrateSource {
),
// Crate is loaded by `use`.
Use,
/// Crate is implicitly loaded by an absolute or an `extern::` path.
/// Crate is implicitly loaded by an absolute path.
Path,
}

Expand Down
9 changes: 4 additions & 5 deletions src/librustc_resolve/lib.rs
Expand Up @@ -1015,7 +1015,7 @@ enum ModuleOrUniformRoot<'a> {
CrateRootAndExternPrelude,

/// Virtual module that denotes resolution in extern prelude.
/// Used for paths starting with `::` on 2018 edition or `extern::`.
/// Used for paths starting with `::` on 2018 edition.
ExternPrelude,

/// Virtual module that denotes resolution in current scope.
Expand Down Expand Up @@ -3836,8 +3836,7 @@ impl<'a> Resolver<'a> {
self.resolve_self(&mut ctxt, self.current_module)));
continue;
}
if name == keywords::Extern.name() ||
name == keywords::PathRoot.name() && ident.span.rust_2018() {
if name == keywords::PathRoot.name() && ident.span.rust_2018() {
module = Some(ModuleOrUniformRoot::ExternPrelude);
continue;
}
Expand Down Expand Up @@ -4004,8 +4003,8 @@ impl<'a> Resolver<'a> {
};

// We're only interested in `use` paths which should start with
// `{{root}}` or `extern` currently.
if first_name != keywords::Extern.name() && first_name != keywords::PathRoot.name() {
// `{{root}}` currently.
if first_name != keywords::PathRoot.name() {
return
}

Expand Down
29 changes: 5 additions & 24 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -25,9 +25,9 @@ use syntax_pos::{Span, DUMMY_SP};
use errors::{DiagnosticBuilder, Handler};
use visit::{self, FnKind, Visitor};
use parse::ParseSess;
use symbol::{keywords, Symbol};
use symbol::Symbol;

use std::{env};
use std::env;

macro_rules! set {
($field: ident) => {{
Expand Down Expand Up @@ -372,9 +372,6 @@ declare_features! (
// Generic associated types (RFC 1598)
(active, generic_associated_types, "1.23.0", Some(44265), None),

// `extern` in paths
(active, extern_in_paths, "1.23.0", Some(55600), None),

// Infer static outlives requirements (RFC 2093).
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),

Expand Down Expand Up @@ -503,6 +500,9 @@ declare_features! (
// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`.
(removed, custom_derive, "1.0.0", Some(29644), None,
Some("subsumed by `#[proc_macro_derive]`")),
// Paths of the form: `extern::foo::bar`
(removed, extern_in_paths, "1.33.0", Some(55600), None,
Some("subsumed by `::foo::bar` paths")),
);

declare_features! (
Expand Down Expand Up @@ -1827,25 +1827,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_impl_item(self, ii);
}

fn visit_path(&mut self, path: &'a ast::Path, _id: NodeId) {
for segment in &path.segments {
// Identifiers we are going to check could come from a legacy macro (e.g., `#[test]`).
// For such macros identifiers must have empty context, because this context is
// used during name resolution and produced names must be unhygienic for compatibility.
// On the other hand, we need the actual non-empty context for feature gate checking
// because it's hygienic even for legacy macros. As previously stated, such context
// 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::Extern.name() {
gate_feature_post!(&self, extern_in_paths, span,
"`extern` in paths is experimental");
}
}

visit::walk_path(self, path);
}

fn visit_vis(&mut self, vis: &'a ast::Visibility) {
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node {
gate_feature_post!(&self, crate_visibility_modifier, vis.span,
Expand Down
13 changes: 3 additions & 10 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -1302,7 +1302,7 @@ impl<'a> Parser<'a> {
fn token_is_bare_fn_keyword(&mut self) -> bool {
self.check_keyword(keywords::Fn) ||
self.check_keyword(keywords::Unsafe) ||
self.check_keyword(keywords::Extern) && self.is_extern_non_path()
self.check_keyword(keywords::Extern)
}

/// parse a `TyKind::BareFn` type:
Expand Down Expand Up @@ -4617,10 +4617,6 @@ impl<'a> Parser<'a> {
self.token.is_keyword(keywords::Crate) && self.look_ahead(1, |t| t != &token::ModSep)
}

fn is_extern_non_path(&self) -> bool {
self.token.is_keyword(keywords::Extern) && self.look_ahead(1, |t| t != &token::ModSep)
}

fn is_existential_type_decl(&self) -> bool {
self.token.is_keyword(keywords::Existential) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Type))
Expand Down Expand Up @@ -4724,12 +4720,10 @@ impl<'a> Parser<'a> {
// like a path (1 token), but it fact not a path.
// `union::b::c` - path, `union U { ... }` - not a path.
// `crate::b::c` - path, `crate struct S;` - not a path.
// `extern::b::c` - path, `extern crate c;` - not a path.
} else if self.token.is_path_start() &&
!self.token.is_qpath_start() &&
!self.is_union_item() &&
!self.is_crate_vis() &&
!self.is_extern_non_path() &&
!self.is_existential_type_decl() &&
!self.is_auto_trait_item() {
let pth = self.parse_path(PathStyle::Expr)?;
Expand Down Expand Up @@ -7198,8 +7192,7 @@ impl<'a> Parser<'a> {
return Ok(Some(item));
}

if self.check_keyword(keywords::Extern) && self.is_extern_non_path() {
self.bump(); // `extern`
if self.eat_keyword(keywords::Extern) {
if self.eat_keyword(keywords::Crate) {
return Ok(Some(self.parse_item_extern_crate(lo, visibility, attrs)?));
}
Expand Down Expand Up @@ -7708,7 +7701,7 @@ impl<'a> Parser<'a> {
fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>,
at_end: &mut bool) -> PResult<'a, Option<Mac>>
{
if self.token.is_path_start() && !self.is_extern_non_path() {
if self.token.is_path_start() {
let prev_span = self.prev_span;
let lo = self.span;
let pth = self.parse_path(PathStyle::Mod)?;
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_pos/symbol.rs
Expand Up @@ -478,7 +478,6 @@ impl Ident {
self.name == keywords::Super.name() ||
self.name == keywords::SelfLower.name() ||
self.name == keywords::SelfUpper.name() ||
self.name == keywords::Extern.name() ||
self.name == keywords::Crate.name() ||
self.name == keywords::PathRoot.name() ||
self.name == keywords::DollarCrate.name()
Expand Down
5 changes: 1 addition & 4 deletions src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile
@@ -1,12 +1,9 @@
-include ../tools.mk

all: extern_absolute_paths.rs extern_in_paths.rs krate2
all: extern_absolute_paths.rs krate2
$(RUSTC) extern_absolute_paths.rs -Zsave-analysis --edition=2018 \
-Z unstable-options --extern krate2
cat $(TMPDIR)/save-analysis/extern_absolute_paths.json | "$(PYTHON)" validate_json.py
$(RUSTC) extern_in_paths.rs -Zsave-analysis --edition=2018 \
-Z unstable-options --extern krate2
cat $(TMPDIR)/save-analysis/extern_in_paths.json | "$(PYTHON)" validate_json.py

krate2: krate2.rs
$(RUSTC) $<

This file was deleted.

28 changes: 0 additions & 28 deletions src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/extern.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/ui/feature-gates/feature-gate-extern_in_paths.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/feature-gates/feature-gate-extern_in_paths.stderr

This file was deleted.

@@ -0,0 +1,3 @@
fn main() {
let s = extern::foo::Bar; //~ ERROR expected expression, found keyword `extern`
}
@@ -0,0 +1,8 @@
error: expected expression, found keyword `extern`
--> $DIR/keyword-extern-as-identifier-expr.rs:2:13
|
LL | let s = extern::foo::Bar; //~ ERROR expected expression, found keyword `extern`
| ^^^^^^ expected expression

error: aborting due to previous error

@@ -0,0 +1,3 @@
fn main() {
let extern = 0; //~ ERROR expected pattern, found keyword `extern`
}
@@ -0,0 +1,8 @@
error: expected pattern, found keyword `extern`
--> $DIR/keyword-extern-as-identifier-pat.rs:2:9
|
LL | let extern = 0; //~ ERROR expected pattern, found keyword `extern`
| ^^^^^^ expected pattern

error: aborting due to previous error

@@ -0,0 +1,3 @@
type A = extern::foo::bar; //~ ERROR expected `fn`, found `::`

fn main() {}
@@ -0,0 +1,8 @@
error: expected `fn`, found `::`
--> $DIR/keyword-extern-as-identifier-type.rs:1:16
|
LL | type A = extern::foo::bar; //~ ERROR expected `fn`, found `::`
| ^^ expected `fn` here

error: aborting due to previous error

@@ -0,0 +1,3 @@
use extern::foo; //~ ERROR expected identifier, found keyword `extern`

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/keyword/extern/keyword-extern-as-identifier-use.stderr
@@ -0,0 +1,12 @@
error: expected identifier, found keyword `extern`
--> $DIR/keyword-extern-as-identifier-use.rs:1:5
|
LL | use extern::foo; //~ ERROR expected identifier, found keyword `extern`
| ^^^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | use r#extern::foo; //~ ERROR expected identifier, found keyword `extern`
| ^^^^^^^^

error: aborting due to previous error

5 changes: 0 additions & 5 deletions src/test/ui/keyword/keyword-extern-as-identifier.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/keyword/keyword-extern-as-identifier.stderr

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/ui/rfc-2126-extern-in-paths/auxiliary/xcrate.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/ui/rfc-2126-extern-in-paths/non-existent-1.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/rfc-2126-extern-in-paths/non-existent-1.stderr

This file was deleted.

6 changes: 0 additions & 6 deletions src/test/ui/rfc-2126-extern-in-paths/non-existent-2.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/rfc-2126-extern-in-paths/non-existent-2.stderr

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/ui/rfc-2126-extern-in-paths/non-existent-3.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/rfc-2126-extern-in-paths/non-existent-3.stderr

This file was deleted.

0 comments on commit 9f52fbb

Please sign in to comment.