From dfa3a3f017c39f745f06d96de11359b97c76fc47 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 18 Sep 2020 16:37:12 +0200 Subject: Add test --- crates/hir_def/src/nameres/tests/macros.rs | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/hir_def/src/nameres/tests') diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index e0fb8bdef..98cb5a0fd 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs @@ -667,3 +667,35 @@ b! { static = #[] (); } "#]], ); } + +#[test] +fn resolves_proc_macros() { + check( + r" + struct TokenStream; + + #[proc_macro] + pub fn function_like_macro(args: TokenStream) -> TokenStream { + args + } + + #[proc_macro_attribute] + pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream { + item + } + + #[proc_macro_derive(DummyTrait)] + pub fn derive_macro(_item: TokenStream) -> TokenStream { + TokenStream + } + ", + expect![[r#" + crate + DummyTrait: m + TokenStream: t v + attribute_macro: v m + derive_macro: v + function_like_macro: v m + "#]], + ); +} -- cgit v1.2.3 From baab72e611fa985c2e62e964f3a48ad31367220f Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 18 Sep 2020 17:50:04 +0200 Subject: Reduce visibility of non-proc-macros proc-macro crates only export proc-macros, but currently other items are also considered public (and show up in completion) --- crates/hir_def/src/nameres/tests/macros.rs | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'crates/hir_def/src/nameres/tests') diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index 98cb5a0fd..0851c3b7d 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs @@ -699,3 +699,44 @@ fn resolves_proc_macros() { "#]], ); } + +#[test] +fn proc_macro_censoring() { + // Make sure that only proc macros are publicly exported from proc-macro crates. + + check( + r" + //- /main.rs crate:main deps:macros + pub use macros::*; + + //- /macros.rs crate:macros + pub struct TokenStream; + + #[proc_macro] + pub fn function_like_macro(args: TokenStream) -> TokenStream { + args + } + + #[proc_macro_attribute] + pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream { + item + } + + #[proc_macro_derive(DummyTrait)] + pub fn derive_macro(_item: TokenStream) -> TokenStream { + TokenStream + } + + #[macro_export] + macro_rules! mbe { + () => {}; + } + ", + expect![[r#" + crate + DummyTrait: m + attribute_macro: m + function_like_macro: m + "#]], + ); +} -- cgit v1.2.3