2019-05-21 22:09:58 +00:00
|
|
|
// aux-build:test-macros.rs
|
2018-07-06 01:09:35 +00:00
|
|
|
// gate-test-proc_macro_hygiene
|
rustc: Tweak custom attribute capabilities
This commit starts to lay some groundwork for the stabilization of custom
attribute invocations and general procedural macros. It applies a number of
changes discussed on [internals] as well as a [recent issue][issue], namely:
* The path used to specify a custom attribute must be of length one and cannot
be a global path. This'll help future-proof us against any ambiguities and
give us more time to settle the precise syntax. In the meantime though a bare
identifier can be used and imported to invoke a custom attribute macro. A new
feature gate, `proc_macro_path_invoc`, was added to gate multi-segment paths
and absolute paths.
* The set of items which can be annotated by a custom procedural attribute has
been restricted. Statements, expressions, and modules are disallowed behind
two new feature gates: `proc_macro_expr` and `proc_macro_mod`.
* The input to procedural macro attributes has been restricted and adjusted.
Today an invocation like `#[foo(bar)]` will receive `(bar)` as the input token
stream, but after this PR it will only receive `bar` (the delimiters were
removed). Invocations like `#[foo]` are still allowed and will be invoked in
the same way as `#[foo()]`. This is a **breaking change** for all nightly
users as the syntax coming in to procedural macros will be tweaked slightly.
* Procedural macros (`foo!()` style) can only be expanded to item-like items by
default. A separate feature gate, `proc_macro_non_items`, is required to
expand to items like expressions, statements, etc.
Closes #50038
[internals]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
[issue]: https://github.com/rust-lang/rust/issues/50038
2018-04-20 14:50:39 +00:00
|
|
|
|
2018-08-04 00:37:14 +00:00
|
|
|
#![feature(stmt_expr_attributes)]
|
rustc: Tweak custom attribute capabilities
This commit starts to lay some groundwork for the stabilization of custom
attribute invocations and general procedural macros. It applies a number of
changes discussed on [internals] as well as a [recent issue][issue], namely:
* The path used to specify a custom attribute must be of length one and cannot
be a global path. This'll help future-proof us against any ambiguities and
give us more time to settle the precise syntax. In the meantime though a bare
identifier can be used and imported to invoke a custom attribute macro. A new
feature gate, `proc_macro_path_invoc`, was added to gate multi-segment paths
and absolute paths.
* The set of items which can be annotated by a custom procedural attribute has
been restricted. Statements, expressions, and modules are disallowed behind
two new feature gates: `proc_macro_expr` and `proc_macro_mod`.
* The input to procedural macro attributes has been restricted and adjusted.
Today an invocation like `#[foo(bar)]` will receive `(bar)` as the input token
stream, but after this PR it will only receive `bar` (the delimiters were
removed). Invocations like `#[foo]` are still allowed and will be invoked in
the same way as `#[foo()]`. This is a **breaking change** for all nightly
users as the syntax coming in to procedural macros will be tweaked slightly.
* Procedural macros (`foo!()` style) can only be expanded to item-like items by
default. A separate feature gate, `proc_macro_non_items`, is required to
expand to items like expressions, statements, etc.
Closes #50038
[internals]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
[issue]: https://github.com/rust-lang/rust/issues/50038
2018-04-20 14:50:39 +00:00
|
|
|
|
2019-05-21 22:09:58 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate test_macros;
|
rustc: Tweak custom attribute capabilities
This commit starts to lay some groundwork for the stabilization of custom
attribute invocations and general procedural macros. It applies a number of
changes discussed on [internals] as well as a [recent issue][issue], namely:
* The path used to specify a custom attribute must be of length one and cannot
be a global path. This'll help future-proof us against any ambiguities and
give us more time to settle the precise syntax. In the meantime though a bare
identifier can be used and imported to invoke a custom attribute macro. A new
feature gate, `proc_macro_path_invoc`, was added to gate multi-segment paths
and absolute paths.
* The set of items which can be annotated by a custom procedural attribute has
been restricted. Statements, expressions, and modules are disallowed behind
two new feature gates: `proc_macro_expr` and `proc_macro_mod`.
* The input to procedural macro attributes has been restricted and adjusted.
Today an invocation like `#[foo(bar)]` will receive `(bar)` as the input token
stream, but after this PR it will only receive `bar` (the delimiters were
removed). Invocations like `#[foo]` are still allowed and will be invoked in
the same way as `#[foo()]`. This is a **breaking change** for all nightly
users as the syntax coming in to procedural macros will be tweaked slightly.
* Procedural macros (`foo!()` style) can only be expanded to item-like items by
default. A separate feature gate, `proc_macro_non_items`, is required to
expand to items like expressions, statements, etc.
Closes #50038
[internals]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
[issue]: https://github.com/rust-lang/rust/issues/50038
2018-04-20 14:50:39 +00:00
|
|
|
|
2018-04-29 22:13:54 +00:00
|
|
|
fn _test_inner() {
|
2020-11-18 22:49:20 +00:00
|
|
|
#![empty_attr] //~ ERROR: inner macro attributes are unstable
|
2018-04-29 22:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mod _test2_inner {
|
2020-11-18 22:49:20 +00:00
|
|
|
#![empty_attr] //~ ERROR: inner macro attributes are unstable
|
2018-04-29 22:13:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 14:07:38 +00:00
|
|
|
#[empty_attr = "y"] //~ ERROR: key-value macro attributes are not supported
|
rustc: Tweak custom attribute capabilities
This commit starts to lay some groundwork for the stabilization of custom
attribute invocations and general procedural macros. It applies a number of
changes discussed on [internals] as well as a [recent issue][issue], namely:
* The path used to specify a custom attribute must be of length one and cannot
be a global path. This'll help future-proof us against any ambiguities and
give us more time to settle the precise syntax. In the meantime though a bare
identifier can be used and imported to invoke a custom attribute macro. A new
feature gate, `proc_macro_path_invoc`, was added to gate multi-segment paths
and absolute paths.
* The set of items which can be annotated by a custom procedural attribute has
been restricted. Statements, expressions, and modules are disallowed behind
two new feature gates: `proc_macro_expr` and `proc_macro_mod`.
* The input to procedural macro attributes has been restricted and adjusted.
Today an invocation like `#[foo(bar)]` will receive `(bar)` as the input token
stream, but after this PR it will only receive `bar` (the delimiters were
removed). Invocations like `#[foo]` are still allowed and will be invoked in
the same way as `#[foo()]`. This is a **breaking change** for all nightly
users as the syntax coming in to procedural macros will be tweaked slightly.
* Procedural macros (`foo!()` style) can only be expanded to item-like items by
default. A separate feature gate, `proc_macro_non_items`, is required to
expand to items like expressions, statements, etc.
Closes #50038
[internals]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
[issue]: https://github.com/rust-lang/rust/issues/50038
2018-04-20 14:50:39 +00:00
|
|
|
fn _test3() {}
|
|
|
|
|
2018-04-29 22:13:54 +00:00
|
|
|
fn attrs() {
|
|
|
|
// Statement, item
|
2019-05-21 22:09:58 +00:00
|
|
|
#[empty_attr] // OK
|
2018-04-29 22:13:54 +00:00
|
|
|
struct S;
|
|
|
|
|
|
|
|
// Statement, macro
|
2019-05-21 22:09:58 +00:00
|
|
|
#[empty_attr] //~ ERROR: custom attributes cannot be applied to statements
|
2018-04-29 22:13:54 +00:00
|
|
|
println!();
|
|
|
|
|
|
|
|
// Statement, semi
|
2019-05-21 22:09:58 +00:00
|
|
|
#[empty_attr] //~ ERROR: custom attributes cannot be applied to statements
|
2018-04-29 22:13:54 +00:00
|
|
|
S;
|
|
|
|
|
|
|
|
// Statement, local
|
2019-05-21 22:09:58 +00:00
|
|
|
#[empty_attr] //~ ERROR: custom attributes cannot be applied to statements
|
rustc: Tweak custom attribute capabilities
This commit starts to lay some groundwork for the stabilization of custom
attribute invocations and general procedural macros. It applies a number of
changes discussed on [internals] as well as a [recent issue][issue], namely:
* The path used to specify a custom attribute must be of length one and cannot
be a global path. This'll help future-proof us against any ambiguities and
give us more time to settle the precise syntax. In the meantime though a bare
identifier can be used and imported to invoke a custom attribute macro. A new
feature gate, `proc_macro_path_invoc`, was added to gate multi-segment paths
and absolute paths.
* The set of items which can be annotated by a custom procedural attribute has
been restricted. Statements, expressions, and modules are disallowed behind
two new feature gates: `proc_macro_expr` and `proc_macro_mod`.
* The input to procedural macro attributes has been restricted and adjusted.
Today an invocation like `#[foo(bar)]` will receive `(bar)` as the input token
stream, but after this PR it will only receive `bar` (the delimiters were
removed). Invocations like `#[foo]` are still allowed and will be invoked in
the same way as `#[foo()]`. This is a **breaking change** for all nightly
users as the syntax coming in to procedural macros will be tweaked slightly.
* Procedural macros (`foo!()` style) can only be expanded to item-like items by
default. A separate feature gate, `proc_macro_non_items`, is required to
expand to items like expressions, statements, etc.
Closes #50038
[internals]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
[issue]: https://github.com/rust-lang/rust/issues/50038
2018-04-20 14:50:39 +00:00
|
|
|
let _x = 2;
|
2018-04-29 22:13:54 +00:00
|
|
|
|
|
|
|
// Expr
|
2019-05-21 22:09:58 +00:00
|
|
|
let _x = #[identity_attr] 2; //~ ERROR: custom attributes cannot be applied to expressions
|
2018-04-29 22:13:54 +00:00
|
|
|
|
|
|
|
// Opt expr
|
2019-05-21 22:09:58 +00:00
|
|
|
let _x = [#[identity_attr] 2]; //~ ERROR: custom attributes cannot be applied to expressions
|
2018-04-29 22:13:54 +00:00
|
|
|
|
|
|
|
// Expr macro
|
2019-05-21 22:09:58 +00:00
|
|
|
let _x = #[identity_attr] println!();
|
|
|
|
//~^ ERROR: custom attributes cannot be applied to expressions
|
2018-04-29 22:13:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 20:42:42 +00:00
|
|
|
fn test_case() {
|
|
|
|
#![test] //~ ERROR inner macro attributes are unstable
|
|
|
|
//~| WARN this was previously accepted
|
|
|
|
}
|
|
|
|
|
2020-01-31 22:02:31 +00:00
|
|
|
fn main() {}
|