Skip to content

Commit

Permalink
Rollup merge of #126281 - ChrisDenton:env, r=jhpratt
Browse files Browse the repository at this point in the history
set_env: State the conclusion upfront

People tend to skim or skip over long explanations so we should be very upfront that `set_var` and `remove_var` are being made unsafe for a very good reason.

This is just the conclusion restated almost verbatim but earlier in the docs and separated from the explanation:

https://github.com/rust-lang/rust/blob/0c960618b56f662d933e8b864cd9632a99174e87/library/std/src/env.rs#L338-L339

I think this may help with people who may not be entirely comfortable with #125937 being rejected.
  • Loading branch information
workingjubilee authored Jun 12, 2024
2 parents 0ed474a + 751143e commit 0805ab4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ impl Error for VarError {
/// This function is also always safe to call on Windows, in single-threaded
/// and multi-threaded programs.
///
/// In multi-threaded programs on other operating systems, we strongly suggest
/// not using `set_var` or `remove_var` at all. The exact requirement is: you
/// In multi-threaded programs on other operating systems, the only safe option is
/// to not use `set_var` or `remove_var` at all.
///
/// The exact requirement is: you
/// must ensure that there are no other threads concurrently writing or
/// *reading*(!) the environment through functions or global variables other
/// than the ones in this module. The problem is that these operating systems
Expand Down Expand Up @@ -390,8 +392,10 @@ unsafe fn _set_var(key: &OsStr, value: &OsStr) {
/// This function is also always safe to call on Windows, in single-threaded
/// and multi-threaded programs.
///
/// In multi-threaded programs on other operating systems, we strongly suggest
/// not using `set_var` or `remove_var` at all. The exact requirement is: you
/// In multi-threaded programs on other operating systems, the only safe option is
/// to not use `set_var` or `remove_var` at all.
///
/// The exact requirement is: you
/// must ensure that there are no other threads concurrently writing or
/// *reading*(!) the environment through functions or global variables other
/// than the ones in this module. The problem is that these operating systems
Expand Down

0 comments on commit 0805ab4

Please sign in to comment.