Skip to content

Commit

Permalink
Stabilize proc macros in type positions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 30, 2019
1 parent 349259d commit 5ae38bb
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/librustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(proc_macro_hygiene)]
#![allow(rustc::default_hash_types)]

#![recursion_limit="128"]
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {

fn gate_proc_macro_expansion_kind(&self, span: Span, kind: AstFragmentKind) {
let kind = match kind {
AstFragmentKind::Expr => "expressions",
AstFragmentKind::Expr |
AstFragmentKind::OptExpr => "expressions",
AstFragmentKind::Pat => "patterns",
AstFragmentKind::Ty => "types",
AstFragmentKind::Stmts => "statements",
AstFragmentKind::Items => return,
AstFragmentKind::TraitItems => return,
AstFragmentKind::ImplItems => return,
AstFragmentKind::Ty |
AstFragmentKind::Items |
AstFragmentKind::TraitItems |
AstFragmentKind::ImplItems |
AstFragmentKind::ForeignItems => return,
AstFragmentKind::Arms
| AstFragmentKind::Fields
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/proc-macro/dollar-crate-issue-62325.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate test_macros;
extern crate dollar_crate_external;
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/proc-macro/lifetimes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// aux-build:lifetimes.rs

#![feature(proc_macro_hygiene)]

extern crate lifetimes;

use lifetimes::*;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/proc-macro/lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected type, found `'`
--> $DIR/lifetimes.rs:9:10
--> $DIR/lifetimes.rs:7:10
|
LL | type A = single_quote_alone!();
| ^^^^^^^^^^^^^^^^^^^^^ this macro call doesn't expand to a type
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/proc-macro/macros-in-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// aux-build:test-macros.rs

#[macro_use]
extern crate test_macros;

const C: identity!(u8) = 10;

fn main() {
let c: u8 = C;
}
1 change: 0 additions & 1 deletion src/test/ui/proc-macro/proc-macro-gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fn attrs() {
}

fn main() {
let _x: identity!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
if let identity!(Some(_x)) = Some(3) {}
//~^ ERROR: procedural macros cannot be expanded to patterns

Expand Down
21 changes: 6 additions & 15 deletions src/test/ui/proc-macro/proc-macro-gates.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,8 @@ LL | let _x = #[identity_attr] println!();
= 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]: procedural macros cannot be expanded to types
--> $DIR/proc-macro-gates.rs:53:13
|
LL | let _x: identity!(u32) = 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[E0658]: procedural macros cannot be expanded to patterns
--> $DIR/proc-macro-gates.rs:54:12
--> $DIR/proc-macro-gates.rs:53:12
|
LL | if let identity!(Some(_x)) = Some(3) {}
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -113,7 +104,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:57:5
--> $DIR/proc-macro-gates.rs:56:5
|
LL | empty!(struct S;);
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -122,7 +113,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:58:5
--> $DIR/proc-macro-gates.rs:57:5
|
LL | empty!(let _x = 3;);
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -131,7 +122,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:60:14
--> $DIR/proc-macro-gates.rs:59:14
|
LL | let _x = identity!(3);
| ^^^^^^^^^^^^
Expand All @@ -140,14 +131,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:61:15
--> $DIR/proc-macro-gates.rs:60: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 17 previous errors
error: aborting due to 16 previous errors

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

0 comments on commit 5ae38bb

Please sign in to comment.