aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_expand')
-rw-r--r--crates/hir_expand/src/builtin_macro.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 7f4db106d..7bb42be6c 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -417,17 +417,25 @@ fn env_expand(
417 Err(e) => return ExpandResult::only_err(e), 417 Err(e) => return ExpandResult::only_err(e),
418 }; 418 };
419 419
420 // FIXME: 420 let mut err = None;
421 // If the environment variable is not defined int rustc, then a compilation error will be emitted. 421 let s = get_env_inner(db, arg_id, &key).unwrap_or_else(|| {
422 // We might do the same if we fully support all other stuffs. 422 // The only variable rust-analyzer ever sets is `OUT_DIR`, so only diagnose that to avoid
423 // But for now on, we should return some dummy string for better type infer purpose. 423 // unnecessary diagnostics for eg. `CARGO_PKG_NAME`.
424 // However, we cannot use an empty string here, because for 424 if key == "OUT_DIR" {
425 // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become 425 err = Some(mbe::ExpandError::Other(
426 // `include!("foo.rs"), which might go to infinite loop 426 r#"`OUT_DIR` not set, enable "load out dirs from check" to fix"#.into(),
427 let s = get_env_inner(db, arg_id, &key).unwrap_or_else(|| "__RA_UNIMPLEMENTED__".to_string()); 427 ));
428 }
429
430 // If the variable is unset, still return a dummy string to help type inference along.
431 // We cannot use an empty string here, because for
432 // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become
433 // `include!("foo.rs"), which might go to infinite loop
434 "__RA_UNIMPLEMENTED__".to_string()
435 });
428 let expanded = quote! { #s }; 436 let expanded = quote! { #s };
429 437
430 ExpandResult::ok(Some((expanded, FragmentKind::Expr))) 438 ExpandResult { value: Some((expanded, FragmentKind::Expr)), err }
431} 439}
432 440
433fn option_env_expand( 441fn option_env_expand(