]> git.lizzy.rs Git - rust.git/commitdiff
Stabilize proc macros in type positions
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 27 Aug 2019 00:48:48 +0000 (03:48 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 30 Sep 2019 18:59:35 +0000 (21:59 +0300)
src/librustc_macros/src/lib.rs
src/libsyntax/ext/expand.rs
src/test/ui/proc-macro/dollar-crate-issue-62325.rs
src/test/ui/proc-macro/lifetimes.rs
src/test/ui/proc-macro/lifetimes.stderr
src/test/ui/proc-macro/macros-in-type.rs [new file with mode: 0644]
src/test/ui/proc-macro/proc-macro-gates.rs
src/test/ui/proc-macro/proc-macro-gates.stderr

index 3d3a020ef0c8e71b60ea893c07bcf0819e09af6d..0540c95d3ded382b1192e67965f3d2ef56ea524c 100644 (file)
@@ -1,4 +1,3 @@
-#![feature(proc_macro_hygiene)]
 #![allow(rustc::default_hash_types)]
 
 #![recursion_limit="128"]
index cf8edf54673164e6d4dbba1adc152841cdedbbe4..581ef5d4da9b31fe8e0866e348b33b63279b112f 100644 (file)
@@ -749,14 +749,14 @@ fn visit_mac(&mut self, _mac: &'ast ast::Mac) {
 
     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
index b7b152e669213beea31d60755375f2ec85034bde..223c4047cb2b1e2548b9dd2fb86fcf23ad00c3a7 100644 (file)
@@ -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;
index d0dd1b4603b168b4409fe05738794eeb66c77bc1..5605696715e34223efd00528a90d061e0ad7aad6 100644 (file)
@@ -1,7 +1,5 @@
 // aux-build:lifetimes.rs
 
-#![feature(proc_macro_hygiene)]
-
 extern crate lifetimes;
 
 use lifetimes::*;
index 6e91201405cc69dbc989567ed08f25f02f1d2dd1..10acd4304aa231a9536879065ee6cf631d26d03b 100644 (file)
@@ -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
diff --git a/src/test/ui/proc-macro/macros-in-type.rs b/src/test/ui/proc-macro/macros-in-type.rs
new file mode 100644 (file)
index 0000000..19ed58e
--- /dev/null
@@ -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;
+}
index 678dc83b753b5f7b5143b846833c62c37698b4d9..0096a84f14c3490a865bcfa723a6082e0ba7bf99 100644 (file)
@@ -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
 
index 8462b564ec1d7b2588458fb52bf209608757fa78..14a4f8c0fbca2ba265b9577fcf15b6a46b48db19 100644 (file)
@@ -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) {}
    |            ^^^^^^^^^^^^^^^^^^^
@@ -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;);
    |     ^^^^^^^^^^^^^^^^^^
@@ -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;);
    |     ^^^^^^^^^^^^^^^^^^^^
@@ -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);
    |              ^^^^^^^^^^^^
@@ -140,7 +131,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:61:15
+  --> $DIR/proc-macro-gates.rs:60:15
    |
 LL |     let _x = [empty!(3)];
    |               ^^^^^^^^^
@@ -148,6 +139,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 17 previous errors
+error: aborting due to 16 previous errors
 
 For more information about this error, try `rustc --explain E0658`.