about summary refs log tree commit diff
path: root/library/std/src/env.rs
AgeCommit message (Collapse)AuthorLines
2025-06-06Add new Tier-3 targets: `loongarch32-unknown-none*`WANG Rui-0/+1
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-05-01Delegate to inner `vec::IntoIter` from `env::ArgsOs`Thalia Archibald-1/+72
Delegate from `std::env::ArgsOs` to the methods of the inner platform-specific iterators, when it would be more efficient than just using the default methods of its own impl. Most platforms use `vec::IntoIter` as the inner type, so prioritize delegating to the methods it provides. `std::env::Args` is implemented atop `std::env::ArgsOs` and performs UTF-8 validation with a panic for invalid data. This is a visible effect which users certainly rely on, so we can't skip any arguments. Any further iterator methods would skip some elements, so no change is needed for that type. Add `#[inline]` for any methods which simply wrap the inner iterator.
2025-04-21Move `sys::pal::os::Env` into `sys::env`Thalia Archibald-6/+6
Although `Env` (as `Vars`), `Args`, path functions, and OS constants are publicly exposed via `std::env`, their implementations are each self-contained. Keep them separate in `std::sys` and make a new module, `sys::env`, for `Env`.
2025-04-18Combine env consts into std::sys::env_constsThalia Archibald-1/+1
2025-03-18Rollup merge of #136320 - RalfJung:exit, r=the8472Matthias Krüger-1/+1
exit: document interaction with C Cc https://github.com/rust-lang/rust/issues/126600
2025-03-07Mention `env` and `option_env` macros in `std::env::var` docsGuillaume Gomez-0/+3
2025-03-06Rollup merge of #137327 - arlosi:home-dir, r=Mark-SimulacrumMichael Goulet-5/+0
Undeprecate env::home_dir #132515 fixed the implementation of `env::home_dir`, but didn't remove the deprecation. Based on [this comment](https://github.com/rust-lang/rust/pull/132515#discussion_r1829715262), libs-api decided to undeprecate in the next release. Let's do that! cc #132650
2025-03-04exit: document interaction with CRalf Jung-1/+1
2025-02-20Undeprecate env::home_dirArlo Siemsen-5/+0
2025-02-21Correct doc about `temp_dir()` behavior on AndroidWang Han-1/+3
Since commit https://github.com/aosp-mirror/platform_frameworks_base/commit/d5ccb038f69193fb63b5169d7adc5da19859c9d8, `TMPDIR` will be set to application's cache dir when app starts.
2025-02-13std: Apply deprecated_safe_2024Eric Huss-1/+1
2025-01-26Move std::env unit tests to integration testsbjorn3-3/+0
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.