Skip to content

Commit e3155ab

Browse files
committed
Stabilize attribute macros on inline modules
1 parent 3a087ad commit e3155ab

7 files changed

+58
-72
lines changed

Diff for: src/libsyntax_expand/expand.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
717717

718718
fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {
719719
let kind = match item {
720-
Annotatable::Item(item) => match &item.kind {
721-
ItemKind::Mod(m) if m.inline => "modules",
722-
_ => return,
723-
},
724-
Annotatable::TraitItem(_) | Annotatable::ImplItem(_) | Annotatable::ForeignItem(_) => {
725-
return;
726-
}
720+
Annotatable::Item(_)
721+
| Annotatable::TraitItem(_)
722+
| Annotatable::ImplItem(_)
723+
| Annotatable::ForeignItem(_) => return,
727724
Annotatable::Stmt(_) => "statements",
728725
Annotatable::Expr(_) => "expressions",
729726
Annotatable::Arm(..)

Diff for: src/test/ui/proc-macro/attributes-on-modules-fail.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[macro_use]
44
extern crate test_macros;
55

6-
#[identity_attr] //~ ERROR custom attributes cannot be applied to modules
6+
#[identity_attr]
77
mod m {
88
pub struct X;
99

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

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

2626
mod inner_inline {} // OK
2727
}
2828

29+
#[derive(Empty)]
30+
struct S {
31+
field: [u8; {
32+
#[path = "outer/inner.rs"]
33+
mod inner; //~ ERROR non-inline modules in proc macro input are unstable
34+
mod inner_inline {} // OK
35+
0
36+
}]
37+
}
38+
39+
#[identity_attr]
40+
fn f() {
41+
#[path = "outer/inner.rs"]
42+
mod inner; //~ ERROR non-inline modules in proc macro input are unstable
43+
mod inner_inline {} // OK
44+
}
45+
2946
fn main() {}

Diff for: src/test/ui/proc-macro/attributes-on-modules-fail.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error[E0658]: custom attributes cannot be applied to modules
2-
--> $DIR/attributes-on-modules-fail.rs:6:1
3-
|
4-
LL | #[identity_attr]
5-
| ^^^^^^^^^^^^^^^^
6-
|
7-
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
8-
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
9-
101
error: `derive` may only be applied to structs, enums and unions
112
--> $DIR/attributes-on-modules-fail.rs:16:1
123
|
@@ -31,11 +22,20 @@ LL | mod inner;
3122
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
3223
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
3324

34-
error[E0658]: custom attributes cannot be applied to modules
35-
--> $DIR/attributes-on-modules-fail.rs:22:1
25+
error[E0658]: non-inline modules in proc macro input are unstable
26+
--> $DIR/attributes-on-modules-fail.rs:33:9
27+
|
28+
LL | mod inner;
29+
| ^^^^^^^^^^
30+
|
31+
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
32+
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
33+
34+
error[E0658]: non-inline modules in proc macro input are unstable
35+
--> $DIR/attributes-on-modules-fail.rs:42:5
3636
|
37-
LL | #[empty_attr]
38-
| ^^^^^^^^^^^^^
37+
LL | mod inner;
38+
| ^^^^^^^^^^
3939
|
4040
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
4141
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

Diff for: src/test/ui/proc-macro/attributes-on-modules.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
// check-pass
12
// aux-build:test-macros.rs
23

34
#[macro_use]
45
extern crate test_macros;
56

6-
#[identity_attr] //~ ERROR custom attributes cannot be applied to modules
7+
#[identity_attr]
78
mod m {
89
pub struct S;
910
}
1011

12+
#[identity_attr]
13+
fn f() {
14+
mod m {}
15+
}
16+
1117
fn main() {
1218
let s = m::S;
1319
}

Diff for: src/test/ui/proc-macro/attributes-on-modules.stderr

-12
This file was deleted.

Diff for: src/test/ui/proc-macro/proc-macro-gates.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ fn _test_inner() {
1010
#![empty_attr] //~ ERROR: non-builtin inner attributes are unstable
1111
}
1212

13-
#[empty_attr] //~ ERROR: custom attributes cannot be applied to modules
14-
mod _test2 {}
15-
1613
mod _test2_inner {
17-
#![empty_attr] //~ ERROR: custom attributes cannot be applied to modules
18-
//~| ERROR: non-builtin inner attributes are unstable
14+
#![empty_attr] //~ ERROR: non-builtin inner attributes are unstable
1915
}
2016

2117
#[empty_attr = "y"] //~ ERROR: key-value macro attributes are not supported

Diff for: src/test/ui/proc-macro/proc-macro-gates.stderr

+14-32
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,22 @@ LL | #![empty_attr]
88
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
99

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

19-
error[E0658]: custom attributes cannot be applied to modules
20-
--> $DIR/proc-macro-gates.rs:13:1
21-
|
22-
LL | #[empty_attr]
23-
| ^^^^^^^^^^^^^
24-
|
25-
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
26-
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
27-
28-
error[E0658]: custom attributes cannot be applied to modules
29-
--> $DIR/proc-macro-gates.rs:17:5
30-
|
31-
LL | #![empty_attr]
32-
| ^^^^^^^^^^^^^^
33-
|
34-
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
35-
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
36-
3719
error: key-value macro attributes are not supported
38-
--> $DIR/proc-macro-gates.rs:21:1
20+
--> $DIR/proc-macro-gates.rs:17:1
3921
|
4022
LL | #[empty_attr = "y"]
4123
| ^^^^^^^^^^^^^^^^^^^
4224

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

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

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

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

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

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

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

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

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

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

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

142-
error: aborting due to 16 previous errors
124+
error: aborting due to 14 previous errors
143125

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

0 commit comments

Comments
 (0)