diff options
author | Aleksey Kladov <[email protected]> | 2019-09-07 19:43:41 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-07 19:47:59 +0100 |
commit | bcc9a28734e731d9823bf0d6516176a71f3d4627 (patch) | |
tree | d4e1fc3861ffcbe815e650377600dd926362498b /crates/ra_hir/src | |
parent | 4a89a7c9026dc3df4466f7b10c666186830d38f6 (diff) |
don't cycle when processing macros from prelude in prelude
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 6 | ||||
-rw-r--r-- | 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 | |||
525 | fn collect(&mut self, items: &[raw::RawItem]) { | 525 | fn collect(&mut self, items: &[raw::RawItem]) { |
526 | // Prelude module is always considered to be `#[macro_use]`. | 526 | // Prelude module is always considered to be `#[macro_use]`. |
527 | if let Some(prelude_module) = self.def_collector.def_map.prelude { | 527 | if let Some(prelude_module) = self.def_collector.def_map.prelude { |
528 | tested_by!(prelude_is_macro_use); | 528 | if prelude_module.krate != self.def_collector.def_map.krate { |
529 | self.def_collector.import_all_macros_exported(prelude_module); | 529 | tested_by!(prelude_is_macro_use); |
530 | self.def_collector.import_all_macros_exported(prelude_module); | ||
531 | } | ||
530 | } | 532 | } |
531 | 533 | ||
532 | // This should be processed eagerly instead of deferred to resolving. | 534 | // 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() { | |||
248 | ⋮Baz: t v | 248 | ⋮Baz: t v |
249 | "###); | 249 | "###); |
250 | } | 250 | } |
251 | |||
252 | #[test] | ||
253 | fn prelude_cycle() { | ||
254 | let map = def_map( | ||
255 | " | ||
256 | //- /lib.rs | ||
257 | #[prelude_import] | ||
258 | use self::prelude::*; | ||
259 | |||
260 | declare_mod!(); | ||
261 | |||
262 | mod prelude { | ||
263 | macro_rules! declare_mod { | ||
264 | () => (mod foo {}) | ||
265 | } | ||
266 | } | ||
267 | ", | ||
268 | ); | ||
269 | assert_snapshot!(map, @r###" | ||
270 | ⋮crate | ||
271 | ⋮foo: t | ||
272 | ⋮prelude: t | ||
273 | ⋮ | ||
274 | ⋮crate::prelude | ||
275 | ⋮declare_mod: m | ||
276 | ⋮ | ||
277 | ⋮crate::foo | ||
278 | "###); | ||
279 | } | ||