diff options
author | Jonas Schievink <[email protected]> | 2020-12-02 16:03:18 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-03 14:48:29 +0000 |
commit | 4634bfb332897f8478ed885970e7cb21bb9c4fce (patch) | |
tree | eb70d41c024032d1ddcd134fa748b2471bcbc5fa /crates/hir_expand/src | |
parent | 17542d08b4316afd899dabc6c7fc4c66f257dacb (diff) |
Give better diagnostic if `OUT_DIR` is unset
Diffstat (limited to 'crates/hir_expand/src')
-rw-r--r-- | crates/hir_expand/src/builtin_macro.rs | 26 |
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 | ||
433 | fn option_env_expand( | 441 | fn option_env_expand( |