]> git.lizzy.rs Git - rust.git/commitdiff
block_def_map: add a few macro tests
authorJonas Schievink <jonasschievink@gmail.com>
Thu, 28 Jan 2021 17:53:35 +0000 (18:53 +0100)
committerJonas Schievink <jonasschievink@gmail.com>
Thu, 28 Jan 2021 17:53:35 +0000 (18:53 +0100)
crates/hir_def/src/nameres/tests/block.rs

index 470ca593e199f5e9369394d2ea0e382ea0b5ed54..6cc65951352cc0ac6449ab5a911988051e929d57 100644 (file)
@@ -121,3 +121,66 @@ struct Struct {}
         "#]],
     );
 }
+
+#[test]
+fn legacy_macro_items() {
+    // Checks that legacy-scoped `macro_rules!` from parent namespaces are resolved and expanded
+    // correctly.
+    check_at(
+        r#"
+macro_rules! hit {
+    () => {
+        struct Hit {}
+    }
+}
+
+fn f() {
+    hit!();
+    $0
+}
+"#,
+        expect![[r#"
+            block scope
+            Hit: t
+            crate
+            f: v
+        "#]],
+    );
+}
+
+#[test]
+fn macro_resolve() {
+    check_at(
+        r#"
+//- /lib.rs crate:lib deps:core
+use core::mark;
+
+fn f() {
+    fn nested() {
+        mark::hit!(Hit);
+        $0
+    }
+}
+//- /core.rs crate:core
+pub mod mark {
+    #[macro_export]
+    macro_rules! _hit {
+        ($name:ident) => {
+            struct $name {}
+        }
+    }
+
+    pub use crate::_hit as hit;
+}
+"#,
+        expect![[r#"
+            block scope
+            Hit: t
+            block scope
+            nested: v
+            crate
+            f: v
+            mark: t
+        "#]],
+    );
+}