-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add environment variable query #130883
base: master
Are you sure you want to change the base?
Add environment variable query #130883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||
use std::any::Any; | ||||
use std::env::VarError; | ||||
use std::ffi::OsString; | ||||
use std::io::{self, BufWriter, Write}; | ||||
use std::path::{Path, PathBuf}; | ||||
|
@@ -336,6 +337,20 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { | |||
) | ||||
} | ||||
|
||||
fn env_var(tcx: TyCtxt<'_>, key: Symbol) -> Option<Symbol> { | ||||
let var = match std::env::var(key.as_str()) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there something similar to Clippy's See also rust-lang/cargo#11588. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's some rustc-internal lints in https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/internal.rs |
||||
Ok(var) => Some(Symbol::intern(&var)), | ||||
Err(VarError::NotPresent) => None, | ||||
Err(VarError::NotUnicode(var)) => { | ||||
tcx.dcx().emit_err(errors::EnvVarNotUnicode { key, var }); | ||||
None | ||||
} | ||||
}; | ||||
// Also add the variable to Cargo's dependency tracking | ||||
tcx.sess.psess.env_depinfo.borrow_mut().insert((key, var)); | ||||
Comment on lines
+349
to
+350
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, a complication here is that this query will only work with the dependency info files that Cargo reads if it's called before rust/compiler/rustc_driver_impl/src/lib.rs Line 437 in a3f76a2
So everything done during Is it possible for us to move the |
||||
var | ||||
} | ||||
|
||||
// Returns all the paths that correspond to generated files. | ||||
fn generated_output_paths( | ||||
tcx: TyCtxt<'_>, | ||||
|
@@ -623,6 +638,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| { | |||
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal()); | ||||
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1; | ||||
providers.early_lint_checks = early_lint_checks; | ||||
providers.env_var = env_var; | ||||
proc_macro_decls::provide(providers); | ||||
rustc_const_eval::provide(providers); | ||||
rustc_middle::hir::provide(providers); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unsure where to put the query definition, so I just put it in the same file as some other general queries.