Skip to content

Commit

Permalink
clippy: warn disallowed_methods for std::env::var and friends
Browse files Browse the repository at this point in the history
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
  • Loading branch information
weihanglo committed Mar 17, 2023
1 parent f2f4496 commit 9e3bb85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
disallowed-methods = [
{ path = "std::env::var", reason = "Use `Config::get_env` instead. See rust-lang/cargo#11588" },
{ path = "std::env::var_os", reason = "Use `Config::get_env_os` instead. See rust-lang/cargo#11588" },
{ path = "std::env::vars", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
{ path = "std::env::vars_os", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
]
1 change: 1 addition & 0 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(rust_2018_idioms)] // while we're getting used to 2018
#![allow(clippy::all)]
#![warn(clippy::disallowed_methods)]

use cargo::util::toml::StringOrVec;
use cargo::util::CliError;
Expand Down
1 change: 1 addition & 0 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Due to some of the default clippy lints being somewhat subjective and not
// necessarily an improvement, we prefer to not use them at this time.
#![allow(clippy::all)]
#![warn(clippy::disallowed_methods)]
#![warn(clippy::self_named_module_files)]
#![allow(rustdoc::private_intra_doc_links)]

Expand Down

0 comments on commit 9e3bb85

Please sign in to comment.