-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #55275 - petrochenkov:extself, r=eddyb
experiment: Support aliasing local crate root in extern prelude This PR provides some minimally invasive solution for the 2018 edition migration issue described in #54647 and affecting proc macro crates. `extern crate NAME as RENAME;` now accepts `NAME`=`self` and interprets it as referring to the local crate. As with other `extern crate` items, `RENAME` in this case gets into extern prelude in accordance with #54658, thus resolving #54647. ```rust extern crate self as serde; // Adds local crate to extern prelude as `serde` ``` This solution doesn't introduce any new syntax and has minimal maintenance cost, so it can be easily deprecated if something better is found in the future. Closes #54647
- Loading branch information
Showing
9 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extern crate self as foo; //~ ERROR `extern crate self` is unstable | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/feature-gates/feature-gate-extern_crate_self.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0658]: `extern crate self` is unstable (see issue #54658) | ||
--> $DIR/feature-gate-extern_crate_self.rs:1:1 | ||
| | ||
LL | extern crate self as foo; //~ ERROR `extern crate self` is unstable | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(extern_crate_self)] to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![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` | ||
extern crate self as foo; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: `extern crate self;` requires renaming | ||
--> $DIR/extern-crate-self-fail.rs:3: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 | ||
| | ||
LL | #[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self` | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// compile-pass | ||
|
||
#![feature(extern_crate_self)] | ||
|
||
extern crate self as foo; | ||
|
||
struct S; | ||
|
||
mod m { | ||
fn check() { | ||
foo::S; // OK | ||
} | ||
} | ||
|
||
fn main() {} |