Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize attribute macros on inline modules #64273

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/libsyntax_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down
21 changes: 19 additions & 2 deletions src/test/ui/proc-macro/attributes-on-modules-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {}
26 changes: 13 additions & 13 deletions src/test/ui/proc-macro/attributes-on-modules-fail.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/proc-macro/attributes-on-modules.rs
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 0 additions & 12 deletions src/test/ui/proc-macro/attributes-on-modules.stderr

This file was deleted.

6 changes: 1 addition & 5 deletions src/test/ui/proc-macro/proc-macro-gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 14 additions & 32 deletions src/test/ui/proc-macro/proc-macro-gates.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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]
| ^^^^^^^^^^^^^
Expand All @@ -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]
| ^^^^^^^^^^^^^
Expand All @@ -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]
| ^^^^^^^^^^^^^
Expand All @@ -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;
| ^^^^^^^^^^^^^^^^
Expand All @@ -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];
| ^^^^^^^^^^^^^^^^
Expand All @@ -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!();
| ^^^^^^^^^^^^^^^^
Expand All @@ -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) {}
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -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;);
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -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;);
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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);
| ^^^^^^^^^^^^
Expand All @@ -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`.