Skip to content

Commit efd3094

Browse files
committed
Auto merge of rust-lang#14890 - HKalbasi:dev, r=HKalbasi
use `::core` instead of `$crate` in `option_env!` fix rust-lang#14885
2 parents 1c65613 + b0f1766 commit efd3094

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn main() { option_env!("TEST_ENV_VAR"); }
9797
#[rustc_builtin_macro]
9898
macro_rules! option_env {() => {}}
9999
100-
fn main() { $crate::option::Option::None:: < &str>; }
100+
fn main() { ::core::option::Option::None:: < &str>; }
101101
"#]],
102102
);
103103
}

crates/hir-expand/src/builtin_fn_macro.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,10 @@ fn option_env_expand(
820820
)
821821
}
822822
};
823-
823+
// FIXME: Use `DOLLAR_CRATE` when that works in eager macros.
824824
let expanded = match get_env_inner(db, arg_id, &key) {
825-
None => quote! { #DOLLAR_CRATE::option::Option::None::<&str> },
826-
Some(s) => quote! { #DOLLAR_CRATE::option::Option::Some(#s) },
825+
None => quote! { ::core::option::Option::None::<&str> },
826+
Some(s) => quote! { ::core::option::Option::Some(#s) },
827827
};
828828

829829
ExpandResult::ok(ExpandedEager::new(expanded))

crates/hir-ty/src/tests/macros.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -947,21 +947,34 @@ fn infer_builtin_macros_concat_with_lazy() {
947947

948948
#[test]
949949
fn infer_builtin_macros_env() {
950-
check_infer(
950+
check_types(
951951
r#"
952952
//- /main.rs env:foo=bar
953953
#[rustc_builtin_macro]
954954
macro_rules! env {() => {}}
955955
956956
fn main() {
957957
let x = env!("foo");
958+
//^ &str
959+
}
960+
"#,
961+
);
962+
}
963+
964+
#[test]
965+
fn infer_builtin_macros_option_env() {
966+
check_types(
967+
r#"
968+
//- minicore: option
969+
//- /main.rs env:foo=bar
970+
#[rustc_builtin_macro]
971+
macro_rules! option_env {() => {}}
972+
973+
fn main() {
974+
let x = option_env!("foo");
975+
//^ Option<&str>
958976
}
959977
"#,
960-
expect![[r#"
961-
!0..22 '"__RA_...TED__"': &str
962-
62..90 '{ ...o"); }': ()
963-
72..73 'x': &str
964-
"#]],
965978
);
966979
}
967980

0 commit comments

Comments
 (0)