about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-11-24 14:47:49 -0500
committerAaron Hill <aa1ronham@gmail.com>2020-11-24 16:38:58 -0500
commit9c9f40656dadf3c2a05b2d5add875f5d0d3541d8 (patch)
tree944fac25493affccbc839cda51f024829f001cd2 /src/test
parente9546bdbaf5794e8cb9a20541c483b8f8f6eb56f (diff)
downloadrust-9c9f40656dadf3c2a05b2d5add875f5d0d3541d8.tar.gz
rust-9c9f40656dadf3c2a05b2d5add875f5d0d3541d8.zip
Invoke attributes on the statement for statement items
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/proc-macro/allowed-attr-stmt-expr.rs59
-rw-r--r--src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout187
-rw-r--r--src/test/ui/proc-macro/attr-stmt-expr.rs32
-rw-r--r--src/test/ui/proc-macro/attr-stmt-expr.stderr4
-rw-r--r--src/test/ui/proc-macro/attr-stmt-expr.stdout187
-rw-r--r--src/test/ui/proc-macro/keep-expr-tokens.rs9
-rw-r--r--src/test/ui/proc-macro/keep-expr-tokens.stderr4
-rw-r--r--src/test/ui/proc-macro/keep-expr-tokens.stdout46
8 files changed, 524 insertions, 4 deletions
diff --git a/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs b/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs
new file mode 100644
index 00000000000..03c10a43248
--- /dev/null
+++ b/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs
@@ -0,0 +1,59 @@
+// aux-build:attr-stmt-expr.rs
+// aux-build:test-macros.rs
+// compile-flags: -Z span-debug
+// check-pass
+
+#![feature(proc_macro_hygiene)]
+#![feature(stmt_expr_attributes)]
+#![feature(rustc_attrs)]
+#![allow(dead_code)]
+
+#![no_std] // Don't load unnecessary hygiene information from std
+extern crate std;
+
+extern crate attr_stmt_expr;
+extern crate test_macros;
+use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
+use test_macros::print_attr;
+use std::println;
+
+fn print_str(string: &'static str) {
+    // macros are handled a bit differently
+    #[expect_print_expr]
+    println!("{}", string)
+}
+
+macro_rules! make_stmt {
+    ($stmt:stmt) => {
+        $stmt
+    }
+}
+
+macro_rules! second_make_stmt {
+    ($stmt:stmt) => {
+        make_stmt!($stmt);
+    }
+}
+
+
+fn main() {
+    make_stmt!(struct Foo {});
+
+    #[print_attr]
+    #[expect_let]
+    let string = "Hello, world!";
+
+    #[print_attr]
+    #[expect_print_stmt]
+    println!("{}", string);
+
+    #[print_attr]
+    second_make_stmt!(#[allow(dead_code)] struct Bar {});
+
+    #[print_attr]
+    #[rustc_dummy]
+    struct Other {};
+
+    #[expect_expr]
+    print_str("string")
+}
diff --git a/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout b/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout
new file mode 100644
index 00000000000..0c7ac4fb682
--- /dev/null
+++ b/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout
@@ -0,0 +1,187 @@
+PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ;
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "expect_let",
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "let",
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "string",
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: '=',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Literal {
+        kind: Str,
+        symbol: "Hello, world!",
+        suffix: None,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: ';',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
+PRINT-ATTR INPUT (DISPLAY): #[expect_print_stmt] println ! ("{}", string) ;
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "expect_print_stmt",
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "println",
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: '!',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Parenthesis,
+        stream: TokenStream [
+            Literal {
+                kind: Str,
+                symbol: "{}",
+                suffix: None,
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Punct {
+                ch: ',',
+                spacing: Alone,
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Ident {
+                ident: "string",
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: ';',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
+PRINT-ATTR INPUT (DISPLAY): second_make_stmt ! (#[allow(dead_code)] struct Bar { }) ;
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Ident {
+        ident: "second_make_stmt",
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: '!',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Parenthesis,
+        stream: TokenStream [
+            Punct {
+                ch: '#',
+                spacing: Alone,
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Group {
+                delimiter: Bracket,
+                stream: TokenStream [
+                    Ident {
+                        ident: "allow",
+                        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+                    },
+                    Group {
+                        delimiter: Parenthesis,
+                        stream: TokenStream [
+                            Ident {
+                                ident: "dead_code",
+                                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+                            },
+                        ],
+                        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+                    },
+                ],
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Ident {
+                ident: "struct",
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Ident {
+                ident: "Bar",
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Group {
+                delimiter: Brace,
+                stream: TokenStream [],
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: ';',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
+PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { }
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "rustc_dummy",
+                span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "struct",
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "Other",
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Brace,
+        stream: TokenStream [],
+        span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
diff --git a/src/test/ui/proc-macro/attr-stmt-expr.rs b/src/test/ui/proc-macro/attr-stmt-expr.rs
index 14a392db4e1..ca1b163c986 100644
--- a/src/test/ui/proc-macro/attr-stmt-expr.rs
+++ b/src/test/ui/proc-macro/attr-stmt-expr.rs
@@ -1,8 +1,17 @@
 // aux-build:attr-stmt-expr.rs
+// aux-build:test-macros.rs
+// compile-flags: -Z span-debug
 
 #![feature(proc_macro_hygiene)]
+#![feature(rustc_attrs)]
 
+#![no_std] // Don't load unnecessary hygiene information from std
+extern crate std;
+extern crate test_macros;
 extern crate attr_stmt_expr;
+
+use test_macros::print_attr;
+use std::println;
 use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
 
 fn print_str(string: &'static str) {
@@ -13,13 +22,36 @@ fn print_str(string: &'static str) {
     println!("{}", string)
 }
 
+macro_rules! make_stmt {
+    ($stmt:stmt) => {
+        $stmt
+    }
+}
+
+macro_rules! second_make_stmt {
+    ($stmt:stmt) => {
+        make_stmt!($stmt);
+    }
+}
+
 fn main() {
+    make_stmt!(struct Foo {});
+
+    #[print_attr]
     #[expect_let]
     let string = "Hello, world!";
 
+    #[print_attr]
     #[expect_print_stmt]
     println!("{}", string);
 
+    #[print_attr]
+    second_make_stmt!(#[allow(dead_code)] struct Bar {});
+
+    #[print_attr]
+    #[rustc_dummy]
+    struct Other {}
+
     #[expect_expr]
     //~^ ERROR attributes on expressions are experimental
     //~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
diff --git a/src/test/ui/proc-macro/attr-stmt-expr.stderr b/src/test/ui/proc-macro/attr-stmt-expr.stderr
index 0d6f247cf83..7bd60e8ee77 100644
--- a/src/test/ui/proc-macro/attr-stmt-expr.stderr
+++ b/src/test/ui/proc-macro/attr-stmt-expr.stderr
@@ -1,5 +1,5 @@
 error[E0658]: attributes on expressions are experimental
-  --> $DIR/attr-stmt-expr.rs:10:5
+  --> $DIR/attr-stmt-expr.rs:19:5
    |
 LL |     #[expect_print_expr]
    |     ^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL |     #[expect_print_expr]
    = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
 
 error[E0658]: attributes on expressions are experimental
-  --> $DIR/attr-stmt-expr.rs:23:5
+  --> $DIR/attr-stmt-expr.rs:55:5
    |
 LL |     #[expect_expr]
    |     ^^^^^^^^^^^^^^
diff --git a/src/test/ui/proc-macro/attr-stmt-expr.stdout b/src/test/ui/proc-macro/attr-stmt-expr.stdout
new file mode 100644
index 00000000000..5c1b586725b
--- /dev/null
+++ b/src/test/ui/proc-macro/attr-stmt-expr.stdout
@@ -0,0 +1,187 @@
+PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ;
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "expect_let",
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "let",
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "string",
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: '=',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Literal {
+        kind: Str,
+        symbol: "Hello, world!",
+        suffix: None,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: ';',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
+PRINT-ATTR INPUT (DISPLAY): #[expect_print_stmt] println ! ("{}", string) ;
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "expect_print_stmt",
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "println",
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: '!',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Parenthesis,
+        stream: TokenStream [
+            Literal {
+                kind: Str,
+                symbol: "{}",
+                suffix: None,
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Punct {
+                ch: ',',
+                spacing: Alone,
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Ident {
+                ident: "string",
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: ';',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
+PRINT-ATTR INPUT (DISPLAY): second_make_stmt ! (#[allow(dead_code)] struct Bar { }) ;
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Ident {
+        ident: "second_make_stmt",
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: '!',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Parenthesis,
+        stream: TokenStream [
+            Punct {
+                ch: '#',
+                spacing: Alone,
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Group {
+                delimiter: Bracket,
+                stream: TokenStream [
+                    Ident {
+                        ident: "allow",
+                        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+                    },
+                    Group {
+                        delimiter: Parenthesis,
+                        stream: TokenStream [
+                            Ident {
+                                ident: "dead_code",
+                                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+                            },
+                        ],
+                        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+                    },
+                ],
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Ident {
+                ident: "struct",
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Ident {
+                ident: "Bar",
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+            Group {
+                delimiter: Brace,
+                stream: TokenStream [],
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Punct {
+        ch: ';',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
+PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { }
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "rustc_dummy",
+                span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+            },
+        ],
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "struct",
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Ident {
+        ident: "Other",
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+    Group {
+        delimiter: Brace,
+        stream: TokenStream [],
+        span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0),
+    },
+]
diff --git a/src/test/ui/proc-macro/keep-expr-tokens.rs b/src/test/ui/proc-macro/keep-expr-tokens.rs
index 888785363cf..0bf889a855d 100644
--- a/src/test/ui/proc-macro/keep-expr-tokens.rs
+++ b/src/test/ui/proc-macro/keep-expr-tokens.rs
@@ -1,7 +1,12 @@
 // aux-build:test-macros.rs
+// compile-flags: -Z span-debug
 
 #![feature(stmt_expr_attributes)]
 #![feature(proc_macro_hygiene)]
+#![feature(rustc_attrs)]
+
+#![no_std] // Don't load unnecessary hygiene information from std
+extern crate std;
 
 extern crate test_macros;
 
@@ -12,4 +17,8 @@ fn main() {
     for item in missing_fn() {} //~ ERROR cannot find
 
     (#[recollect_attr] #[recollect_attr] ((#[recollect_attr] bad))); //~ ERROR cannot
+
+    #[test_macros::print_attr]
+    #[rustc_dummy]
+    { 1 +1; } // Don't change the weird spacing of the '+'
 }
diff --git a/src/test/ui/proc-macro/keep-expr-tokens.stderr b/src/test/ui/proc-macro/keep-expr-tokens.stderr
index 2be8c0184da..11052d11c25 100644
--- a/src/test/ui/proc-macro/keep-expr-tokens.stderr
+++ b/src/test/ui/proc-macro/keep-expr-tokens.stderr
@@ -1,11 +1,11 @@
 error[E0425]: cannot find function `missing_fn` in this scope
-  --> $DIR/keep-expr-tokens.rs:12:17
+  --> $DIR/keep-expr-tokens.rs:17:17
    |
 LL |     for item in missing_fn() {}
    |                 ^^^^^^^^^^ not found in this scope
 
 error[E0425]: cannot find value `bad` in this scope
-  --> $DIR/keep-expr-tokens.rs:14:62
+  --> $DIR/keep-expr-tokens.rs:19:62
    |
 LL |     (#[recollect_attr] #[recollect_attr] ((#[recollect_attr] bad)));
    |                                                              ^^^ not found in this scope
diff --git a/src/test/ui/proc-macro/keep-expr-tokens.stdout b/src/test/ui/proc-macro/keep-expr-tokens.stdout
new file mode 100644
index 00000000000..fcd72a0e017
--- /dev/null
+++ b/src/test/ui/proc-macro/keep-expr-tokens.stdout
@@ -0,0 +1,46 @@
+PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] { 1 + 1 ; }
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Punct {
+        ch: '#',
+        spacing: Alone,
+        span: $DIR/keep-expr-tokens.rs:22:5: 22:6 (#0),
+    },
+    Group {
+        delimiter: Bracket,
+        stream: TokenStream [
+            Ident {
+                ident: "rustc_dummy",
+                span: $DIR/keep-expr-tokens.rs:22:7: 22:18 (#0),
+            },
+        ],
+        span: $DIR/keep-expr-tokens.rs:22:6: 22:19 (#0),
+    },
+    Group {
+        delimiter: Brace,
+        stream: TokenStream [
+            Literal {
+                kind: Integer,
+                symbol: "1",
+                suffix: None,
+                span: $DIR/keep-expr-tokens.rs:23:7: 23:8 (#0),
+            },
+            Punct {
+                ch: '+',
+                spacing: Alone,
+                span: $DIR/keep-expr-tokens.rs:23:9: 23:10 (#0),
+            },
+            Literal {
+                kind: Integer,
+                symbol: "1",
+                suffix: None,
+                span: $DIR/keep-expr-tokens.rs:23:10: 23:11 (#0),
+            },
+            Punct {
+                ch: ';',
+                spacing: Alone,
+                span: $DIR/keep-expr-tokens.rs:23:11: 23:12 (#0),
+            },
+        ],
+        span: $DIR/keep-expr-tokens.rs:23:5: 23:14 (#0),
+    },
+]