Skip to content
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

doc: std::env::var: Returns None for names with '=' or NUL byte #128902

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

evanj
Copy link
Contributor

@evanj evanj commented Aug 9, 2024

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 f2c0f29, 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.

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 rust-lang#109894, which
closed Issue rust-lang#109893.

This documentation was incorrectly added in commit f2c0f29, 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.
@rustbot
Copy link
Collaborator

rustbot commented Aug 9, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 9, 2024
Comment on lines 201 to 206
/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we frame this in a way that visibly ORs these two together? like

Suggested change
/// 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 may return [`VarError::NotPresent`] if
/// - the environment variable isn't set
/// - the environment variable's name contains an equals sign or NUL (`=` or `\0`)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could leave it as you have written it since it's copying directly from var_os for the most part, but it feels strange to me that they are being made to match here but one has an # Errors header?

errors header creating this additional visual distinction

There doesn't seem to be, even in this module, consistency in whether that is present on Result-returning functions, or what it documents:

It doesn't seem to make things clearer the way the # Examples header tends to.

Copy link
Member

@workingjubilee workingjubilee Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I bring this up is that for the most part they are self-explanatory variants except the "returns NotPresent if we determine the variable is invalid" happens yes, but is an essentially spurious error, and Option only requires spelling this out because it doesn't attach a direct semantic to the Some or None variants, being a much more "vibe-based" notion of "was available".

This PR description even says None instead of NotPresent, here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestions, thanks! I have pushed a new revision:

  • Uses a bullet list for the error results. This is much clearer, thanks! This makes it look similar to current_dir.
  • Minor tweaks to make the text a bit shorter.

I have left the Errors header, but if you want it removed, I'm happy to do that also. I think the general recommendation is that functions returning a Result should document the errors in an Errors section. Some evidence:

Current rendered version:

errors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, so set_current_dir is the odd one out. That's fine then!

Yes, that looks nicer. Thank you!

@workingjubilee
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 18, 2024

📌 Commit b0023f5 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 18, 2024
…rkingjubilee

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 rust-lang#109894, which closed Issue rust-lang#109893.

This documentation was incorrectly added in commit f2c0f29, 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.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 18, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#125854 (Move ZST ABI handling to `rustc_target`)
 - rust-lang#127623 (fix: fs::remove_dir_all: treat internal ENOENT as success)
 - rust-lang#128084 (Suggest adding Result return type for associated method in E0277.)
 - rust-lang#128902 (doc: std::env::var: Returns None for names with '=' or NUL byte)
 - rust-lang#129187 (bootstrap: fix clean's remove_dir_all implementation)
 - rust-lang#129235 (Check that `#[may_dangle]` is properly applied)
 - rust-lang#129245 (Typo)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 18, 2024
…rkingjubilee

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 rust-lang#109894, which closed Issue rust-lang#109893.

This documentation was incorrectly added in commit f2c0f29, 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.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#128084 (Suggest adding Result return type for associated method in E0277.)
 - rust-lang#128902 (doc: std::env::var: Returns None for names with '=' or NUL byte)
 - rust-lang#129187 (bootstrap: fix clean's remove_dir_all implementation)
 - rust-lang#129194 (Fix bootstrap test `detect_src_and_out` on Windows)
 - rust-lang#129231 (improve submodule updates)
 - rust-lang#129235 (Check that `#[may_dangle]` is properly applied)
 - rust-lang#129245 (Typo)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#127679 (Stabilize `raw_ref_op` (RFC 2582))
 - rust-lang#128084 (Suggest adding Result return type for associated method in E0277.)
 - rust-lang#128628 (When deduplicating unreachable blocks, erase the source information.)
 - rust-lang#128902 (doc: std::env::var: Returns None for names with '=' or NUL byte)
 - rust-lang#129048 (Update `crosstool-ng` for loongarch64)
 - rust-lang#129116 (Include a copy of `compiler-rt` source in the `download-ci-llvm` tarball)
 - rust-lang#129208 (Fix order of normalization and recursion in const folding.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 332ab61 into rust-lang:master Aug 19, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2024
Rollup merge of rust-lang#128902 - evanj:evan.jones/env-var-doc, r=workingjubilee

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 rust-lang#109894, which closed Issue rust-lang#109893.

This documentation was incorrectly added in commit f2c0f29, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants