Skip to content

Deprecate set_var and remove_var in 1.58.0 #90830

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_feature/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::UnstableFeatures;

#[test]
#[allow(deprecated, deprecated_in_future)]
fn rustc_bootstrap_parsing() {
let is_bootstrap = |env, krate| {
std::env::set_var("RUSTC_BOOTSTRAP", env);
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
@@ -257,6 +257,7 @@ fn pre_expansion_lint(
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
/// harness if one is to be provided, injection of a dependency on the
/// standard library and prelude, and name resolution.
#[allow(deprecated, deprecated_in_future)]
pub fn configure_and_expand(
sess: &Session,
lint_store: &LintStore,
8 changes: 8 additions & 0 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
@@ -327,6 +327,10 @@ impl Error for VarError {
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
/// ```
#[stable(feature = "env", since = "1.0.0")]
#[rustc_deprecated(
since = "1.58.0",
reason = "unclear soundness on POSIX, use `libc::setenv` or `std::process::Command::env` instead"
)]
pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
_set_var(key.as_ref(), value.as_ref())
}
@@ -369,6 +373,10 @@ fn _set_var(key: &OsStr, value: &OsStr) {
/// assert!(env::var(key).is_err());
/// ```
#[stable(feature = "env", since = "1.0.0")]
#[rustc_deprecated(
since = "1.58.0",
reason = "unclear soundness on POSIX, use `libc::unsetenv` or `std::process::Command::env_remove` instead"
)]
pub fn remove_var<K: AsRef<OsStr>>(key: K) {
_remove_var(key.as_ref())
}
1 change: 1 addition & 0 deletions library/std/src/process/tests.rs
Original file line number Diff line number Diff line change
@@ -260,6 +260,7 @@ fn test_add_to_env() {

#[test]
#[cfg_attr(target_os = "vxworks", ignore)]
#[allow(deprecated, deprecated_in_future)]
fn test_capture_env_at_spawn() {
use crate::env;

1 change: 1 addition & 0 deletions library/std/src/sys/windows/process/tests.rs
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ fn test_make_command_line() {
// On Windows, environment args are case preserving but comparisons are case-insensitive.
// See: #85242
#[test]
#[allow(deprecated, deprecated_in_future)]
fn windows_env_unicode_case() {
let test_cases = [
("ä", "Ä"),
1 change: 1 addition & 0 deletions library/std/src/sys_common/process.rs
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ impl CommandEnv {
}

// Apply these changes directly to the current environment
#[allow(deprecated, deprecated_in_future)]
pub fn apply(&self) {
if self.clear {
for (k, _) in env::vars_os() {
2 changes: 2 additions & 0 deletions library/std/tests/env.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated, deprecated_in_future)]

use std::env::*;
use std::ffi::{OsStr, OsString};

1 change: 1 addition & 0 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -151,6 +151,7 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
///
/// This is the entry point for the main function generated by `rustc --test`
/// when panic=abort.
#[allow(deprecated, deprecated_in_future)]
pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
// If we're being run in SpawnedSecondary mode, run the test here. run_test
// will then exit the process.
1 change: 1 addition & 0 deletions library/test/src/term/terminfo/searcher/tests.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use super::*;

#[test]
#[ignore = "buildbots don't have ncurses installed and I can't mock everything I need"]
#[allow(deprecated, deprecated_in_future)]
fn test_get_dbpath_for_term() {
// woefully inadequate test coverage
// note: current tests won't work with non-standard terminfo hierarchies (e.g., macOS's)
1 change: 1 addition & 0 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ pub fn tracked_env_var_os<K: AsRef<OsStr> + Display>(key: K) -> Option<OsString>
// the one we want to use. As such, we restore the environment to what bootstrap saw. This isn't
// perfect -- we might actually want to see something from Cargo's added library paths -- but
// for now it works.
#[allow(deprecated, deprecated_in_future)]
pub fn restore_library_path() {
let key = tracked_env_var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
1 change: 1 addition & 0 deletions src/test/ui/command/command-exec.rs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ use std::env;
use std::os::unix::process::CommandExt;
use std::process::Command;

#[allow(deprecated, deprecated_in_future)]
fn main() {
let mut args = env::args();
let me = args.next().unwrap();
1 change: 1 addition & 0 deletions src/test/ui/process/process-envs.rs
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ pub fn env_cmd() -> Command {
cmd
}

#[allow(deprecated, deprecated_in_future)]
fn main() {
// save original environment
let old_env = env::var_os("RUN_TEST_NEW_ENV");
1 change: 1 addition & 0 deletions src/test/ui/process/process-remove-from-env.rs
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ pub fn env_cmd() -> Command {
cmd
}

#[allow(deprecated, deprecated_in_future)]
fn main() {
// save original environment
let old_env = env::var_os("RUN_TEST_NEW_ENV");
1 change: 1 addition & 0 deletions src/test/ui/std-backtrace.rs
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ fn main() {
}
}

#[allow(deprecated, deprecated_in_future)]
fn runtest(me: &str) {
env::remove_var("RUST_BACKTRACE");
env::remove_var("RUST_LIB_BACKTRACE");