Skip to content

std::env::{set_var, remove_var} is called in tests without safety documentation #148432

@tbu-

Description

@tbu-

Introduced by @ehuss in #136983 (36733f3, ef20a1b), apparently without double-checking whether these functions were actually safe to call.

Found when trying to audit whether this repository's calls to these unsafe environment variable functions were safe. It doesn't appear to be the case to me, e.g.

assert_eq!(get_dbpath_for_term(""), None);
unsafe {
env::set_var("TERMINFO_DIRS", ":");
}
assert_eq!(x("screen"), PathBuf::from("/usr/share/terminfo/s/screen"));
unsafe {
env::remove_var("TERMINFO_DIRS");
}

unsafe {
env::set_var("RUN_TEST_NEW_ENV2", "456");
}
let result = cmd.output().unwrap();
unsafe {
env::remove_var("RUN_TEST_NEW_ENV2");
}

/// unsafe { env::set_var("PATH", &new_path); }

The last example is even in user-facing documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-testsuiteArea: The testsuite used to check the correctness of rustcneeds-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions