clippy: warn disallowed_methods for std::env::var and friends #11828
clippy: warn disallowed_methods for std::env::var and friends #11828bors merged 3 commits intorust-lang:masterfrom
disallowed_methods for std::env::var and friends #11828Conversation
|
r? @ehuss (rustbot has picked a reviewer for you, use r? to override) |
a00a551 to
290c0dd
Compare
I think it can be a useful tool
I lean towards "no" but am fine if we do end up centralizing. Its also something we can always change later with minimal impact, so its not a big deal either way. |
|
Before starting the scrutiny of all environment variable access. Let's see if we agree on this: @rfcbot poll T-cargo "Should we leverage |
|
Team member @weihanglo has asked teams: T-cargo, for consensus on:
|
|
☔ The latest upstream changes (presumably #11824) made this pull request unmergeable. Please resolve the merge conflicts. |
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
290c0dd to
f78d081
Compare
See comments above for each usage about why it is allowed.
f78d081 to
5ccca80
Compare
| fn from_env<K: AsRef<str>>(key: K) -> LocalFingerprint { | ||
| let key = key.as_ref(); | ||
| let var = key.to_owned(); | ||
| let val = env::var(key).ok(); |
There was a problem hiding this comment.
Confirmed that on the current master cargo, when changing variable inside [env] config table, build script won't rerun.
std::env::{var,var_os}disallowed_methods for std::env::var and friends
|
This is ready to review. The examination of all usages of |
|
@bors r+ |
|
☀️ Test successful - checks-actions |
Update cargo 11 commits in 4a3c588b1f0a8e2dc8dd8789dbf3b6a71b02ed49..15d090969743630bff549a1b068bcaa8174e5ee3 2023-03-14 14:05:36 +0000 to 2023-03-21 17:54:28 +0000 - docs(contrib): Move higher level resolver docs into doc comments (rust-lang/cargo#11870) - docs(contrib): Pull impl info out of architecture (rust-lang/cargo#11869) - Update curl-sys (rust-lang/cargo#11871) - Poll loop fixes (rust-lang/cargo#11624) - clippy: warn `disallowed_methods` for `std::env::var` and friends (rust-lang/cargo#11828) - Add --ignore-rust-version flag to cargo install (rust-lang/cargo#11859) - Handle case mismatches when looking up env vars in the Config snapshot (rust-lang/cargo#11824) - align semantics of generated vcs ignore files (rust-lang/cargo#11855) - Add more information to wait-for-publish (rust-lang/cargo#11713) - docs: Address warnings (rust-lang/cargo#11856) - docs(contrib): Create a file overview in the nightly docs (rust-lang/cargo#11850)
Update cargo 11 commits in 4a3c588b1f0a8e2dc8dd8789dbf3b6a71b02ed49..15d090969743630bff549a1b068bcaa8174e5ee3 2023-03-14 14:05:36 +0000 to 2023-03-21 17:54:28 +0000 - docs(contrib): Move higher level resolver docs into doc comments (rust-lang/cargo#11870) - docs(contrib): Pull impl info out of architecture (rust-lang/cargo#11869) - Update curl-sys (rust-lang/cargo#11871) - Poll loop fixes (rust-lang/cargo#11624) - clippy: warn `disallowed_methods` for `std::env::var` and friends (rust-lang/cargo#11828) - Add --ignore-rust-version flag to cargo install (rust-lang/cargo#11859) - Handle case mismatches when looking up env vars in the Config snapshot (rust-lang/cargo#11824) - align semantics of generated vcs ignore files (rust-lang/cargo#11855) - Add more information to wait-for-publish (rust-lang/cargo#11713) - docs: Address warnings (rust-lang/cargo#11856) - docs(contrib): Create a file overview in the nightly docs (rust-lang/cargo#11850)
What does this PR try to resolve?
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_methodslint, helping us enforce the rule.I am trying to dogfood tools from rust-lang org :)
How should we test and review this PR?
We need to scrutinize each usage of
std::env::varandstd::env::var_os. Please review comments above each usage of those.Additional information
Some variables are read from snapshot starting from #11727 might need double checks. See #11588 (comment).