Proposal
Assuming that#[deprecated_safe] is accepted and applied to env::set_var/env::remove_var, there will need to be some way for unit tests to be made sound if they call the now unsafe env::set_var/env::remove_var. This can be done by guaranteeing that specific tests are started with only a single thread active, and then each affected test can ensure it meets the safety precondition of env::set_var/env::remove_var that no other threads could be reading or writing the environment.
To guarantee specific tests are started with only a single thread active, a new attribute is added that can be applied to #[test] items. This will cause each marked test to be run in its own isolated process, with a single thread guaranteed to be active when the #[test] item is entered. A new process is needed for each test, rather than running marked tests one after another in a single thread, as a prior test may have spun up background threads.
Proof of concept implementation that piggybacks off the functionality already present for -Zpanic-abort-tests.
Some additional motivations from the zulip stream, unrelated to env::set_var/env::remove_var:
Concerns from zulip:
Alternatives from zulip:
Mentors or Reviewers
If you have a reviewer or mentor in mind for this work, mention then
here. You can put your own name here if you are planning to mentor the
work.
Process
The main points of the Major Change Process are as follows:
You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
Proposal
Assuming that
#[deprecated_safe]is accepted and applied toenv::set_var/env::remove_var, there will need to be some way for unit tests to be made sound if they call the now unsafeenv::set_var/env::remove_var. This can be done by guaranteeing that specific tests are started with only a single thread active, and then each affected test can ensure it meets the safety precondition ofenv::set_var/env::remove_varthat no other threads could be reading or writing the environment.To guarantee specific tests are started with only a single thread active, a new attribute is added that can be applied to
#[test]items. This will cause each marked test to be run in its own isolated process, with a single thread guaranteed to be active when the#[test]item is entered. A new process is needed for each test, rather than running marked tests one after another in a single thread, as a prior test may have spun up background threads.Proof of concept implementation that piggybacks off the functionality already present for -Zpanic-abort-tests.
Some additional motivations from the zulip stream, unrelated to
env::set_var/env::remove_var:Concerns from zulip:
Alternatives from zulip:
Mentors or Reviewers
If you have a reviewer or mentor in mind for this work, mention then
here. You can put your own name here if you are planning to mentor the
work.
Process
The main points of the Major Change Process are as follows:
@rustbot second.-C flag, then full team check-off is required.@rfcbot fcp mergeon either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.