about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-09-08 01:42:12 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-12-28 11:42:26 +0300
commite3155abd2efd5d07a8bc323b1ea0a915616c7ae0 (patch)
treec253e73f99edc0eaef0b586bcc44c1b4206b71ea
parent3a087ad3a924be12343bb035bf9b63ed81f650bf (diff)
downloadrust-e3155abd2efd5d07a8bc323b1ea0a915616c7ae0.tar.gz
rust-e3155abd2efd5d07a8bc323b1ea0a915616c7ae0.zip
Stabilize attribute macros on inline modules
-rw-r--r--src/libsyntax_expand/expand.rs11
-rw-r--r--src/test/ui/proc-macro/attributes-on-modules-fail.rs21
-rw-r--r--src/test/ui/proc-macro/attributes-on-modules-fail.stderr26
-rw-r--r--src/test/ui/proc-macro/attributes-on-modules.rs8
-rw-r--r--src/test/ui/proc-macro/attributes-on-modules.stderr12
-rw-r--r--src/test/ui/proc-macro/proc-macro-gates.rs6
-rw-r--r--src/test/ui/proc-macro/proc-macro-gates.stderr46
7 files changed, 58 insertions, 72 deletions
diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs
index b9b449d1779..4f6f88a753b 100644
--- a/src/libsyntax_expand/expand.rs
+++ b/src/libsyntax_expand/expand.rs
@@ -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(..)
diff --git a/src/test/ui/proc-macro/attributes-on-modules-fail.rs b/src/test/ui/proc-macro/attributes-on-modules-fail.rs
index c8bc0b34374..c506e903e7f 100644
--- a/src/test/ui/proc-macro/attributes-on-modules-fail.rs
+++ b/src/test/ui/proc-macro/attributes-on-modules-fail.rs
@@ -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() {}
diff --git a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr
index 34a5a5aaa54..74b9932a916 100644
--- a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr
+++ b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr
@@ -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
diff --git a/src/test/ui/proc-macro/attributes-on-modules.rs b/src/test/ui/proc-macro/attributes-on-modules.rs
index 12c3ac6d947..6c73b0bf19c 100644
--- a/src/test/ui/proc-macro/attributes-on-modules.rs
+++ b/src/test/ui/proc-macro/attributes-on-modules.rs
@@ -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;
 }
diff --git a/src/test/ui/proc-macro/attributes-on-modules.stderr b/src/test/ui/proc-macro/attributes-on-modules.stderr
deleted file mode 100644
index df75f0bf4b1..00000000000
--- a/src/test/ui/proc-macro/attributes-on-modules.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0658]: custom attributes cannot be applied to modules
-  --> $DIR/attributes-on-modules.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: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/proc-macro/proc-macro-gates.rs b/src/test/ui/proc-macro/proc-macro-gates.rs
index 591c1e039bd..5df6ac422ac 100644
--- a/src/test/ui/proc-macro/proc-macro-gates.rs
+++ b/src/test/ui/proc-macro/proc-macro-gates.rs
@@ -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
diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr
index e939434243b..fff96572e34 100644
--- a/src/test/ui/proc-macro/proc-macro-gates.stderr
+++ b/src/test/ui/proc-macro/proc-macro-gates.stderr
@@ -8,7 +8,7 @@ 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]
    |     ^^^^^^^^^^^^^^
@@ -16,32 +16,14 @@ 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,7 +113,7 @@ 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)];
    |               ^^^^^^^^^
@@ -139,6 +121,6 @@ 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`.