diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-14 17:32:43 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-14 17:32:43 +0100 |
commit | a50c64a4f13b47de7fa08eb3e6ff222a96389b28 (patch) | |
tree | 30e2cf89854d4f522896bdd7aaedb141f169ef83 /crates/ra_hir_def/src | |
parent | ff6cf4f84914529f112b5bbefbefb2fb33c7f67a (diff) | |
parent | d47834ee1b8fce7956272e27c9403021940fec8e (diff) |
Merge #5379
5379: Guard against infinite macro expansions r=matklad a=matklad
closes #4463
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/macros.rs | 24 |
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] | ||
665 | fn macro_expansion_overflow() { | ||
666 | mark::check!(macro_expansion_overflow); | ||
667 | compute_crate_def_map( | ||
668 | " | ||
669 | macro_rules! a { | ||
670 | ($e:expr; $($t:tt)*) => { | ||
671 | b!($($t)*); | ||
672 | }; | ||
673 | () => {}; | ||
674 | } | ||
675 | |||
676 | macro_rules! b { | ||
677 | (static = $e:expr; $($t:tt)*) => { | ||
678 | a!($e; $($t)*); | ||
679 | }; | ||
680 | () => {}; | ||
681 | } | ||
682 | |||
683 | b! { static = #[] (); } | ||
684 | ", | ||
685 | ); | ||
686 | } | ||