From 18f88ad10bed9f8d82a3a67c2bb9eb23995641a0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 7 Mar 2020 16:25:43 +0800 Subject: Prevent include! macro include itself --- crates/ra_hir_expand/src/builtin_macro.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_expand') diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index a57e9285f..9bc33cfa8 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs @@ -279,7 +279,12 @@ fn relative_file(db: &dyn AstDatabase, call_id: MacroCallId, path: &str) -> Opti let call_site = call_id.as_file().original_file(db); let path = RelativePath::new(&path); - db.resolve_relative_path(call_site, &path) + let res = db.resolve_relative_path(call_site, &path)?; + // Prevent include itself + if res == call_site { + return None; + } + Some(res) } fn include_expand( -- cgit v1.2.3