-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix imports of built-in macros (mostly) #61877
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,7 @@ symbols! { | |
box_patterns, | ||
box_syntax, | ||
braced_empty_structs, | ||
builtin_macro_imports, | ||
C, | ||
cdylib, | ||
cfg, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// edition:2018 | ||
// ignore-stage1 | ||
// aux-build:attr-plugin-test.rs | ||
|
||
#![feature(plugin)] | ||
#![plugin(attr_plugin_test)] | ||
|
||
use empty as full; //~ ERROR cannot import a built-in macro | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: cannot import a built-in macro | ||
--> $DIR/plugin-import.rs:8:5 | ||
| | ||
LL | use empty as full; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// edition:2018 | ||
|
||
#![feature(builtin_macro_imports)] | ||
|
||
// Tests that arbitrary crates (other than `core`, `std` and `meta`) | ||
// aren't allowed without `--extern`, even if they're in the sysroot. | ||
use alloc; //~ ERROR unresolved import `alloc` | ||
use test; //~ ERROR cannot import a built-in macro | ||
use test; // OK, imports the built-in attribute macro `test` | ||
use proc_macro; // OK, imports the built-in `proc_macro` attribute, but not the `proc_macro` crate. | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
error: cannot import a built-in macro | ||
--> $DIR/not-whitelisted.rs:6:5 | ||
| | ||
LL | use test; | ||
| ^^^^ | ||
|
||
error[E0432]: unresolved import `alloc` | ||
--> $DIR/not-whitelisted.rs:5:5 | ||
--> $DIR/not-whitelisted.rs:7:5 | ||
| | ||
LL | use alloc; | ||
| ^^^^^ no `alloc` external crate | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0432`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// edition:2018 | ||
|
||
#![feature(builtin_macro_imports)] | ||
|
||
pub use concat as my_concat; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// edition:2018 | ||
// aux-build:export-builtin-macros.rs | ||
|
||
#![feature(builtin_macro_imports)] | ||
|
||
extern crate export_builtin_macros; | ||
|
||
mod local { | ||
pub use concat as my_concat; | ||
} | ||
|
||
use export_builtin_macros::*; | ||
use local::*; | ||
|
||
fn main() { | ||
// `concat`s imported from different crates should ideally have the same `DefId` | ||
// and not conflict with each other, but that's not the case right now. | ||
my_concat!("x"); //~ ERROR `my_concat` is ambiguous | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0659]: `my_concat` is ambiguous (glob import vs glob import in the same module) | ||
--> $DIR/import-builtin-macros-bug.rs:18:5 | ||
| | ||
LL | my_concat!("x"); | ||
| ^^^^^^^^^ ambiguous name | ||
| | ||
note: `my_concat` could refer to the macro imported here | ||
--> $DIR/import-builtin-macros-bug.rs:12:5 | ||
| | ||
LL | use export_builtin_macros::*; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: consider adding an explicit import of `my_concat` to disambiguate | ||
note: `my_concat` could also refer to the macro imported here | ||
--> $DIR/import-builtin-macros-bug.rs:13:5 | ||
| | ||
LL | use local::*; | ||
| ^^^^^^^^ | ||
= help: consider adding an explicit import of `my_concat` to disambiguate | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0659`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// FIXME: Individual imports of built-in macros are not stability checked right now, | ||
// so the whole feature is gated instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what this comment means. Can you illustrate the difference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see; I read There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahaha, |
||
|
||
// edition:2018 | ||
// gate-test-builtin_macro_imports | ||
|
||
use concat as stable; //~ ERROR imports of built-in macros are unstable | ||
use concat_idents as unstable; //~ ERROR imports of built-in macros are unstable | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0658]: imports of built-in macros are unstable | ||
--> $DIR/import-builtin-macros-stability.rs:7:5 | ||
| | ||
LL | use concat as stable; | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/61875 | ||
= help: add #![feature(builtin_macro_imports)] to the crate attributes to enable | ||
|
||
error[E0658]: imports of built-in macros are unstable | ||
--> $DIR/import-builtin-macros-stability.rs:8:5 | ||
| | ||
LL | use concat_idents as unstable; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/61875 | ||
= help: add #![feature(builtin_macro_imports)] to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// compile-pass | ||
// edition:2018 | ||
// aux-build:export-builtin-macros.rs | ||
|
||
#![feature(builtin_macro_imports)] | ||
|
||
extern crate export_builtin_macros; | ||
|
||
mod local { | ||
pub use concat as my_concat; | ||
} | ||
|
||
mod xcrate { | ||
pub use export_builtin_macros::my_concat; | ||
} | ||
|
||
fn main() { | ||
assert_eq!(local::my_concat!("a", "b"), "ab"); | ||
assert_eq!(xcrate::my_concat!("a", "b"), "ab"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
// edition:2018 | ||
|
||
// Built-in macro | ||
use env as env_imported; //~ ERROR cannot import a built-in macro | ||
|
||
// Tool attribute | ||
use rustfmt::skip as imported_rustfmt_skip; //~ ERROR unresolved import `rustfmt` | ||
|
||
fn main() { | ||
env_imported!("PATH"); | ||
} | ||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
error: cannot import a built-in macro | ||
--> $DIR/prelude-fail.rs:4:5 | ||
| | ||
LL | use env as env_imported; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0432]: unresolved import `rustfmt` | ||
--> $DIR/prelude-fail.rs:7:5 | ||
--> $DIR/prelude-fail.rs:4:5 | ||
| | ||
LL | use rustfmt::skip as imported_rustfmt_skip; | ||
| ^^^^^^^ `rustfmt` is a tool module, not a module | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0432`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.