about summary refs log tree commit diff
path: root/library/std/src/env.rs
AgeCommit message (Collapse)AuthorLines
2025-01-17doc: Point to methods on `Command` as alternatives to `set/remove_var`clubby789-0/+8
2025-01-08update version placeholdersPietro Albini-1/+1
2024-12-05Expand home_dir docsChris Denton-0/+7
2024-11-30Rollup merge of #132515 - kornelski:home_fix, r=jhpratt许杰友 Jieyou Xu (Joe)-10/+6
Fix and undeprecate home_dir() `home_dir()` has been deprecated for 6 years due to using `HOME` env var on Windows. It's been a long time, and having a perpetually buggy and deprecated function in the standard library is not useful. I propose fixing and undeprecating it. 6 years seems more than long enough to warn users against relying on this function. The change in behavior is minor, and it's more of a bug fix than breakage. The old behavior is unlikely to be useful, and even if anybody actually needed to specifically use the non-standard `HOME` on Windows, they can trivially mitigate this change by reading the env var themselves. ---- Use of `USERPROFILE` is in line with the `home` crate: https://github.com/rust-lang/cargo/blob/37bc5f0232a0bb72dedd2c14149614fd8cdae649/crates/home/src/windows.rs#L12 The `home` crate uses `SHGetKnownFolderPath` instead of `GetUserProfileDirectoryW`. AFAIK it doesn't make any difference in practice, because `SHGetKnownFolderPath` merely adds support for more kinds of folders, including virtual (non-filesystem) folders identified by a GUID, but the specific case of [`FOLDERID_Profile`](https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid#FOLDERID_Profile) is documented as a FIXED folder (a regular filesystem path). Just in case, I've added a note to documentation that the use of `GetUserProfileDirectoryW` can change. I've used `CURRENT_RUSTC_VERSION` in a doccomment. `replace-version-placeholder` tool seems to perform a simple string replacement, so hopefully it'll get updated.
2024-11-23Rollup merge of #131505 - madsmtm:darwin_user_temp_dir, r=dtolnay许杰友 Jieyou Xu (Joe)-3/+12
use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin Rebased version of https://github.com/rust-lang/rust/pull/100824, FCP has completed there. Motivation from https://github.com/rust-lang/rust/pull/100824#issuecomment-1262264127: > This is a behavioral change in an edge case on Darwin platforms (macOS, iOS, ...). > > Specifically, this changes it so that iff `TMPDIR` is unset in the environment, then we use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` to query the user temporary directory (previously we just returned `"/tmp"`). If this fails (probably possible in a sandboxed program), only then do we fallback to `"/tmp"` (as before). > > The motivations here are two-fold: > > 1. This is better for security, and is in line with the [platform security recommendations](https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585-SW10), as it is unavailable to other users (although it is the same value as seen by all other processes run by the same user). > 2. This is a more consistent fallback for when `getenv("TMPDIR")` is unavailable, as `$TMPDIR` is usually initialized to the `DARWIN_USER_TEMP_DIR`. > > It seems quite unlikely that anybody will break because of this, and I think it falls under the carve-out we have for platform specific behavior: https://doc.rust-lang.org/nightly/std/io/index.html#platform-specific-behavior. Closes https://github.com/rust-lang/rust/issues/99608. Closes https://github.com/rust-lang/rust/pull/100824. ``@rustbot`` label O-apple T-libs-api r? Dylan-DPC
2024-11-04Fix and undeprecate home_dir()Kornel-10/+6
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-1/+1
2024-10-10use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on darwinThom Chiovoloni-3/+12
2024-09-17Rollup merge of #128535 - mmvanheusden:master, r=workingjubileeMatthias Krüger-66/+107
Format `std::env::consts` docstrings with markdown backticks This clarifies possible outputs the constants might be. **Before:** -- <img src="https://github.com/user-attachments/assets/8ee8772a-7562-42a2-89be-f8772b76dbd5" width="500px"> **After:** -- <img src="https://github.com/user-attachments/assets/4632e5e2-db3e-4372-b13e-006cc1701eb1" width="500px">
2024-09-05update cfgsBoxy-12/+4
2024-08-18Rollup merge of #128902 - evanj:evan.jones/env-var-doc, r=workingjubileeTrevor Gross-6/+5
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.
2024-08-18code review improvementsEvan Jones-9/+5
2024-08-16Refer to other docsMaarten-23/+3
2024-08-15Add unordered list with possible values for each constMaarten-64/+125
2024-08-15Format std::env::consts docstringsMaarten-37/+37
This clarifies possible outputs the constants might be.
2024-08-13`#[deprecated_safe_2024]`: Also use the `// TODO:` hint in the compiler errorTobias Bucher-2/+2
This doesn't work for translated compiler error messages.
2024-08-13Allow to customize `// TODO:` comment for deprecated safe autofixTobias Bucher-2/+14
Relevant for the deprecation of `CommandExt::before_exit` in #125970.
2024-08-09doc: std::env::var: Returns None for names with '=' or NUL byteEvan Jones-5/+8
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.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-3/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-16Rollup merge of #125206 - mgeisler:simplify-std-env-vars, r=jhpratt,tgross35Trevor Gross-10/+4
Simplify environment variable examples I’ve found myself visiting the documentation for `std::env::vars` every few months, and every time I do, it is because I want to quickly get a snippet to print out all environment variables :-) So I think it could be nice to simplify the examples a little to make them self-contained. It is of course a style question if one should import a module a not, but I personally don’t import modules used just once in a code snippet.
2024-07-14std: Directly call unsafe {un,}setenv in envJubilee Young-11/+4
2024-07-14std: deny(unsafe_op_in_unsafe_fn) but allow sitesJubilee Young-0/+1
This provides a list of locations to hunt down issues in.
2024-06-12Auto merge of #126273 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrumbors-16/+0
Bump stage0 to 1.80.0 r? `@Mark-Simulacrum`
2024-06-11set_env: State the conclusion upfrontChris Denton-4/+8
2024-06-11remove cfg(bootstrap)Pietro Albini-16/+0
2024-05-29Elaborate about modifying env vars in multi-threaded programsTobias Bucher-18/+28
2024-05-29Add note about safety of `std::env::set_var` on WindowsTobias Bucher-5/+11
2024-05-29Make `std::env::{set_var, remove_var}` unsafe in edition 2024Tobias Bucher-20/+34
Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions. Fixes #27970. Fixes #90308. CC #124866.
2024-05-21Simplify environment variable examplesMartin Geisler-10/+4
I’ve found myself visiting the documentation for `std::env::vars` every few months, and every time I do, it is because I want to quickly get a snippet to print out all environment variables :-) So I think it could be nice to simplify the examples a little to make them self-contained. It is of course a style question if one should import a module a not, but I personally don’t import modules used just once in a code snippet.
2024-02-29Remove doc aliases to PATHTrevor Gross-2/+0
Remove aliases for `split_paths` and `join_paths` as should have been done in <https://github.com/rust-lang/rust/pull/119748> (Bors merged the wrong commit).
2024-02-29Rollup merge of #119748 - tgross35:suggest-path-split, r=AmanieuJacob Pratt-1/+17
Increase visibility of `join_path` and `split_paths` Add some crosslinking among `std::env` pages to make it easier to discover `join_paths` and `split_paths`. Also add aliases to help anyone searching for `PATH`.
2024-02-18Add uncontroversial syscall doc aliases to std docsSabrinaJewson-1/+2
2024-02-10Fix typoJosh Triplett-1/+1
Co-authored-by: Benjamin Peter <145429680+benjamin-nw@users.noreply.github.com>
2024-01-08Increase visibility of `join_path` and `split_paths`Trevor Gross-1/+17
Add some crosslinking among `std::env` pages. Also add aliases to help anyone searching for `PATH`.
2023-12-13Reformulate `std::env::{set,remove}_env` as safety noteTobias Bucher-24/+36
2023-10-18Add discussion that concurrent access to the environment is unsafeTobias Bucher-10/+28
The bug report #27970 has existed for 8 years, the actual bug dates back to Rust pre-1.0. I documented it since it's in the interest of the user to be aware of it. The note can be removed once #27970 is fixed.
2023-08-14add a csky-unknown-linux-gnuabiv2 targetDirreke-0/+1
2023-08-07Better Debug for Vars and VarsOsTamir Duberstein-4/+8
Display actual vars instead of two dots. The same was done for Args and ArgsOs in 275f9a04af6191e3aee3852a5a1713.
2023-04-11Rollup merge of #109894 - ↵Michael Goulet-12/+5
fleetingbytes:109893-var_os-never-returns-an-error, r=cuviper Remove Errors section from var_os docs Remove `Errors` section from `var_os` documentation, fixes #109893
2023-04-11Break up long first paragraphfleetingbytes-3/+4
Further referring to `var_os` as a "function" (like in `var`), rather than "method".
2023-04-04library/std: Add support for loongarch64zhaixiaojuan-0/+1
2023-04-03Preserve potential mood for equal or NUL signfleetingbytes-5/+3
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).
2023-04-03Remove redundant empty linefleetingbytes-1/+0
one is enough
2023-04-03remove self-reference in var_os docfleetingbytes-1/+0
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2023-04-03add situation where var_os returns Nonefleetingbytes-1/+7
Re-introduced some of the former errors as situations where `None` is returned.
2023-04-03Update env.rsfleetingbytes-10/+0
Remove `Errors` section from `var_os` documentation
2022-12-11Rollup merge of #101648 - Timmmm:home_dir_docs, r=joshtriplettMatthias Krüger-1/+8
Better documentation for env::home_dir()'s broken behaviour This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684
2022-10-03Reword "has no meaning" per suggestionTim-2/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-09-28env::temp_dir: fix a typoRalf Jung-1/+1
2022-09-10Better documentation for env::home_dir()'s broken behaviourTim Hutt-1/+8
This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684