Repository: rust-lang/rust-analyzer (rust)

Issue:
Unknown type with `option_env` macro
```Rust
let x = option_env!("CI");
   //^ {unknown}
```
The strange part is that if I use `inline macro` assist, it will work (after manually replacing `$crate` with `core`):
```Rust
let x = core::option::Option::None:: < &str>;
  //^ Option<&str>
```

Pull request description:
use `::core` instead of `$crate` in `option_env!`
fix #14885 

Patch:
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index 0640ba774b..7ce5b02314 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -820,10 +820,10 @@ fn option_env_expand(
             )
         }
     };
-
+    // FIXME: Use `DOLLAR_CRATE` when that works in eager macros.
     let expanded = match get_env_inner(db, arg_id, &key) {
-        None => quote! { #DOLLAR_CRATE::option::Option::None::<&str> },
-        Some(s) => quote! { #DOLLAR_CRATE::option::Option::Some(#s) },
+        None => quote! { ::core::option::Option::None::<&str> },
+        Some(s) => quote! { ::core::option::Option::Some(#s) },
     };
 
     ExpandResult::ok(ExpandedEager::new(expanded))


Test patch:
diff --git a/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs b/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
index 13aa6130be..006d292992 100644
--- a/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
+++ b/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
@@ -97,7 +97,7 @@ fn main() { option_env!("TEST_ENV_VAR"); }
 #[rustc_builtin_macro]
 macro_rules! option_env {() => {}}
 
-fn main() { $crate::option::Option::None:: < &str>; }
+fn main() { ::core::option::Option::None:: < &str>; }
 "#]],
     );
 }
diff --git a/crates/hir-ty/src/tests/macros.rs b/crates/hir-ty/src/tests/macros.rs
index 9377a3a5f2..772bd3e536 100644
--- a/crates/hir-ty/src/tests/macros.rs
+++ b/crates/hir-ty/src/tests/macros.rs
@@ -947,7 +947,7 @@ fn infer_builtin_macros_concat_with_lazy() {
 
 #[test]
 fn infer_builtin_macros_env() {
-    check_infer(
+    check_types(
         r#"
         //- /main.rs env:foo=bar
         #[rustc_builtin_macro]
@@ -955,13 +955,26 @@ fn infer_builtin_macros_env() {
 
         fn main() {
             let x = env!("foo");
+              //^ &str
+        }
+        "#,
+    );
+}
+
+#[test]
+fn infer_builtin_macros_option_env() {
+    check_types(
+        r#"
+        //- minicore: option
+        //- /main.rs env:foo=bar
+        #[rustc_builtin_macro]
+        macro_rules! option_env {() => {}}
+
+        fn main() {
+            let x = option_env!("foo");
+              //^ Option<&str>
         }
         "#,
-        expect![[r#"
-            !0..22 '"__RA_...TED__"': &str
-            62..90 '{     ...o"); }': ()
-            72..73 'x': &str
-        "#]],
     );
 }