about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/attributes/assoc-expr.rs42
-rw-r--r--tests/ui/macros/stringify.rs47
2 files changed, 87 insertions, 2 deletions
diff --git a/tests/ui/attributes/assoc-expr.rs b/tests/ui/attributes/assoc-expr.rs
new file mode 100644
index 00000000000..f39557d2ef0
--- /dev/null
+++ b/tests/ui/attributes/assoc-expr.rs
@@ -0,0 +1,42 @@
+//@ check-pass
+// This test triggered an assertion failure in token collection due to
+// mishandling of attributes on associative expressions.
+
+#![feature(cfg_eval)]
+#![feature(rustc_attrs)]
+#![feature(stmt_expr_attributes)]
+#![allow(internal_features)]
+
+fn main() {}
+
+#[cfg_eval]
+struct Foo1(
+    [ bool; {
+        let _x = 30;
+        #[cfg_attr(unix, rustc_dummy(aa))] 1
+    } ]
+);
+
+#[cfg_eval]
+struct Foo12(
+    [ bool; {
+        let _x = 30;
+        #[cfg_attr(unix, rustc_dummy(bb))] 1 + 2
+    } ]
+);
+
+#[cfg_eval]
+struct Foox(
+    [ bool; {
+        let _x = 30;
+        #[cfg_attr(unix, rustc_dummy(cc))] _x
+    } ]
+);
+
+#[cfg_eval]
+struct Foox2(
+    [ bool; {
+        let _x = 30;
+        #[cfg_attr(unix, rustc_dummy(dd))] _x + 2
+    } ]
+);
diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs
index f06c1f99069..37409dd066d 100644
--- a/tests/ui/macros/stringify.rs
+++ b/tests/ui/macros/stringify.rs
@@ -33,8 +33,6 @@ macro_rules! stmt { ($stmt:stmt) => { stringify!($stmt) }; }
 macro_rules! ty { ($ty:ty) => { stringify!($ty) }; }
 macro_rules! vis { ($vis:vis) => { stringify!($vis) }; }
 
-// Use this when AST pretty-printing and TokenStream pretty-printing give
-// the same result (which is preferable.)
 macro_rules! c1 {
     ($frag:ident, [$($tt:tt)*], $s:literal) => {
         // Prior to #125174:
@@ -66,6 +64,8 @@ fn test_block() {
         } ],
         "{ let _; true }"
     );
+
+    // Attributes are not allowed on vanilla blocks.
 }
 
 #[test]
@@ -332,6 +332,20 @@ fn test_expr() {
     // ExprKind::FormatArgs: untestable because this test works pre-expansion.
 
     // ExprKind::Err: untestable.
+
+    // Ones involving attributes.
+    c1!(expr, [ #[aa] 1 ], "#[aa] 1");
+    c1!(expr, [ #[aa] #[bb] x ], "#[aa] #[bb] x");
+    c1!(expr, [ #[aa] 1 + 2 ], "#[aa] 1 + 2");
+    c1!(expr, [ #[aa] x + 2 ], "#[aa] x + 2");
+    c1!(expr, [ #[aa] 1 / #[bb] 2 ], "#[aa] 1 / #[bb] 2");
+    c1!(expr, [ #[aa] x / #[bb] 2 ], "#[aa] x / #[bb] 2");
+    c1!(expr, [ 1 << #[bb] 2 ], "1 << #[bb] 2");
+    c1!(expr, [ x << #[bb] 2 ], "x << #[bb] 2");
+    c1!(expr, [ #[aa] (1 + 2) ], "#[aa] (1 + 2)");
+    c1!(expr, [ #[aa] #[bb] (x + 2) ], "#[aa] #[bb] (x + 2)");
+    c1!(expr, [ #[aa] x[0].p ], "#[aa] x[0].p");
+    c1!(expr, [ #[aa] { #![bb] 0 } ], "#[aa] { #![bb] 0 }");
 }
 
 #[test]
@@ -484,6 +498,11 @@ fn test_item() {
         "macro_rules! stringify { () => {}; }"
     );
     c1!(item, [ pub macro stringify() {} ], "pub macro stringify() {}");
+
+    // Ones involving attributes.
+    c1!(item, [ #[aa] mod m; ], "#[aa] mod m;");
+    c1!(item, [ mod m { #![bb] } ], "mod m { #![bb] }");
+    c1!(item, [ #[aa] mod m { #![bb] } ], "#[aa] mod m { #![bb] }");
 }
 
 #[test]
@@ -492,6 +511,8 @@ fn test_meta() {
     c1!(meta, [ k = "v" ], "k = \"v\"");
     c1!(meta, [ list(k1, k2 = "v") ], "list(k1, k2 = \"v\")");
     c1!(meta, [ serde::k ], "serde::k");
+
+    // Attributes are not allowed on metas.
 }
 
 #[test]
@@ -580,6 +601,8 @@ fn test_pat() {
     c1!(pat, [ mac!(...) ], "mac!(...)");
     c1!(pat, [ mac![...] ], "mac![...]");
     c1!(pat, [ mac! { ... } ], "mac! { ... }");
+
+    // Attributes are not allowed on patterns.
 }
 
 #[test]
@@ -593,6 +616,8 @@ fn test_path() {
     c1!(path, [ Self::<'static> ], "Self::<'static>");
     c1!(path, [ Self() ], "Self()");
     c1!(path, [ Self() -> () ], "Self() -> ()");
+
+    // Attributes are not allowed on paths.
 }
 
 #[test]
@@ -622,6 +647,20 @@ fn test_stmt() {
     c1!(stmt, [ mac!(...) ], "mac!(...)");
     c1!(stmt, [ mac![...] ], "mac![...]");
     c1!(stmt, [ mac! { ... } ], "mac! { ... }");
+
+    // Ones involving attributes.
+    c1!(stmt, [ #[aa] 1 ], "#[aa] 1");
+    c1!(stmt, [ #[aa] #[bb] x ], "#[aa] #[bb] x");
+    c1!(stmt, [ #[aa] 1 as u32 ], "#[aa] 1 as u32");
+    c1!(stmt, [ #[aa] x as u32 ], "#[aa] x as u32");
+    c1!(stmt, [ #[aa] 1 .. #[bb] 2 ], "#[aa] 1 .. #[bb] 2");
+    c1!(stmt, [ #[aa] x .. #[bb] 2 ], "#[aa] x .. #[bb] 2");
+    c1!(stmt, [ 1 || #[bb] 2 ], "1 || #[bb] 2");
+    c1!(stmt, [ x || #[bb] 2 ], "x || #[bb] 2");
+    c1!(stmt, [ #[aa] (1 + 2) ], "#[aa] (1 + 2)");
+    c1!(stmt, [ #[aa] #[bb] (x + 2) ], "#[aa] #[bb] (x + 2)");
+    c1!(stmt, [ #[aa] x[0].p ], "#[aa] x[0].p");
+    c1!(stmt, [ #[aa] { #![bb] 0 } ], "#[aa] { #![bb] 0 }");
 }
 
 #[test]
@@ -708,6 +747,8 @@ fn test_ty() {
 
     // TyKind::CVarArgs
     // FIXME: todo
+
+    // Attributes are not allowed on types.
 }
 
 #[test]
@@ -732,6 +773,8 @@ fn test_vis() {
     macro_rules! inherited_vis { ($vis:vis struct) => { vis!($vis) }; }
     assert_eq!(inherited_vis!(struct), "");
     assert_eq!(stringify!(), "");
+
+    // Attributes are not allowed on visibilities.
 }
 
 macro_rules! p {