From d5a7c459662a4868f4a38cbafb72dce7885e027d Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Fri, 9 Aug 2024 14:26:18 -0400 Subject: [PATCH 1/2] doc: std::env::var: Returns None for names with '=' or NUL byte The documentation incorrectly stated that std::env::var could return an error for variable names containing '=' or the NUL byte. Copy the correct documentation from var_os. var_os was fixed in Commit 8a7a665, Pull Request #109894, which closed Issue #109893. This documentation was incorrectly added in commit f2c0f292, which replaced a panic in var_os by returning None, but documented the change as "May error if ...". Reference the specific error values and link to them. --- library/std/src/env.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 50ae83090c7..215b7b03f04 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -198,13 +198,16 @@ impl fmt::Debug for VarsOs { /// /// # Errors /// -/// This function will return an error if the environment variable isn't set. +/// This function returns [`VarError::NotPresent`] if the environment variable +/// isn't set. /// -/// This function may return an error if the environment variable's name contains -/// the equal sign character (`=`) or the NUL character. +/// This function may return [`VarError::NotPresent`] if the +/// environment variable's name contains the equal sign character (`=`) or the +/// NUL character. /// -/// This function will return an error if the environment variable's value is -/// not valid Unicode. If this is not desired, consider using [`var_os`]. +/// This function will return [`VarError::NotUnicode`] if the environment +/// variable's value is not valid Unicode. If this is not desired, consider +/// using [`var_os`]. /// /// # Examples /// From b0023f5a417374aad980422b3f437f133676d4ef Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Sun, 18 Aug 2024 10:43:36 -0400 Subject: [PATCH 2/2] code review improvements --- library/std/src/env.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 215b7b03f04..bbe191181c5 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -198,16 +198,12 @@ impl fmt::Debug for VarsOs { /// /// # Errors /// -/// This function returns [`VarError::NotPresent`] if the environment variable -/// isn't set. +/// Returns [`VarError::NotPresent`] if: +/// - The variable is not set. +/// - The variable's name contains an equal sign or NUL (`'='` or `'\0'`). /// -/// This function may return [`VarError::NotPresent`] if the -/// environment variable's name contains the equal sign character (`=`) or the -/// NUL character. -/// -/// This function will return [`VarError::NotUnicode`] if the environment -/// variable's value is not valid Unicode. If this is not desired, consider -/// using [`var_os`]. +/// Returns [`VarError::NotUnicode`] if the variable's value is not valid +/// Unicode. If this is not desired, consider using [`var_os`]. /// /// # Examples ///