From 36c768468729653079ed5c00e759bd12cd02e241 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 7 Mar 2020 12:53:40 +0800 Subject: Use a not so dummy implementation of env macro --- crates/ra_hir_expand/src/builtin_macro.rs | 2 +- crates/ra_hir_ty/src/tests/macros.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 9fc33e4b1..51d54331e 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs @@ -142,7 +142,7 @@ fn env_expand( _tt: &tt::Subtree, ) -> Result { // dummy implementation for type-checking purposes - let expanded = quote! { "" }; + let expanded = quote! { "__RA_UNIMPLEMENTATED__" }; Ok(expanded) } diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 42814941f..c86733ac3 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs @@ -483,6 +483,33 @@ fn bar() -> u32 {0} assert_eq!("u32", type_at_pos(&db, pos)); } +#[test] +fn infer_builtin_macros_include_concat_with_bad_env_should_failed() { + let (db, pos) = TestDB::with_position( + r#" +//- /main.rs +#[rustc_builtin_macro] +macro_rules! include {() => {}} + +#[rustc_builtin_macro] +macro_rules! concat {() => {}} + +#[rustc_builtin_macro] +macro_rules! env {() => {}} + +include!(concat!(env!("OUT_DIR"), "/foo.rs")); + +fn main() { + bar()<|>; +} + +//- /foo.rs +fn bar() -> u32 {0} +"#, + ); + assert_eq!("{unknown}", type_at_pos(&db, pos)); +} + #[test] fn infer_builtin_macros_concat_with_lazy() { assert_snapshot!( -- cgit v1.2.3 From 2e178b5475b156e1876e4e6971c0abd3bdf6c889 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 7 Mar 2020 13:02:54 +0800 Subject: Fix test and add more comment --- crates/ra_hir_expand/src/builtin_macro.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 51d54331e..a57e9285f 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs @@ -142,6 +142,9 @@ fn env_expand( _tt: &tt::Subtree, ) -> Result { // dummy implementation for type-checking purposes + // we cannot use an empty string here, because for + // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become + // `include!("foo.rs"), which maybe infinite loop let expanded = quote! { "__RA_UNIMPLEMENTATED__" }; Ok(expanded) @@ -394,7 +397,7 @@ mod tests { "#, ); - assert_eq!(expanded, "\"\""); + assert_eq!(expanded, "\"__RA_UNIMPLEMENTATED__\""); } #[test] -- cgit v1.2.3