From 91b7331a8259b374e90082cfb86ae98f4d54d274 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 14 Jul 2024 17:07:19 -0700 Subject: [PATCH] std: Directly call unsafe {un,}setenv in env --- std/src/env.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/std/src/env.rs b/std/src/env.rs index b47b6531d5380..36add02d68c5c 100644 --- a/std/src/env.rs +++ b/std/src/env.rs @@ -9,7 +9,6 @@ //! and those without will return a [`String`]. #![stable(feature = "env", since = "1.0.0")] -#![allow(unsafe_op_in_unsafe_fn)] #[cfg(test)] mod tests; @@ -367,11 +366,8 @@ impl Error for VarError { #[rustc_deprecated_safe_2024] #[stable(feature = "env", since = "1.0.0")] pub unsafe fn set_var, V: AsRef>(key: K, value: V) { - _set_var(key.as_ref(), value.as_ref()) -} - -unsafe fn _set_var(key: &OsStr, value: &OsStr) { - os_imp::setenv(key, value).unwrap_or_else(|e| { + let (key, value) = (key.as_ref(), value.as_ref()); + unsafe { os_imp::setenv(key, value) }.unwrap_or_else(|e| { panic!("failed to set environment variable `{key:?}` to `{value:?}`: {e}") }) } @@ -434,11 +430,8 @@ unsafe fn _set_var(key: &OsStr, value: &OsStr) { #[rustc_deprecated_safe_2024] #[stable(feature = "env", since = "1.0.0")] pub unsafe fn remove_var>(key: K) { - _remove_var(key.as_ref()) -} - -unsafe fn _remove_var(key: &OsStr) { - os_imp::unsetenv(key) + let key = key.as_ref(); + unsafe { os_imp::unsetenv(key) } .unwrap_or_else(|e| panic!("failed to remove environment variable `{key:?}`: {e}")) }