diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_builtin_macros/src/env.rs | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_builtin_macros/src/env.rs')
-rw-r--r-- | compiler/rustc_builtin_macros/src/env.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_builtin_macros/src/env.rs b/compiler/rustc_builtin_macros/src/env.rs index 8c2fa6ee9..d772642b8 100644 --- a/compiler/rustc_builtin_macros/src/env.rs +++ b/compiler/rustc_builtin_macros/src/env.rs @@ -13,6 +13,16 @@ use thin_vec::thin_vec; use crate::errors; +fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Option<Symbol> { + let var = var.as_str(); + if let Some(value) = cx.sess.opts.logical_env.get(var) { + return Some(Symbol::intern(value)); + } + // If the environment variable was not defined with the `--env` option, we try to retrieve it + // from rustc's environment. + env::var(var).ok().as_deref().map(Symbol::intern) +} + pub fn expand_option_env<'cx>( cx: &'cx mut ExtCtxt<'_>, sp: Span, @@ -23,7 +33,7 @@ pub fn expand_option_env<'cx>( }; let sp = cx.with_def_site_ctxt(sp); - let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern); + let value = lookup_env(cx, var); cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value)); let e = match value { None => { @@ -77,7 +87,7 @@ pub fn expand_env<'cx>( }; let span = cx.with_def_site_ctxt(sp); - let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern); + let value = lookup_env(cx, var); cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value)); let e = match value { None => { |