From bcc9a28734e731d9823bf0d6516176a71f3d4627 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Sep 2019 21:43:41 +0300 Subject: don't cycle when processing macros from prelude in prelude --- crates/ra_hir/src/nameres/collector.rs | 6 ++++-- crates/ra_hir/src/nameres/tests/macros.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 5af26f953..34b90a666 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -525,8 +525,10 @@ where fn collect(&mut self, items: &[raw::RawItem]) { // Prelude module is always considered to be `#[macro_use]`. if let Some(prelude_module) = self.def_collector.def_map.prelude { - tested_by!(prelude_is_macro_use); - self.def_collector.import_all_macros_exported(prelude_module); + if prelude_module.krate != self.def_collector.def_map.krate { + tested_by!(prelude_is_macro_use); + self.def_collector.import_all_macros_exported(prelude_module); + } } // This should be processed eagerly instead of deferred to resolving. diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index aece1515b..c62152d26 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -248,3 +248,32 @@ fn prelude_is_macro_use() { ⋮Baz: t v "###); } + +#[test] +fn prelude_cycle() { + let map = def_map( + " + //- /lib.rs + #[prelude_import] + use self::prelude::*; + + declare_mod!(); + + mod prelude { + macro_rules! declare_mod { + () => (mod foo {}) + } + } + ", + ); + assert_snapshot!(map, @r###" + ⋮crate + ⋮foo: t + ⋮prelude: t + ⋮ + ⋮crate::prelude + ⋮declare_mod: m + ⋮ + ⋮crate::foo + "###); +} -- cgit v1.2.3