@@ -417,17 +417,25 @@ fn env_expand(
417417 Err ( e) => return ExpandResult :: only_err ( e) ,
418418 } ;
419419
420- // FIXME:
421- // If the environment variable is not defined int rustc, then a compilation error will be emitted.
422- // We might do the same if we fully support all other stuffs.
423- // But for now on, we should return some dummy string for better type infer purpose.
424- // However, we cannot use an empty string here, because for
425- // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become
426- // `include!("foo.rs"), which might go to infinite loop
427- let s = get_env_inner ( db, arg_id, & key) . unwrap_or_else ( || "__RA_UNIMPLEMENTED__" . to_string ( ) ) ;
420+ let mut err = None ;
421+ let s = get_env_inner ( db, arg_id, & key) . unwrap_or_else ( || {
422+ // The only variable rust-analyzer ever sets is `OUT_DIR`, so only diagnose that to avoid
423+ // unnecessary diagnostics for eg. `CARGO_PKG_NAME`.
424+ if key == "OUT_DIR" {
425+ err = Some ( mbe:: ExpandError :: Other (
426+ r#"`OUT_DIR` not set, enable "load out dirs from check" to fix"# . into ( ) ,
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+ } ) ;
428436 let expanded = quote ! { #s } ;
429437
430- ExpandResult :: ok ( Some ( ( expanded, FragmentKind :: Expr ) ) )
438+ ExpandResult { value : Some ( ( expanded, FragmentKind :: Expr ) ) , err }
431439}
432440
433441fn option_env_expand (
0 commit comments