Skip to content

Commit

Permalink
clippy: allow usages of std::env::{var,var_os} by exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Mar 10, 2023
1 parent 959819c commit a00a551
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::disallowed_methods)]

use flate2::{Compression, GzBuilder};
use std::ffi::OsStr;
use std::fs;
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
// If we're opting into backtraces, mention that build dependencies' backtraces can
// be improved by requesting debuginfo to be built, if we're not building with
// debuginfo already.
#[allow(clippy::disallowed_methods)]
if let Ok(show_backtraces) = std::env::var("RUST_BACKTRACE") {
if !built_with_debuginfo && show_backtraces != "0" {
build_error_context.push_str(&format!(
Expand Down Expand Up @@ -727,6 +728,7 @@ impl BuildOutput {
None => return false,
Some(n) => n,
};
#[allow(clippy::disallowed_methods)]
std::env::var("RUSTC_BOOTSTRAP")
.map_or(false, |var| var.split(',').any(|s| s == name))
};
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,11 @@ impl CliUnstable {

/// Returns the current release channel ("stable", "beta", "nightly", "dev").
pub fn channel() -> String {
#[allow(clippy::disallowed_methods)]
if let Ok(override_channel) = env::var("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS") {
return override_channel;
}
#[allow(clippy::disallowed_methods)]
if let Ok(staging) = env::var("RUSTC_BOOTSTRAP") {
if staging == "1" {
return "dev".to_string();
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl ResolverProgress {
// Architectures that do not have a modern processor, hardware emulation, etc.
// In the test code we have `slow_cpu_multiplier`, but that is not accessible here.
#[cfg(debug_assertions)]
#[allow(clippy::disallowed_methods)]
slow_cpu_multiplier: std::env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER")
.ok()
.and_then(|m| m.parse().ok())
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl TtyWidth {
/// Returns the width of the terminal to use for diagnostics (which is
/// relayed to rustc via `--diagnostic-width`).
pub fn diagnostic_terminal_width(&self) -> Option<usize> {
#[allow(clippy::disallowed_methods)]
if let Ok(width) = std::env::var("__CARGO_TEST_TTY_WIDTH_DO_NOT_USE_THIS") {
return Some(width.parse().unwrap());
}
Expand Down
9 changes: 6 additions & 3 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,12 @@ impl SourceId {
_ => return false,
}
let url = self.inner.url.as_str();
url == CRATES_IO_INDEX
|| url == CRATES_IO_HTTP_INDEX
|| std::env::var("__CARGO_TEST_CRATES_IO_URL_DO_NOT_USE_THIS").as_deref() == Ok(url)
if url == CRATES_IO_INDEX || url == CRATES_IO_HTTP_INDEX {
true
} else {
#[allow(clippy::disallowed_methods)]
std::env::var("__CARGO_TEST_CRATES_IO_URL_DO_NOT_USE_THIS").map_or(false, |v| v == url)
}
}

/// Hashes `self`.
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ to prevent this issue from happening.
/// Returns `None` if `fix` is not being run (not in proxy mode). Returns
/// `Some(...)` if in `fix` proxy mode
pub fn fix_get_proxy_lock_addr() -> Option<String> {
#[allow(clippy::disallowed_methods)]
env::var(FIX_ENV).ok()
}

Expand Down Expand Up @@ -847,8 +848,10 @@ impl FixArgs {
}

let file = file.ok_or_else(|| anyhow::anyhow!("could not find .rs file in rustc args"))?;
#[allow(clippy::disallowed_methods)]
let idioms = env::var(IDIOMS_ENV).is_ok();

#[allow(clippy::disallowed_methods)]
let prepare_for_edition = env::var(EDITION_ENV).ok().map(|_| {
enabled_edition
.unwrap_or(Edition::Edition2015)
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod imp {
// when-cargo-is-killed-subprocesses-are-also-killed, but that requires
// one cargo spawned to become its own session leader, so we do that
// here.
#[allow(clippy::disallowed_methods)]
if env::var("__CARGO_TEST_SETSID_PLEASE_DONT_USE_ELSEWHERE").is_ok() {
libc::setsid();
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Profiler {
}

fn enabled_level() -> Option<usize> {
#[allow(clippy::disallowed_methods)]
env::var("CARGO_PROFILE").ok().and_then(|s| s.parse().ok())
}

Expand Down

0 comments on commit a00a551

Please sign in to comment.