-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
docs: add stdlib env::var(_os) panic #63461
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
/// | ||
/// This function may panic if `key` is empty, contains an ASCII equals sign | ||
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL | ||
/// character. |
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.
NUL character is repeated twice in both of these?
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.
This is copied verbatim from the underlying functions called, which state they may crash when either the key or the value contain a null byte.
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.
Oh, I missed the key/value distinction.
This looks great to me. @bors r+ rollup |
📌 Commit af5625d has been approved by |
…iplett docs: add stdlib env::var(_os) panic Closes rust-lang#63456
Rollup of 10 pull requests Successful merges: - #62108 (Use sharded maps for queries) - #63297 (Improve pointer offset method docs) - #63306 (Adapt AddRetag for shallow retagging) - #63406 (Suggest using a qualified path in patterns with inconsistent bindings) - #63431 (Revert "Simplify MIR generation for logical ops") - #63449 (resolve: Remove remaining special cases from built-in macros) - #63461 (docs: add stdlib env::var(_os) panic) - #63473 (Regression test for #56870) - #63474 (Add tests for issue #53598 and #57700) - #63480 (Fixes #63477) Failed merges: r? @ghost
@@ -182,6 +182,12 @@ impl fmt::Debug for VarsOs { | |||
/// * Environment variable is not present | |||
/// * Environment variable is not valid unicode | |||
/// | |||
/// # Panics | |||
/// | |||
/// This function may panic if `key` is empty, contains an ASCII equals sign |
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.
Is it "may panic" or "panics" (definitive)?
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.
The function relies on std::sys::os
, so the behaviour differs by operating system. We could update the docs to make this clearer.
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.
Hmm, I'm not sure what is the practice in this case. Maybe "may" is fine.
BTW, I do wonder why this behavior was chosen, that if key
contains a nul then it panics. It makes sense for setting a var, but when getting, it makes more sense to me that it just return None
. The code comment in the unix implementation seems to agree, I think..
rust/src/libstd/sys/unix/os.rs
Lines 469 to 471 in ad7c55e
// environment variables with a nul byte can't be set, so their value is | |
// always None as well | |
let k = CString::new(k.as_bytes())?; |
…iplett docs: add stdlib env::var(_os) panic Closes rust-lang#63456
Rollup of 9 pull requests Successful merges: - #62108 (Use sharded maps for queries) - #63297 (Improve pointer offset method docs) - #63406 (Suggest using a qualified path in patterns with inconsistent bindings) - #63431 (Revert "Simplify MIR generation for logical ops") - #63449 (resolve: Remove remaining special cases from built-in macros) - #63461 (docs: add stdlib env::var(_os) panic) - #63473 (Regression test for #56870) - #63474 (Add tests for issue #53598 and #57700) - #63480 (Fixes #63477) Failed merges: r? @ghost
@@ -182,6 +182,12 @@ impl fmt::Debug for VarsOs { | |||
/// * Environment variable is not present | |||
/// * Environment variable is not valid unicode | |||
/// | |||
/// # Panics | |||
/// | |||
/// This function may panic if `key` is empty, contains an ASCII equals sign |
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.
Another question: the function documentation says that when key
is not present, an error is returned, not a panic. So is the "is empty" here correct?
Closes #63456