-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Another question: the function documentation says that when |
||
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL | ||
/// character. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
|
@@ -210,6 +216,12 @@ fn _var(key: &OsStr) -> Result<String, VarError> { | |
/// | ||
/// [`None`]: ../option/enum.Option.html#variant.None | ||
/// | ||
/// # Panics | ||
/// | ||
/// 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I missed the key/value distinction. |
||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
|
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 returnNone
. 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