Uh oh!
There was an error while loading. Please reload this page.
proc_macro: Add API for tracked access to environment variables - #74653
Conversation
rust-highfive
commented
Jul 22, 2020
@petrochenkov: no appropriate reviewer found, use r? to override |
petrochenkov
commented
Jul 22, 2020
Mark-Simulacrum
commented
Jul 22, 2020
❤️ Thank you for following through on this. cc @dtolnay to get libs sign-off on the unstable API. |
dtolnay
left a comment
There was a problem hiding this comment.
Seems fine. Please file a tracking issue.
Some notes to address here or otherwise add to the tracking issue to address before stabilizing:
Ideally the signature would match the function in std::env but I see that putting OsStr in depinfo is possibly hard. Don't filepaths go into depinfo though? Those are OS strings so what do we do there, and would it be possible to do that for here as well?
If there is a possibility we want to expose some other things from std::env, maybe
proc_macro::tracked_env::varwould be more appropriate to keep those together.
petrochenkov
commented
Jul 23, 2020
They do, and they use lossy There's some discussion about non-UTF-8 cases in environment variables in #71858, looks like the general stance is that they don't matter.
I thought about the signature a bit, assuming we are keeping UTF-8, the alternatives to pubfntracked_env_var(var:implAsRef<OsStr> + AsRef<str> + Copy) -> Result<String,VarError>{let value = env::var(var);// Need `Copy` to avoid consuming `var` here
bridge::client::FreeFunctions::track_env_var(var, value.as_deref().ok());
value
}or // Without `Copy`pubfntracked_env_var(var:implAsRef<OsStr> + AsRef<str>) -> Result<String,VarError>{let var = &var.to_string();// Have to convert into an owned stringlet value = env::var(var);
bridge::client::FreeFunctions::track_env_var(var, value.as_deref().ok());
value
}The original |
petrochenkov
commented
Jul 23, 2020
Yeah, sounds reasonable. |
dtolnay
left a comment
There was a problem hiding this comment.
I would feel more comfortable with var: impl AsRef<OsStr> + AsRef<str>. That leaves the possibility to remove AsRef<str> bound backward compatibly to match the std::env::var signature.
petrochenkov
commented
Jul 26, 2020
Updated.
|
dtolnay
commented
Jul 26, 2020
@bors r+ |
bors
commented
Jul 26, 2020
📌 Commit 62c9fa9 has been approved by |
bors
commented
Jul 27, 2020
bors
commented
Jul 27, 2020
☀️ Test successful - checks-actions, checks-azure |
rust-highfive
commented
Jul 27, 2020
📣 Toolstate changed by #74653! Tested on commit 1841fb9. 💔 rls on windows: test-pass → build-fail (cc @Xanewok). |
Tested on commit rust-lang/rust@1841fb9. Direct link to PR: <rust-lang/rust#74653> 💔 rls on windows: test-pass → build-fail (cc @Xanewok). 💔 rls on linux: test-pass → build-fail (cc @Xanewok). 💔 rustfmt on windows: test-pass → build-fail (cc @topecongiro@calebcartwright). 💔 rustfmt on linux: test-pass → build-fail (cc @topecongiro@calebcartwright).
Continuation of #71858.
proc_macro::tracked_env::varis similar to regularenv::varcalled from a proc macro, except that it also adds the accessed variable to depinfo.