Skip to content
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

chore: ignore lint unsafe_op_in_unsafe_fn for usage of env::remove_var #2421

Merged
merged 1 commit into from
Jun 2, 2024

Conversation

SteveLauC
Copy link
Member

@SteveLauC SteveLauC commented Jun 1, 2024

What does this PR do

std::env::remove_var has been made unsafe. Due to lint unsafe_op_in_unsafe_fn, we need to wrap it in an unsafe block.

This PR is for the following CI failure (full log here):

error[E0133]: call to unsafe function `std::env::remove_var` is unsafe and requires unsafe block
  --> src/env.rs:52:17
   |
52 |                 env::remove_var(name);
   |                 ^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
   |
   = note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
   = note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
  --> src/env.rs:41:1
   |
41 | pub unsafe fn clearenv() -> std::result::Result<(), ClearEnvError> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
  --> src/lib.rs:94:9
   |
94 | #![deny(unsafe_op_in_unsafe_fn)]
   |         ^^^^^^^^^^^^^^^^^^^^^^

std::env::remove_var() will become unsafe ONLY in Rust 2024, Nix is using Rust 2021, so the above issue should not happen. I have filed an issue for this bug, before it gets fixed, ignore the lint unsafe_op_in_unsafe_fn here.

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

@SteveLauC
Copy link
Member Author

SteveLauC commented Jun 1, 2024

Well, we should only do this for toolchains newer than nightly 2024-05-31, this can be achieved with the help of rustversion.

But I kinda think introducing a new dependency just for this issue is not worthwhile, maybe we should just ignore the lint for this case.

@SteveLauC
Copy link
Member Author

This is a breaking change and should be only available in Rust 2024, we are using Rust 2021 so we should not encounter this. I have filed an issue to the Rust repo.

@SteveLauC SteveLauC changed the title refactor: wrap std::env::remove_var() in unsafe block chore: ignore lint unsafe_op_in_unsafe_fn for usage of env::remove_var Jun 2, 2024
@SteveLauC SteveLauC added this pull request to the merge queue Jun 2, 2024
Merged via the queue into nix-rust:master with commit f1b1ded Jun 2, 2024
36 checks passed
@SteveLauC SteveLauC deleted the refactor/unsafe branch June 2, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant