diff options
Diffstat (limited to 'crates/hir_def/src/nameres/tests')
-rw-r--r-- | crates/hir_def/src/nameres/tests/macros.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index e0fb8bdef..0851c3b7d 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs | |||
@@ -667,3 +667,76 @@ b! { static = #[] (); } | |||
667 | "#]], | 667 | "#]], |
668 | ); | 668 | ); |
669 | } | 669 | } |
670 | |||
671 | #[test] | ||
672 | fn resolves_proc_macros() { | ||
673 | check( | ||
674 | r" | ||
675 | struct TokenStream; | ||
676 | |||
677 | #[proc_macro] | ||
678 | pub fn function_like_macro(args: TokenStream) -> TokenStream { | ||
679 | args | ||
680 | } | ||
681 | |||
682 | #[proc_macro_attribute] | ||
683 | pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream { | ||
684 | item | ||
685 | } | ||
686 | |||
687 | #[proc_macro_derive(DummyTrait)] | ||
688 | pub fn derive_macro(_item: TokenStream) -> TokenStream { | ||
689 | TokenStream | ||
690 | } | ||
691 | ", | ||
692 | expect![[r#" | ||
693 | crate | ||
694 | DummyTrait: m | ||
695 | TokenStream: t v | ||
696 | attribute_macro: v m | ||
697 | derive_macro: v | ||
698 | function_like_macro: v m | ||
699 | "#]], | ||
700 | ); | ||
701 | } | ||
702 | |||
703 | #[test] | ||
704 | fn proc_macro_censoring() { | ||
705 | // Make sure that only proc macros are publicly exported from proc-macro crates. | ||
706 | |||
707 | check( | ||
708 | r" | ||
709 | //- /main.rs crate:main deps:macros | ||
710 | pub use macros::*; | ||
711 | |||
712 | //- /macros.rs crate:macros | ||
713 | pub struct TokenStream; | ||
714 | |||
715 | #[proc_macro] | ||
716 | pub fn function_like_macro(args: TokenStream) -> TokenStream { | ||
717 | args | ||
718 | } | ||
719 | |||
720 | #[proc_macro_attribute] | ||
721 | pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream { | ||
722 | item | ||
723 | } | ||
724 | |||
725 | #[proc_macro_derive(DummyTrait)] | ||
726 | pub fn derive_macro(_item: TokenStream) -> TokenStream { | ||
727 | TokenStream | ||
728 | } | ||
729 | |||
730 | #[macro_export] | ||
731 | macro_rules! mbe { | ||
732 | () => {}; | ||
733 | } | ||
734 | ", | ||
735 | expect![[r#" | ||
736 | crate | ||
737 | DummyTrait: m | ||
738 | attribute_macro: m | ||
739 | function_like_macro: m | ||
740 | "#]], | ||
741 | ); | ||
742 | } | ||