Skip to content

Commit

Permalink
Rollup merge of rust-lang#57407 - mehcode:stabilize-extern-crate-self…
Browse files Browse the repository at this point in the history
…, r=Centril

Stabilize extern_crate_self

Fixes rust-lang#56409
  • Loading branch information
Centril authored Jan 26, 2019
2 parents ccd428b + 09d073a commit 5e6c2f4
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 28 deletions.
6 changes: 1 addition & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::base::Determinacy::Undetermined;
use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
use syntax::feature_gate::{is_builtin_attr, emit_feature_err, GateIssue};
use syntax::feature_gate::is_builtin_attr;
use syntax::parse::token::{self, Token};
use syntax::std_inject::injected_crate_name;
use syntax::symbol::keywords;
Expand Down Expand Up @@ -356,10 +356,6 @@ impl<'a> Resolver<'a> {
.emit();
return;
} else if orig_name == Some(keywords::SelfLower.name()) {
if !self.session.features_untracked().extern_crate_self {
emit_feature_err(&self.session.parse_sess, "extern_crate_self", item.span,
GateIssue::Language, "`extern crate self` is unstable");
}
self.graph_root
} else {
let crate_id = self.crate_loader.process_extern_crate(item, &self.definitions);
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,6 @@ declare_features! (
// Adds `reason` and `expect` lint attributes.
(active, lint_reasons, "1.31.0", Some(54503), None),

// `extern crate self as foo;` puts local crate root into extern prelude under name `foo`.
(active, extern_crate_self, "1.31.0", Some(56409), None),

// Allows paths to enum variants on type aliases.
(active, type_alias_enum_variants, "1.31.0", Some(49683), None),

Expand Down Expand Up @@ -689,6 +686,8 @@ declare_features! (
(accepted, uniform_paths, "1.32.0", Some(53130), None),
// Allows `cfg(target_vendor = "...")`.
(accepted, cfg_target_vendor, "1.33.0", Some(29718), None),
// `extern crate self as foo;` puts local crate root into extern prelude under name `foo`.
(accepted, extern_crate_self, "1.34.0", Some(56409), None),
);

// If you change this, please modify `src/doc/unstable-book` as well. You must
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/feature-gates/feature-gate-extern_crate_self.rs

This file was deleted.

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(extern_crate_self)]

extern crate self; //~ ERROR `extern crate self;` requires renaming

#[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: `extern crate self;` requires renaming
--> $DIR/extern-crate-self-fail.rs:3:1
--> $DIR/extern-crate-self-fail.rs:1:1
|
LL | extern crate self; //~ ERROR `extern crate self;` requires renaming
| ^^^^^^^^^^^^^^^^^^ help: try: `extern crate self as name;`

error: `macro_use` is not supported on `extern crate self`
--> $DIR/extern-crate-self-fail.rs:5:1
--> $DIR/extern-crate-self-fail.rs:3:1
|
LL | #[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self`
| ^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-pass

// Test that a macro can correctly expand the alias
// in an `extern crate self as ALIAS` item.

fn the_answer() -> usize { 42 }

macro_rules! alias_self {
($alias:ident) => { extern crate self as $alias; }
}

alias_self!(the_alias);

fn main() {
assert_eq!(the_alias::the_answer(), 42);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// compile-pass

// Test that `extern crate self;` is accepted
// syntactically as an item for use in a macro.

macro_rules! accept_item { ($x:item) => {} }

accept_item! {
extern crate self;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-pass

// Test that a macro can correctly expand `self` in
// an `extern crate self as ALIAS` item.

fn the_answer() -> usize { 42 }

macro_rules! extern_something {
($alias:ident) => { extern crate $alias as the_alias; }
}

extern_something!(self);

fn main() {
assert_eq!(the_alias::the_answer(), 42);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// compile-pass

#![feature(extern_crate_self)]

extern crate self as foo;

struct S;
Expand Down

0 comments on commit 5e6c2f4

Please sign in to comment.