diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 5af26f953a..34b90a666c 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 aece1515b5..c62152d26a 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 + "###); +}