diff options
| author | bors <bors@rust-lang.org> | 2019-07-26 23:29:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-26 23:29:02 +0000 |
| commit | 09e39897587dca70f0b15093d425a682c392349c (patch) | |
| tree | 508bc51dc8e6410bffb962429eb5a61ec6d6a3cc /src/test/ui | |
| parent | c43753f910aae000f8bcb0a502407ea332afc74b (diff) | |
| parent | 8eaf17bca2674293eba0ea10056d5c77b6352086 (diff) | |
Auto merge of #62086 - petrochenkov:builtout, r=eddyb
Define built-in macros through libcore
This PR defines built-in macros through libcore using a scheme similar to lang items (attribute `#[rustc_builtin_macro]`).
All the macro properties (stability, visibility, etc.) are taken from the source code in libcore, with exception of the expander function transforming input tokens/AST into output tokens/AST, which is still provided by the compiler.
The macros are made available to user code through the standard library prelude (`{core,std}::prelude::v1`), so they are still always in scope.
As a result **built-in macros now have stable absolute addresses in the library**, like `core::prelude::v1::line!()`, this is an insta-stable change.
Right now `prelude::v1` is the only publicly available absolute address for these macros, but eventually they can be moved into more appropriate locations with library team approval (e.g. `Clone` derive -> `core::clone::Clone`).
Now when built-in macros have canonical definitions they can be imported or reexported without issues (https://github.com/rust-lang/rust/issues/61687).
Other changes:
- You can now define a derive macro with a name matching one of the built-in derives (https://github.com/rust-lang/rust/issues/52269). This was an artificial restriction that could be worked around with import renaming anyway.
Known regressions:
- Empty library crate with a crate-level `#![test]` attribute no longer compiles without `--test`. Previously it didn't compile *with* `--test` or with the bin crate type.
Fixes https://github.com/rust-lang/rust/issues/61687
Fixes https://github.com/rust-lang/rust/issues/61804
r? @eddyb
Diffstat (limited to 'src/test/ui')
19 files changed, 76 insertions, 89 deletions
diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-bench.rs b/src/test/ui/feature-gate/issue-43106-gating-of-bench.rs index 2d8868995f4..31eee88d1fa 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-bench.rs +++ b/src/test/ui/feature-gate/issue-43106-gating-of-bench.rs @@ -1,17 +1,10 @@ -// error-pattern: `main` function not found - -// At time of authorship, a crate-level #![bench] with no `--test` -// will cause compilation to error unconditionally with "main function -// not found" (despite having one), similar to #[bench]. -// -// (The non-crate level cases are in -// issue-43106-gating-of-builtin-attrs.rs.) - +// The non-crate level cases are in issue-43106-gating-of-builtin-attrs.rs. // See issue-12997-1.rs and issue-12997-2.rs to see how `#[bench]` is // handled in "weird places" when `--test` is passed. #![feature(custom_inner_attributes)] #![bench = "4100"] +//~^ ERROR cannot determine resolution for the attribute macro `bench` -fn main() { } +fn main() {} diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-bench.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-bench.stderr index 37b5e792dc2..d0305c5160f 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-bench.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-bench.stderr @@ -1,17 +1,10 @@ -warning: attribute must be of the form `#[bench]` - --> $DIR/issue-43106-gating-of-bench.rs:15:1 +error: cannot determine resolution for the attribute macro `bench` + --> $DIR/issue-43106-gating-of-bench.rs:7:4 | LL | #![bench = "4100"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ | - = note: `#[warn(ill_formed_attribute_input)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> - -error[E0601]: `main` function not found in crate `issue_43106_gating_of_bench` - | - = note: consider adding a `main` function to `$DIR/issue-43106-gating-of-bench.rs` + = note: import resolution is stuck, try simplifying macro imports error: aborting due to previous error -For more information about this error, try `rustc --explain E0601`. diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-test.rs b/src/test/ui/feature-gate/issue-43106-gating-of-test.rs index c0c49d35300..d343746955f 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-test.rs +++ b/src/test/ui/feature-gate/issue-43106-gating-of-test.rs @@ -1,12 +1,6 @@ -// error-pattern: `main` function not found - -// At time of authorship, crate-level #[test] attribute with no -// `--test` signals unconditional error complaining of missing main -// function (despite having one), similar to #[bench]. -// -// (The non-crate level cases are in -// issue-43106-gating-of-builtin-attrs.rs.) +// The non-crate level cases are in issue-43106-gating-of-builtin-attrs.rs. #![test = "4200"] +//~^ ERROR cannot determine resolution for the attribute macro `test` -fn main() { } +fn main() {} diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-test.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-test.stderr index dbffabf3e02..a7d3a1e1684 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-test.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-test.stderr @@ -1,17 +1,10 @@ -warning: attribute must be of the form `#[test]` - --> $DIR/issue-43106-gating-of-test.rs:10:1 +error: cannot determine resolution for the attribute macro `test` + --> $DIR/issue-43106-gating-of-test.rs:3:4 | LL | #![test = "4200"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ | - = note: `#[warn(ill_formed_attribute_input)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571> - -error[E0601]: `main` function not found in crate `issue_43106_gating_of_test` - | - = note: consider adding a `main` function to `$DIR/issue-43106-gating-of-test.rs` + = note: import resolution is stuck, try simplifying macro imports error: aborting due to previous error -For more information about this error, try `rustc --explain E0601`. diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs index 827ac3af8f1..506b21dc7d5 100644 --- a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs +++ b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs @@ -1,4 +1,4 @@ -#![feature(intrinsics, lang_items, no_core)] +#![feature(intrinsics, lang_items, no_core, rustc_attrs)] #![crate_type="rlib"] #![no_core] @@ -88,3 +88,7 @@ fn main() { cfg!(target_has_atomic = "ptr"); //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change } + +#[macro_export] +#[rustc_builtin_macro] +macro_rules! cfg { () => () } diff --git a/src/test/ui/imports/glob-shadowing.stderr b/src/test/ui/imports/glob-shadowing.stderr index 7962fcb9aec..4ef446f93c8 100644 --- a/src/test/ui/imports/glob-shadowing.stderr +++ b/src/test/ui/imports/glob-shadowing.stderr @@ -4,7 +4,7 @@ error[E0659]: `env` is ambiguous (glob import vs any other name from outer scope LL | let x = env!("PATH"); | ^^^ ambiguous name | - = note: `env` could refer to a built-in macro + = note: `env` could refer to a macro from prelude note: `env` could also refer to the macro imported here --> $DIR/glob-shadowing.rs:9:9 | @@ -19,7 +19,7 @@ error[E0659]: `env` is ambiguous (glob import vs any other name from outer scope LL | let x = env!("PATH"); | ^^^ ambiguous name | - = note: `env` could refer to a built-in macro + = note: `env` could refer to a macro from prelude note: `env` could also refer to the macro imported here --> $DIR/glob-shadowing.rs:17:13 | diff --git a/src/test/ui/imports/local-modularized-tricky-fail-1.stderr b/src/test/ui/imports/local-modularized-tricky-fail-1.stderr index 13d3227d8b3..5afdd8889ae 100644 --- a/src/test/ui/imports/local-modularized-tricky-fail-1.stderr +++ b/src/test/ui/imports/local-modularized-tricky-fail-1.stderr @@ -27,7 +27,7 @@ error[E0659]: `include` is ambiguous (macro-expanded name vs less macro-expanded LL | include!(); | ^^^^^^^ ambiguous name | - = note: `include` could refer to a built-in macro + = note: `include` could refer to a macro from prelude note: `include` could also refer to the macro defined here --> $DIR/local-modularized-tricky-fail-1.rs:17:5 | diff --git a/src/test/ui/issues/issue-28134.rs b/src/test/ui/issues/issue-28134.rs index 2bd4f93791d..fa692db4bf6 100644 --- a/src/test/ui/issues/issue-28134.rs +++ b/src/test/ui/issues/issue-28134.rs @@ -1,3 +1,3 @@ // compile-flags: --test -#![test] //~ ERROR only functions may be used as tests +#![test] //~ ERROR cannot determine resolution for the attribute macro `test` diff --git a/src/test/ui/issues/issue-28134.stderr b/src/test/ui/issues/issue-28134.stderr index b9189480048..5f8d27dd043 100644 --- a/src/test/ui/issues/issue-28134.stderr +++ b/src/test/ui/issues/issue-28134.stderr @@ -1,8 +1,10 @@ -error: only functions may be used as tests - --> $DIR/issue-28134.rs:3:1 +error: cannot determine resolution for the attribute macro `test` + --> $DIR/issue-28134.rs:3:4 | LL | #![test] - | ^^^^^^^^ + | ^^^^ + | + = note: import resolution is stuck, try simplifying macro imports error: aborting due to previous error diff --git a/src/test/ui/macros/unknown-builtin.rs b/src/test/ui/macros/unknown-builtin.rs new file mode 100644 index 00000000000..a96b99ae4ff --- /dev/null +++ b/src/test/ui/macros/unknown-builtin.rs @@ -0,0 +1,14 @@ +// error-pattern: cannot find a built-in macro with name `line` + +#![feature(rustc_attrs)] + +#[rustc_builtin_macro] +macro_rules! unknown { () => () } //~ ERROR cannot find a built-in macro with name `unknown` + +#[rustc_builtin_macro] +macro_rules! line { () => () } + +fn main() { + line!(); + std::prelude::v1::line!(); +} diff --git a/src/test/ui/macros/unknown-builtin.stderr b/src/test/ui/macros/unknown-builtin.stderr new file mode 100644 index 00000000000..33b7b055b4e --- /dev/null +++ b/src/test/ui/macros/unknown-builtin.stderr @@ -0,0 +1,14 @@ +error: cannot find a built-in macro with name `unknown` + --> $DIR/unknown-builtin.rs:6:1 + | +LL | macro_rules! unknown { () => () } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cannot find a built-in macro with name `line` + --> <::core::macros::builtin::line macros>:1:1 + | +LL | () => { } + | ^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/proc-macro/attribute.rs b/src/test/ui/proc-macro/attribute.rs index 04c88dcef50..5531b323621 100644 --- a/src/test/ui/proc-macro/attribute.rs +++ b/src/test/ui/proc-macro/attribute.rs @@ -40,8 +40,7 @@ pub fn foo8(input: TokenStream) -> TokenStream { input } //~^ ERROR: `self` cannot be a name of derive macro pub fn foo9(input: TokenStream) -> TokenStream { input } -#[proc_macro_derive(PartialEq)] -//~^ ERROR: cannot override a built-in derive macro +#[proc_macro_derive(PartialEq)] // OK pub fn foo10(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d11, a)] diff --git a/src/test/ui/proc-macro/attribute.stderr b/src/test/ui/proc-macro/attribute.stderr index e632875cb16..1503f62cb6c 100644 --- a/src/test/ui/proc-macro/attribute.stderr +++ b/src/test/ui/proc-macro/attribute.stderr @@ -40,56 +40,50 @@ error: `self` cannot be a name of derive macro LL | #[proc_macro_derive(self)] | ^^^^ -error: cannot override a built-in derive macro - --> $DIR/attribute.rs:43:21 - | -LL | #[proc_macro_derive(PartialEq)] - | ^^^^^^^^^ - error: second argument must be `attributes` - --> $DIR/attribute.rs:47:26 + --> $DIR/attribute.rs:46:26 | LL | #[proc_macro_derive(d11, a)] | ^ error: attribute must be of form: `attributes(foo, bar)` - --> $DIR/attribute.rs:47:26 + --> $DIR/attribute.rs:46:26 | LL | #[proc_macro_derive(d11, a)] | ^ error: attribute must be of form: `attributes(foo, bar)` - --> $DIR/attribute.rs:52:26 + --> $DIR/attribute.rs:51:26 | LL | #[proc_macro_derive(d12, attributes)] | ^^^^^^^^^^ error: not a meta item - --> $DIR/attribute.rs:56:37 + --> $DIR/attribute.rs:55:37 | LL | #[proc_macro_derive(d13, attributes("a"))] | ^^^ error: must only be one word - --> $DIR/attribute.rs:60:37 + --> $DIR/attribute.rs:59:37 | LL | #[proc_macro_derive(d14, attributes(a = ""))] | ^^^^^^ error: must only be one word - --> $DIR/attribute.rs:64:37 + --> $DIR/attribute.rs:63:37 | LL | #[proc_macro_derive(d15, attributes(m::a))] | ^^^^ error: must only be one word - --> $DIR/attribute.rs:68:37 + --> $DIR/attribute.rs:67:37 | LL | #[proc_macro_derive(d16, attributes(a(b)))] | ^^^^ error: `self` cannot be a name of derive helper attribute - --> $DIR/attribute.rs:72:37 + --> $DIR/attribute.rs:71:37 | LL | #[proc_macro_derive(d17, attributes(self))] | ^^^^ @@ -106,5 +100,5 @@ error: malformed `proc_macro_derive` attribute input LL | #[proc_macro_derive = ""] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` -error: aborting due to 18 previous errors +error: aborting due to 17 previous errors diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.rs b/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.rs index dd21de75aaf..acb4bbebe7f 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.rs @@ -3,7 +3,7 @@ // 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]`, but not the `test` crate. use proc_macro; // OK, imports the built-in `proc_macro` attribute, but not the `proc_macro` crate. fn main() {} diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.stderr index 4e3fff98e6f..f324378d4ca 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/not-whitelisted.stderr @@ -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 | 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`. diff --git a/src/test/ui/rust-2018/uniform-paths/prelude-fail.rs b/src/test/ui/rust-2018/uniform-paths/prelude-fail.rs index d717884c901..48c33d720dc 100644 --- a/src/test/ui/rust-2018/uniform-paths/prelude-fail.rs +++ b/src/test/ui/rust-2018/uniform-paths/prelude-fail.rs @@ -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() {} diff --git a/src/test/ui/rust-2018/uniform-paths/prelude-fail.stderr b/src/test/ui/rust-2018/uniform-paths/prelude-fail.stderr index 42daf7c6fb1..97d4c736751 100644 --- a/src/test/ui/rust-2018/uniform-paths/prelude-fail.stderr +++ b/src/test/ui/rust-2018/uniform-paths/prelude-fail.stderr @@ -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`. diff --git a/src/test/ui/rust-2018/uniform-paths/prelude.rs b/src/test/ui/rust-2018/uniform-paths/prelude.rs index dca9587c5d3..65763614ce0 100644 --- a/src/test/ui/rust-2018/uniform-paths/prelude.rs +++ b/src/test/ui/rust-2018/uniform-paths/prelude.rs @@ -10,9 +10,13 @@ use Vec as ImportedVec; // Built-in type use u8 as imported_u8; +// Built-in macro +use env as env_imported; + type A = imported_u8; fn main() { imported_vec![0]; ImportedVec::<u8>::new(); + env_imported!("PATH"); } diff --git a/src/test/ui/rust-unstable-column-gated.stderr b/src/test/ui/rust-unstable-column-gated.stderr index c581a16dbb0..7db1b01fb0e 100644 --- a/src/test/ui/rust-unstable-column-gated.stderr +++ b/src/test/ui/rust-unstable-column-gated.stderr @@ -1,4 +1,4 @@ -error[E0658]: use of unstable library feature '__rust_unstable_column': internal implementation detail of the `column` macro +error[E0658]: use of unstable library feature '__rust_unstable_column': internal implementation detail of the `panic` macro --> $DIR/rust-unstable-column-gated.rs:2:20 | LL | println!("{}", __rust_unstable_column!()); |
