Skip to content

Commit 9e3bb85

Browse files
committed
clippy: warn disallowed_methods for std::env::var and friends
In 11588 we want to avoid reading from environment variables, 11727 did that well. I wonder if we could leverage tools to help with this. Thankfully, clippy has a `disallowed_methods`[1] lint, helping us enforce the rule. [1]: https://rust-lang.github.io/rust-clippy/stable/index.html#disallowed_methods
1 parent f2f4496 commit 9e3bb85

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

clippy.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
disallowed-methods = [
2+
{ path = "std::env::var", reason = "Use `Config::get_env` instead. See rust-lang/cargo#11588" },
3+
{ path = "std::env::var_os", reason = "Use `Config::get_env_os` instead. See rust-lang/cargo#11588" },
4+
{ path = "std::env::vars", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
5+
{ path = "std::env::vars_os", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
6+
]

src/bin/cargo/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms)] // while we're getting used to 2018
22
#![allow(clippy::all)]
3+
#![warn(clippy::disallowed_methods)]
34

45
use cargo::util::toml::StringOrVec;
56
use cargo::util::CliError;

src/cargo/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Due to some of the default clippy lints being somewhat subjective and not
55
// necessarily an improvement, we prefer to not use them at this time.
66
#![allow(clippy::all)]
7+
#![warn(clippy::disallowed_methods)]
78
#![warn(clippy::self_named_module_files)]
89
#![allow(rustdoc::private_intra_doc_links)]
910

0 commit comments

Comments
 (0)