]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_def/src/macro_expansion_tests/mbe.rs
parameters.split_last()
[rust.git] / crates / hir_def / src / macro_expansion_tests / mbe.rs
index 953750d36052cf9710dda36b7ed25dc6a416c05a..2cd70a84c537fb2f8433b0ebf5b1b73cfc847e5f 100644 (file)
 
 use crate::macro_expansion_tests::check;
 
+#[test]
+fn token_mapping_smoke_test() {
+    check(
+        r#"
+// +tokenids
+macro_rules! f {
+    ( struct $ident:ident ) => {
+        struct $ident {
+            map: ::std::collections::HashSet<()>,
+        }
+    };
+}
+
+// +tokenids
+f!(struct MyTraitMap2);
+"#,
+        expect![[r##"
+// call ids will be shifted by Shift(30)
+// +tokenids
+macro_rules! f {#0
+    (#1 struct#2 $#3ident#4:#5ident#6 )#1 =#7>#8 {#9
+        struct#10 $#11ident#12 {#13
+            map#14:#15 :#16:#17std#18:#19:#20collections#21:#22:#23HashSet#24<#25(#26)#26>#27,#28
+        }#13
+    }#9;#29
+}#0
+
+// // +tokenids
+// f!(struct#1 MyTraitMap2#2);
+struct#10 MyTraitMap2#32 {#13
+    map#14:#15 ::std#18::collections#21::HashSet#24<#25(#26)#26>#27,#28
+}#13
+"##]],
+    );
+}
+
 #[test]
 fn mbe_smoke_test() {
     check(
@@ -49,26 +85,6 @@ fn from(it: Subtree) -> TokenTree {
     );
 }
 
-#[test]
-fn expansion_does_not_parse_as_expression() {
-    check(
-        r#"
-macro_rules! stmts {
-    () => { let _ = 0; }
-}
-
-fn f() { let _ = stmts!(); }
-"#,
-        expect![[r#"
-macro_rules! stmts {
-    () => { let _ = 0; }
-}
-
-fn f() { let _ = /* error: could not convert tokens */; }
-"#]],
-    )
-}
-
 #[test]
 fn wrong_nesting_level() {
     check(