Skip to content

Commit 4cb5b94

Browse files
authored
Use Build::getenv instead of env::var* in anywhere that makes sense (#1103)
1 parent 6fa9ea6 commit 4cb5b94

File tree

10 files changed

+622
-420
lines changed

10 files changed

+622
-420
lines changed

clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
disallowed-methods = [
2+
{ path = "std::env::var_os", reason = "Please use Build::getenv" },
3+
{ path = "std::env::var", reason = "Please use Build::getenv" },
4+
]

dev-tools/cc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::disallowed_methods)]
2+
13
use std::env;
24
use std::fs;
35
use std::path::{Path, PathBuf};

src/bin/gcc-shim.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! It is not intended for users and is not published with the library code to crates.io.
33
44
#![cfg_attr(test, allow(dead_code))]
5+
#![allow(clippy::disallowed_methods)]
56

67
use std::env;
78
use std::fs::File;

src/command_helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) struct CargoOutput {
2727

2828
impl CargoOutput {
2929
pub(crate) fn new() -> Self {
30+
#[allow(clippy::disallowed_methods)]
3031
Self {
3132
metadata: true,
3233
warnings: true,

src/lib.rs

Lines changed: 354 additions & 310 deletions
Large diffs are not rendered by default.

src/tool.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
io::Write,
77
path::{Path, PathBuf},
88
process::{Command, Stdio},
9-
sync::Mutex,
9+
sync::RwLock,
1010
};
1111

1212
use crate::{
@@ -40,7 +40,7 @@ pub struct Tool {
4040
impl Tool {
4141
pub(crate) fn new(
4242
path: PathBuf,
43-
cached_compiler_family: &Mutex<HashMap<Box<Path>, ToolFamily>>,
43+
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
4444
cargo_output: &CargoOutput,
4545
out_dir: Option<&Path>,
4646
) -> Self {
@@ -57,7 +57,7 @@ impl Tool {
5757
pub(crate) fn with_clang_driver(
5858
path: PathBuf,
5959
clang_driver: Option<&str>,
60-
cached_compiler_family: &Mutex<HashMap<Box<Path>, ToolFamily>>,
60+
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
6161
cargo_output: &CargoOutput,
6262
out_dir: Option<&Path>,
6363
) -> Self {
@@ -90,7 +90,7 @@ impl Tool {
9090
path: PathBuf,
9191
clang_driver: Option<&str>,
9292
cuda: bool,
93-
cached_compiler_family: &Mutex<HashMap<Box<Path>, ToolFamily>>,
93+
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
9494
cargo_output: &CargoOutput,
9595
out_dir: Option<&Path>,
9696
) -> Self {
@@ -186,13 +186,13 @@ impl Tool {
186186
}
187187
}
188188
let detect_family = |path: &Path| -> Result<ToolFamily, Error> {
189-
if let Some(family) = cached_compiler_family.lock().unwrap().get(path) {
189+
if let Some(family) = cached_compiler_family.read().unwrap().get(path) {
190190
return Ok(*family);
191191
}
192192

193193
let family = detect_family_inner(path, cargo_output, out_dir)?;
194194
cached_compiler_family
195-
.lock()
195+
.write()
196196
.unwrap()
197197
.insert(path.into(), family);
198198
Ok(family)

src/utilities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515
{
1616
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1717
let len = self.slice.len();
18-
for (index, os_str) in self.slice.into_iter().enumerate() {
18+
for (index, os_str) in self.slice.iter().enumerate() {
1919
// TODO: Use OsStr::display once it is stablised,
2020
// Path and OsStr has the same `Display` impl
2121
write!(f, "{}", Path::new(os_str).display())?;

0 commit comments

Comments
 (0)