Skip to content
Permalink
Browse files

Stabilize attribute macros on inline modules

  • Loading branch information
petrochenkov committed Sep 7, 2019
1 parent 3a087ad commit e3155abd2efd5d07a8bc323b1ea0a915616c7ae0
@@ -717,13 +717,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {

fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {
let kind = match item {
Annotatable::Item(item) => match &item.kind {
ItemKind::Mod(m) if m.inline => "modules",
_ => return,
},
Annotatable::TraitItem(_) | Annotatable::ImplItem(_) | Annotatable::ForeignItem(_) => {
return;
}
Annotatable::Item(_)
| Annotatable::TraitItem(_)
| Annotatable::ImplItem(_)
| Annotatable::ForeignItem(_) => return,
Annotatable::Stmt(_) => "statements",
Annotatable::Expr(_) => "expressions",
Annotatable::Arm(..)
@@ -3,7 +3,7 @@
#[macro_use]
extern crate test_macros;

#[identity_attr] //~ ERROR custom attributes cannot be applied to modules
#[identity_attr]
mod m {
pub struct X;

@@ -19,11 +19,28 @@ mod n {}
#[empty_attr]
mod module; //~ ERROR non-inline modules in proc macro input are unstable

#[empty_attr] //~ ERROR custom attributes cannot be applied to modules
#[empty_attr]
mod outer {
mod inner; //~ ERROR non-inline modules in proc macro input are unstable

mod inner_inline {} // OK
}

#[derive(Empty)]
struct S {
field: [u8; {
#[path = "outer/inner.rs"]
mod inner; //~ ERROR non-inline modules in proc macro input are unstable
mod inner_inline {} // OK
0
}]
}

#[identity_attr]
fn f() {
#[path = "outer/inner.rs"]
mod inner; //~ ERROR non-inline modules in proc macro input are unstable
mod inner_inline {} // OK
}

fn main() {}
@@ -1,12 +1,3 @@
error[E0658]: custom attributes cannot be applied to modules
--> $DIR/attributes-on-modules-fail.rs:6:1
|
LL | #[identity_attr]
| ^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error: `derive` may only be applied to structs, enums and unions
--> $DIR/attributes-on-modules-fail.rs:16:1
|
@@ -31,11 +22,20 @@ LL | mod inner;
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to modules
--> $DIR/attributes-on-modules-fail.rs:22:1
error[E0658]: non-inline modules in proc macro input are unstable
--> $DIR/attributes-on-modules-fail.rs:33:9
|
LL | mod inner;
| ^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: non-inline modules in proc macro input are unstable
--> $DIR/attributes-on-modules-fail.rs:42:5
|
LL | #[empty_attr]
| ^^^^^^^^^^^^^
LL | mod inner;
| ^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
@@ -1,13 +1,19 @@
// check-pass
// aux-build:test-macros.rs

#[macro_use]
extern crate test_macros;

#[identity_attr] //~ ERROR custom attributes cannot be applied to modules
#[identity_attr]
mod m {
pub struct S;
}

#[identity_attr]
fn f() {
mod m {}
}

fn main() {
let s = m::S;
}

This file was deleted.

@@ -10,12 +10,8 @@ fn _test_inner() {
#![empty_attr] //~ ERROR: non-builtin inner attributes are unstable
}

#[empty_attr] //~ ERROR: custom attributes cannot be applied to modules
mod _test2 {}

mod _test2_inner {
#![empty_attr] //~ ERROR: custom attributes cannot be applied to modules
//~| ERROR: non-builtin inner attributes are unstable
#![empty_attr] //~ ERROR: non-builtin inner attributes are unstable
}

#[empty_attr = "y"] //~ ERROR: key-value macro attributes are not supported
@@ -8,40 +8,22 @@ LL | #![empty_attr]
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable

error[E0658]: non-builtin inner attributes are unstable
--> $DIR/proc-macro-gates.rs:17:5
--> $DIR/proc-macro-gates.rs:14:5
|
LL | #![empty_attr]
| ^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54726
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to modules
--> $DIR/proc-macro-gates.rs:13:1
|
LL | #[empty_attr]
| ^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to modules
--> $DIR/proc-macro-gates.rs:17:5
|
LL | #![empty_attr]
| ^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error: key-value macro attributes are not supported
--> $DIR/proc-macro-gates.rs:21:1
--> $DIR/proc-macro-gates.rs:17:1
|
LL | #[empty_attr = "y"]
| ^^^^^^^^^^^^^^^^^^^

error[E0658]: custom attributes cannot be applied to statements
--> $DIR/proc-macro-gates.rs:30:5
--> $DIR/proc-macro-gates.rs:26:5
|
LL | #[empty_attr]
| ^^^^^^^^^^^^^
@@ -50,7 +32,7 @@ LL | #[empty_attr]
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to statements
--> $DIR/proc-macro-gates.rs:34:5
--> $DIR/proc-macro-gates.rs:30:5
|
LL | #[empty_attr]
| ^^^^^^^^^^^^^
@@ -59,7 +41,7 @@ LL | #[empty_attr]
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to statements
--> $DIR/proc-macro-gates.rs:38:5
--> $DIR/proc-macro-gates.rs:34:5
|
LL | #[empty_attr]
| ^^^^^^^^^^^^^
@@ -68,7 +50,7 @@ LL | #[empty_attr]
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to expressions
--> $DIR/proc-macro-gates.rs:42:14
--> $DIR/proc-macro-gates.rs:38:14
|
LL | let _x = #[identity_attr] 2;
| ^^^^^^^^^^^^^^^^
@@ -77,7 +59,7 @@ LL | let _x = #[identity_attr] 2;
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to expressions
--> $DIR/proc-macro-gates.rs:45:15
--> $DIR/proc-macro-gates.rs:41:15
|
LL | let _x = [#[identity_attr] 2];
| ^^^^^^^^^^^^^^^^
@@ -86,7 +68,7 @@ LL | let _x = [#[identity_attr] 2];
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to expressions
--> $DIR/proc-macro-gates.rs:48:14
--> $DIR/proc-macro-gates.rs:44:14
|
LL | let _x = #[identity_attr] println!();
| ^^^^^^^^^^^^^^^^
@@ -95,7 +77,7 @@ LL | let _x = #[identity_attr] println!();
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to patterns
--> $DIR/proc-macro-gates.rs:53:12
--> $DIR/proc-macro-gates.rs:49:12
|
LL | if let identity!(Some(_x)) = Some(3) {}
| ^^^^^^^^^^^^^^^^^^^
@@ -104,7 +86,7 @@ LL | if let identity!(Some(_x)) = Some(3) {}
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to statements
--> $DIR/proc-macro-gates.rs:56:5
--> $DIR/proc-macro-gates.rs:52:5
|
LL | empty!(struct S;);
| ^^^^^^^^^^^^^^^^^^
@@ -113,7 +95,7 @@ LL | empty!(struct S;);
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to statements
--> $DIR/proc-macro-gates.rs:57:5
--> $DIR/proc-macro-gates.rs:53:5
|
LL | empty!(let _x = 3;);
| ^^^^^^^^^^^^^^^^^^^^
@@ -122,7 +104,7 @@ LL | empty!(let _x = 3;);
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to expressions
--> $DIR/proc-macro-gates.rs:59:14
--> $DIR/proc-macro-gates.rs:55:14
|
LL | let _x = identity!(3);
| ^^^^^^^^^^^^
@@ -131,14 +113,14 @@ LL | let _x = identity!(3);
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to expressions
--> $DIR/proc-macro-gates.rs:60:15
--> $DIR/proc-macro-gates.rs:56:15
|
LL | let _x = [empty!(3)];
| ^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error: aborting due to 16 previous errors
error: aborting due to 14 previous errors

For more information about this error, try `rustc --explain E0658`.

0 comments on commit e3155ab

Please sign in to comment.
You can’t perform that action at this time.