From 92cc6c9816d8dd3793cd810d83f47cbff927494e Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 21 Mar 2020 23:55:20 +0800 Subject: Add recursive limit in expression macro expansion --- crates/ra_hir_def/src/body.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 27a297e8b..5f9d53ecb 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -30,6 +30,7 @@ pub(crate) struct Expander { hygiene: Hygiene, ast_id_map: Arc, module: ModuleId, + recursive_limit: usize, } impl Expander { @@ -41,7 +42,7 @@ impl Expander { let crate_def_map = db.crate_def_map(module.krate); let hygiene = Hygiene::new(db.upcast(), current_file_id); let ast_id_map = db.ast_id_map(current_file_id); - Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module } + Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module, recursive_limit: 0 } } pub(crate) fn enter_expand( @@ -50,6 +51,10 @@ impl Expander { local_scope: Option<&ItemScope>, macro_call: ast::MacroCall, ) -> Option<(Mark, T)> { + if self.recursive_limit > 1024 { + return None; + } + let macro_call = InFile::new(self.current_file_id, ¯o_call); if let Some(call_id) = macro_call.as_call_id(db, |path| { @@ -73,6 +78,7 @@ impl Expander { self.hygiene = Hygiene::new(db.upcast(), file_id); self.current_file_id = file_id; self.ast_id_map = db.ast_id_map(file_id); + self.recursive_limit += 1; return Some((mark, expr)); } @@ -88,6 +94,7 @@ impl Expander { self.hygiene = Hygiene::new(db.upcast(), mark.file_id); self.current_file_id = mark.file_id; self.ast_id_map = mem::take(&mut mark.ast_id_map); + self.recursive_limit -= 1; mark.bomb.defuse(); } -- cgit v1.2.3