Skip to content

Commit feb48f3

Browse files
authored
Rollup merge of #57572 - Centril:unaccept-extern-in-path, r=petrochenkov
Unaccept `extern_in_paths` Based on completed fcp-close in #55600, this removes `extern_in_path` (e.g. `extern::foo::bar`) from the language. The changes are primarily reversing 32db83b. Closes #55600 r? @petrochenkov
2 parents 2e10944 + c4f6ef2 commit feb48f3

30 files changed

+62
-233
lines changed

src/doc/unstable-book/src/language-features/extern-in-paths.md

-40
This file was deleted.

src/librustc/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub enum ExternCrateSource {
140140
),
141141
// Crate is loaded by `use`.
142142
Use,
143-
/// Crate is implicitly loaded by an absolute or an `extern::` path.
143+
/// Crate is implicitly loaded by an absolute path.
144144
Path,
145145
}
146146

src/librustc_resolve/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ enum ModuleOrUniformRoot<'a> {
10151015
CrateRootAndExternPrelude,
10161016

10171017
/// Virtual module that denotes resolution in extern prelude.
1018-
/// Used for paths starting with `::` on 2018 edition or `extern::`.
1018+
/// Used for paths starting with `::` on 2018 edition.
10191019
ExternPrelude,
10201020

10211021
/// Virtual module that denotes resolution in current scope.
@@ -3836,8 +3836,7 @@ impl<'a> Resolver<'a> {
38363836
self.resolve_self(&mut ctxt, self.current_module)));
38373837
continue;
38383838
}
3839-
if name == keywords::Extern.name() ||
3840-
name == keywords::PathRoot.name() && ident.span.rust_2018() {
3839+
if name == keywords::PathRoot.name() && ident.span.rust_2018() {
38413840
module = Some(ModuleOrUniformRoot::ExternPrelude);
38423841
continue;
38433842
}
@@ -4004,8 +4003,8 @@ impl<'a> Resolver<'a> {
40044003
};
40054004

40064005
// We're only interested in `use` paths which should start with
4007-
// `{{root}}` or `extern` currently.
4008-
if first_name != keywords::Extern.name() && first_name != keywords::PathRoot.name() {
4006+
// `{{root}}` currently.
4007+
if first_name != keywords::PathRoot.name() {
40094008
return
40104009
}
40114010

src/libsyntax/feature_gate.rs

+5-24
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use syntax_pos::{Span, DUMMY_SP};
2525
use errors::{DiagnosticBuilder, Handler};
2626
use visit::{self, FnKind, Visitor};
2727
use parse::ParseSess;
28-
use symbol::{keywords, Symbol};
28+
use symbol::Symbol;
2929

30-
use std::{env};
30+
use std::env;
3131

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

375-
// `extern` in paths
376-
(active, extern_in_paths, "1.23.0", Some(55600), None),
377-
378375
// Infer static outlives requirements (RFC 2093).
379376
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
380377

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

508508
declare_features! (
@@ -1827,25 +1827,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18271827
visit::walk_impl_item(self, ii);
18281828
}
18291829

1830-
fn visit_path(&mut self, path: &'a ast::Path, _id: NodeId) {
1831-
for segment in &path.segments {
1832-
// Identifiers we are going to check could come from a legacy macro (e.g., `#[test]`).
1833-
// For such macros identifiers must have empty context, because this context is
1834-
// used during name resolution and produced names must be unhygienic for compatibility.
1835-
// On the other hand, we need the actual non-empty context for feature gate checking
1836-
// because it's hygienic even for legacy macros. As previously stated, such context
1837-
// cannot be kept in identifiers, so it's kept in paths instead and we take it from
1838-
// there while keeping location info from the ident span.
1839-
let span = segment.ident.span.with_ctxt(path.span.ctxt());
1840-
if segment.ident.name == keywords::Extern.name() {
1841-
gate_feature_post!(&self, extern_in_paths, span,
1842-
"`extern` in paths is experimental");
1843-
}
1844-
}
1845-
1846-
visit::walk_path(self, path);
1847-
}
1848-
18491830
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
18501831
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node {
18511832
gate_feature_post!(&self, crate_visibility_modifier, vis.span,

src/libsyntax/parse/parser.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ impl<'a> Parser<'a> {
13021302
fn token_is_bare_fn_keyword(&mut self) -> bool {
13031303
self.check_keyword(keywords::Fn) ||
13041304
self.check_keyword(keywords::Unsafe) ||
1305-
self.check_keyword(keywords::Extern) && self.is_extern_non_path()
1305+
self.check_keyword(keywords::Extern)
13061306
}
13071307

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

4620-
fn is_extern_non_path(&self) -> bool {
4621-
self.token.is_keyword(keywords::Extern) && self.look_ahead(1, |t| t != &token::ModSep)
4622-
}
4623-
46244620
fn is_existential_type_decl(&self) -> bool {
46254621
self.token.is_keyword(keywords::Existential) &&
46264622
self.look_ahead(1, |t| t.is_keyword(keywords::Type))
@@ -4724,12 +4720,10 @@ impl<'a> Parser<'a> {
47244720
// like a path (1 token), but it fact not a path.
47254721
// `union::b::c` - path, `union U { ... }` - not a path.
47264722
// `crate::b::c` - path, `crate struct S;` - not a path.
4727-
// `extern::b::c` - path, `extern crate c;` - not a path.
47284723
} else if self.token.is_path_start() &&
47294724
!self.token.is_qpath_start() &&
47304725
!self.is_union_item() &&
47314726
!self.is_crate_vis() &&
4732-
!self.is_extern_non_path() &&
47334727
!self.is_existential_type_decl() &&
47344728
!self.is_auto_trait_item() {
47354729
let pth = self.parse_path(PathStyle::Expr)?;
@@ -7198,8 +7192,7 @@ impl<'a> Parser<'a> {
71987192
return Ok(Some(item));
71997193
}
72007194

7201-
if self.check_keyword(keywords::Extern) && self.is_extern_non_path() {
7202-
self.bump(); // `extern`
7195+
if self.eat_keyword(keywords::Extern) {
72037196
if self.eat_keyword(keywords::Crate) {
72047197
return Ok(Some(self.parse_item_extern_crate(lo, visibility, attrs)?));
72057198
}
@@ -7708,7 +7701,7 @@ impl<'a> Parser<'a> {
77087701
fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>,
77097702
at_end: &mut bool) -> PResult<'a, Option<Mac>>
77107703
{
7711-
if self.token.is_path_start() && !self.is_extern_non_path() {
7704+
if self.token.is_path_start() {
77127705
let prev_span = self.prev_span;
77137706
let lo = self.span;
77147707
let pth = self.parse_path(PathStyle::Mod)?;

src/libsyntax_pos/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ impl Ident {
478478
self.name == keywords::Super.name() ||
479479
self.name == keywords::SelfLower.name() ||
480480
self.name == keywords::SelfUpper.name() ||
481-
self.name == keywords::Extern.name() ||
482481
self.name == keywords::Crate.name() ||
483482
self.name == keywords::PathRoot.name() ||
484483
self.name == keywords::DollarCrate.name()
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
-include ../tools.mk
22

3-
all: extern_absolute_paths.rs extern_in_paths.rs krate2
3+
all: extern_absolute_paths.rs krate2
44
$(RUSTC) extern_absolute_paths.rs -Zsave-analysis --edition=2018 \
55
-Z unstable-options --extern krate2
66
cat $(TMPDIR)/save-analysis/extern_absolute_paths.json | "$(PYTHON)" validate_json.py
7-
$(RUSTC) extern_in_paths.rs -Zsave-analysis --edition=2018 \
8-
-Z unstable-options --extern krate2
9-
cat $(TMPDIR)/save-analysis/extern_in_paths.json | "$(PYTHON)" validate_json.py
107

118
krate2: krate2.rs
129
$(RUSTC) $<

src/test/run-make-fulldeps/save-analysis-rfc2126/extern_in_paths.rs

-7
This file was deleted.

src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/extern.rs

-28
This file was deleted.

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

-5
This file was deleted.

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

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let s = extern::foo::Bar; //~ ERROR expected expression, found keyword `extern`
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected expression, found keyword `extern`
2+
--> $DIR/keyword-extern-as-identifier-expr.rs:2:13
3+
|
4+
LL | let s = extern::foo::Bar; //~ ERROR expected expression, found keyword `extern`
5+
| ^^^^^^ expected expression
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let extern = 0; //~ ERROR expected pattern, found keyword `extern`
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected pattern, found keyword `extern`
2+
--> $DIR/keyword-extern-as-identifier-pat.rs:2:9
3+
|
4+
LL | let extern = 0; //~ ERROR expected pattern, found keyword `extern`
5+
| ^^^^^^ expected pattern
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type A = extern::foo::bar; //~ ERROR expected `fn`, found `::`
2+
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected `fn`, found `::`
2+
--> $DIR/keyword-extern-as-identifier-type.rs:1:16
3+
|
4+
LL | type A = extern::foo::bar; //~ ERROR expected `fn`, found `::`
5+
| ^^ expected `fn` here
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use extern::foo; //~ ERROR expected identifier, found keyword `extern`
2+
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: expected identifier, found keyword `extern`
2+
--> $DIR/keyword-extern-as-identifier-use.rs:1:5
3+
|
4+
LL | use extern::foo; //~ ERROR expected identifier, found keyword `extern`
5+
| ^^^^^^ expected identifier, found keyword
6+
help: you can escape reserved keywords to use them as identifiers
7+
|
8+
LL | use r#extern::foo; //~ ERROR expected identifier, found keyword `extern`
9+
| ^^^^^^^^
10+
11+
error: aborting due to previous error
12+

src/test/ui/keyword/keyword-extern-as-identifier.rs

-5
This file was deleted.

src/test/ui/keyword/keyword-extern-as-identifier.stderr

-9
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/auxiliary/xcrate.rs

-5
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/non-existent-1.rs

-5
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/non-existent-1.stderr

-9
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/non-existent-2.rs

-6
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/non-existent-2.stderr

-9
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/non-existent-3.rs

-5
This file was deleted.

src/test/ui/rfc-2126-extern-in-paths/non-existent-3.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)