From 9f1a3a131b3a32ac86f5d230357fff94b17c34cb Mon Sep 17 00:00:00 2001 From: fleetingbytes <7075397+fleetingbytes@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:09:15 +0200 Subject: [PATCH 1/6] Update env.rs Remove `Errors` section from `var_os` documentation --- library/std/src/env.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 183f9ab3b08f6..3fcf96c761bf2 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -242,16 +242,6 @@ fn _var(key: &OsStr) -> Result { /// is valid Unicode. If you want to have an error on invalid UTF-8, /// use the [`var`] function instead. /// -/// # Errors -/// -/// This function returns an error 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 an error if the environment variable's value contains -/// the NUL character. -/// /// # Examples /// /// ``` From c252f0d4044876509e08be27f82dbf0f33bc5cc2 Mon Sep 17 00:00:00 2001 From: fleetingbytes <7075397+fleetingbytes@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:46:43 +0200 Subject: [PATCH 2/6] add situation where var_os returns None Re-introduced some of the former errors as situations where `None` is returned. --- library/std/src/env.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 3fcf96c761bf2..63338bd5876bf 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -236,7 +236,13 @@ fn _var(key: &OsStr) -> Result { } /// Fetches the environment variable `key` from the current process, returning -/// [`None`] if the variable isn't set or there's another error. +/// [`None`] in the following situations: +/// +/// - the environment variable isn't set +/// - the environment variable's name contains +/// the equal sign character (`=`) or the NUL character +/// +/// If this is not desired, consider using [`var_os`]. /// /// Note that the method will not check if the environment variable /// is valid Unicode. If you want to have an error on invalid UTF-8, From 5618c8efd7925b6f1b5d8e5b30228f065606e841 Mon Sep 17 00:00:00 2001 From: fleetingbytes <7075397+fleetingbytes@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:13:30 +0200 Subject: [PATCH 3/6] remove self-reference in var_os doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: León Orell Valerian Liehr --- library/std/src/env.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 63338bd5876bf..c9f8e617df602 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -242,7 +242,6 @@ fn _var(key: &OsStr) -> Result { /// - the environment variable's name contains /// the equal sign character (`=`) or the NUL character /// -/// If this is not desired, consider using [`var_os`]. /// /// Note that the method will not check if the environment variable /// is valid Unicode. If you want to have an error on invalid UTF-8, From a450557a54b871ce182900cde3894a3494876e1e Mon Sep 17 00:00:00 2001 From: fleetingbytes <7075397+fleetingbytes@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:17:43 +0200 Subject: [PATCH 4/6] Remove redundant empty line one is enough --- library/std/src/env.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index c9f8e617df602..1345469d8b329 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -242,7 +242,6 @@ fn _var(key: &OsStr) -> Result { /// - the environment variable's name contains /// the equal sign character (`=`) or the NUL character /// -/// /// Note that the method will not check if the environment variable /// is valid Unicode. If you want to have an error on invalid UTF-8, /// use the [`var`] function instead. From 4cb73cc7d014d9848c0e00531cbd9dcc561e4253 Mon Sep 17 00:00:00 2001 From: fleetingbytes <7075397+fleetingbytes@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:30:20 +0200 Subject: [PATCH 5/6] Preserve potential mood for equal or NUL sign Original `var_os` description said that it _may_ return an error if the value contains `=` or NUL. Let's make no promises on the `None` return value in these situation either, keep it in the [potential mood](https://en.wikipedia.org/wiki/Grammatical_mood#Potential). --- library/std/src/env.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 1345469d8b329..51e5c60ed294e 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -236,11 +236,9 @@ fn _var(key: &OsStr) -> Result { } /// Fetches the environment variable `key` from the current process, returning -/// [`None`] in the following situations: -/// -/// - the environment variable isn't set -/// - the environment variable's name contains -/// the equal sign character (`=`) or the NUL character +/// [`None`] if the environment variable isn't set. It may return `None` also +/// if the environment variable's name contains +/// the equal sign character (`=`) or the NUL character. /// /// Note that the method will not check if the environment variable /// is valid Unicode. If you want to have an error on invalid UTF-8, From 7d269633b1e254ad21f23994bbf04a6a8296abf7 Mon Sep 17 00:00:00 2001 From: fleetingbytes <7075397+fleetingbytes@users.noreply.github.com> Date: Tue, 11 Apr 2023 04:13:35 +0200 Subject: [PATCH 6/6] Break up long first paragraph Further referring to `var_os` as a "function" (like in `var`), rather than "method". --- library/std/src/env.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 51e5c60ed294e..74394694d43ca 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -236,11 +236,12 @@ fn _var(key: &OsStr) -> Result { } /// Fetches the environment variable `key` from the current process, returning -/// [`None`] if the environment variable isn't set. It may return `None` also -/// if the environment variable's name contains +/// [`None`] if the variable isn't set or if there is another error. +/// +/// It may return `None` if the environment variable's name contains /// the equal sign character (`=`) or the NUL character. /// -/// Note that the method will not check if the environment variable +/// Note that this function will not check if the environment variable /// is valid Unicode. If you want to have an error on invalid UTF-8, /// use the [`var`] function instead. ///