aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs5
-rw-r--r--crates/ra_hir_def/src/nameres/tests/macros.rs24
2 files changed, 29 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index a35ac1024..e55cc1e55 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -717,6 +717,11 @@ impl DefCollector<'_> {
717 macro_call_id: MacroCallId, 717 macro_call_id: MacroCallId,
718 depth: usize, 718 depth: usize,
719 ) { 719 ) {
720 if depth > 100 {
721 mark::hit!(macro_expansion_overflow);
722 log::warn!("macro expansion is too deep");
723 return;
724 }
720 let file_id: HirFileId = macro_call_id.as_file(); 725 let file_id: HirFileId = macro_call_id.as_file();
721 let item_tree = self.db.item_tree(file_id); 726 let item_tree = self.db.item_tree(file_id);
722 let mod_dir = self.mod_dirs[&module_id].clone(); 727 let mod_dir = self.mod_dirs[&module_id].clone();
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs
index 84480d9f6..c52341a07 100644
--- a/crates/ra_hir_def/src/nameres/tests/macros.rs
+++ b/crates/ra_hir_def/src/nameres/tests/macros.rs
@@ -660,3 +660,27 @@ fn expand_multiple_derive() {
660 ); 660 );
661 assert_eq!(map.modules[map.root].scope.impls().len(), 2); 661 assert_eq!(map.modules[map.root].scope.impls().len(), 2);
662} 662}
663
664#[test]
665fn macro_expansion_overflow() {
666 mark::check!(macro_expansion_overflow);
667 compute_crate_def_map(
668 "
669macro_rules! a {
670 ($e:expr; $($t:tt)*) => {
671 b!($($t)*);
672 };
673 () => {};
674}
675
676macro_rules! b {
677 (static = $e:expr; $($t:tt)*) => {
678 a!($e; $($t)*);
679 };
680 () => {};
681}
682
683b! { static = #[] (); }
684",
685 );
686}