about summary refs log tree commit diff
path: root/tests/ui/macros/stringify.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-08-06 17:16:40 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-08-16 09:07:55 +1000
commit9d31f86f0d1482b4e5084579238009cc5d98e49f (patch)
tree902fd3a835b94ecd4fa7466743fea17d4897ca1a /tests/ui/macros/stringify.rs
parentfe460ac28b63ea97685f131c318af99158a5f87c (diff)
downloadrust-9d31f86f0d1482b4e5084579238009cc5d98e49f.tar.gz
rust-9d31f86f0d1482b4e5084579238009cc5d98e49f.zip
Overhaul token collection.
This commit does the following.

- Renames `collect_tokens_trailing_token` as `collect_tokens`, because
  (a) it's annoying long, and (b) the `_trailing_token` bit is less
  accurate now that its types have changed.

- In `collect_tokens`, adds a `Option<CollectPos>` argument and a
  `UsePreAttrPos` in the return type of `f`. These are used in
  `parse_expr_force_collect` (for vanilla expressions) and in
  `parse_stmt_without_recovery` (for two different cases of expression
  statements). Together these ensure are enough to fix all the problems
  with token collection and assoc expressions. The changes to the
  `stringify.rs` test demonstrate some of these.

- Adds a new test. The code in this test was causing an assertion
  failure prior to this commit, due to an invalid `NodeRange`.

The extra complexity is annoying, but necessary to fix the existing
problems.
Diffstat (limited to 'tests/ui/macros/stringify.rs')
-rw-r--r--tests/ui/macros/stringify.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs
index a8b73ac7e15..37409dd066d 100644
--- a/tests/ui/macros/stringify.rs
+++ b/tests/ui/macros/stringify.rs
@@ -51,14 +51,6 @@ macro_rules! c1 {
     };
 }
 
-// FIXME: temporary
-macro_rules! c2 {
-    ($frag:ident, [$($tt:tt)*], $s1:literal, $s2:literal) => {
-        assert_eq!($frag!($($tt)*), $s1);
-        assert_eq!(stringify!($($tt)*), $s2);
-    };
-}
-
 #[test]
 fn test_block() {
     c1!(block, [ {} ], "{}");
@@ -344,10 +336,10 @@ fn test_expr() {
     // Ones involving attributes.
     c1!(expr, [ #[aa] 1 ], "#[aa] 1");
     c1!(expr, [ #[aa] #[bb] x ], "#[aa] #[bb] x");
-    c2!(expr, [ #[aa] 1 + 2 ], "1 + 2", "#[aa] 1 + 2"); // FIXME
-    c2!(expr, [ #[aa] x + 2 ], "x + 2", "#[aa] x + 2"); // FIXME
-    c2!(expr, [ #[aa] 1 / #[bb] 2 ], "1 / #[bb] 2", "#[aa] 1 / #[bb] 2"); // FIXME
-    c2!(expr, [ #[aa] x / #[bb] 2 ], "x / #[bb] 2", "#[aa] x / #[bb] 2"); // FIXME
+    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)");
@@ -659,10 +651,10 @@ fn test_stmt() {
     // Ones involving attributes.
     c1!(stmt, [ #[aa] 1 ], "#[aa] 1");
     c1!(stmt, [ #[aa] #[bb] x ], "#[aa] #[bb] x");
-    c2!(stmt, [ #[aa] 1 as u32 ], "1 as u32", "#[aa] 1 as u32"); // FIXME
-    c2!(stmt, [ #[aa] x as u32 ], "x as u32", "#[aa] x as u32"); // FIXME
-    c2!(stmt, [ #[aa] 1 .. #[bb] 2 ], "1 .. #[bb] 2", "#[aa] 1 .. #[bb] 2"); // FIXME
-    c2!(stmt, [ #[aa] x .. #[bb] 2 ], "x .. #[bb] 2", "#[aa] x .. #[bb] 2"); // FIXME
+    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)");