diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index b9b449d177915..4f6f88a753b2b 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 c8bc0b3437436..c506e903e7f89 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 34a5a5aaa54fb..74b9932a916c9 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 12c3ac6d9475b..6c73b0bf19c7f 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 df75f0bf4b149..0000000000000 --- 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 591c1e039bd75..5df6ac422ac4b 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 e939434243b6a..fff96572e340f 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`.