- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.7k
 
          clippy: warn disallowed_methods for std::env::var and friends 
          #11828
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 
           r? @ehuss (rustbot has picked a reviewer for you, use r? to override)  | 
    
a00a551    to
    290c0dd      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to make decisions on these things (in this order):
- Should we leverage 
clippy::disallowed_methodsin our codebase? - Do we want to have a centralized place for exceptions of env var access?
 
          
 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).