diff options
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 18 |
2 files changed, 24 insertions, 1 deletions
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 | |||
279 | let call_site = call_id.as_file().original_file(db); | 279 | let call_site = call_id.as_file().original_file(db); |
280 | let path = RelativePath::new(&path); | 280 | let path = RelativePath::new(&path); |
281 | 281 | ||
282 | db.resolve_relative_path(call_site, &path) | 282 | let res = db.resolve_relative_path(call_site, &path)?; |
283 | // Prevent include itself | ||
284 | if res == call_site { | ||
285 | return None; | ||
286 | } | ||
287 | Some(res) | ||
283 | } | 288 | } |
284 | 289 | ||
285 | fn include_expand( | 290 | fn include_expand( |
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index c86733ac3..ffa78b046 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -511,6 +511,24 @@ fn bar() -> u32 {0} | |||
511 | } | 511 | } |
512 | 512 | ||
513 | #[test] | 513 | #[test] |
514 | fn infer_builtin_macros_include_itself_should_failed() { | ||
515 | let (db, pos) = TestDB::with_position( | ||
516 | r#" | ||
517 | //- /main.rs | ||
518 | #[rustc_builtin_macro] | ||
519 | macro_rules! include {() => {}} | ||
520 | |||
521 | include!("main.rs"); | ||
522 | |||
523 | fn main() { | ||
524 | 0<|> | ||
525 | } | ||
526 | "#, | ||
527 | ); | ||
528 | assert_eq!("i32", type_at_pos(&db, pos)); | ||
529 | } | ||
530 | |||
531 | #[test] | ||
514 | fn infer_builtin_macros_concat_with_lazy() { | 532 | fn infer_builtin_macros_concat_with_lazy() { |
515 | assert_snapshot!( | 533 | assert_snapshot!( |
516 | infer(r#" | 534 | infer(r#" |