Skip to content

Commit

Permalink
Fixed static_mut_refs warning
Browse files Browse the repository at this point in the history
```text
warning: creating a mutable reference to mutable static is discouraged
    --> test/signal/test_signals.rs:1164:22
     |
1164 |             unsafe { DO_SETCONTEXT_RES.take() },
     |                      ^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static
     |
     = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
     = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives
     = note: `#[warn(static_mut_refs)]` on by default
```
  • Loading branch information
stevenengler committed Oct 8, 2024
1 parent ca337da commit d84b563
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/test/signal/test_signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ fn test_validate_context() -> Result<(), Box<dyn Error>> {
assert_eq!(rv, 0);
// The signal handler sees the syscall return value stored in RAX.
assert_eq!(
unsafe { DO_SETCONTEXT_RES.take() },
unsafe { std::ptr::replace(std::ptr::addr_of_mut!(DO_SETCONTEXT_RES), None) },
Some(DoSetcontextHandlerResult {
ctx_rax: -(libc::EINTR as i64)
})
Expand Down Expand Up @@ -1190,7 +1190,7 @@ fn test_validate_context() -> Result<(), Box<dyn Error>> {
// context, but it's unclear that just "fixing" that register without
// fixing the others would have much point. Don't assert anything about it;
// just clear it.
unsafe { DO_SETCONTEXT_RES.take() };
unsafe { std::ptr::replace(std::ptr::addr_of_mut!(DO_SETCONTEXT_RES), None) };
}

// Same thing again, but sleep using a direct syscall, which will be
Expand All @@ -1208,7 +1208,7 @@ fn test_validate_context() -> Result<(), Box<dyn Error>> {
assert!(matches!(res, NanosleepRelativeResult::Ok));
// The signal handler sees the original syscall return value stored in RAX.
assert_eq!(
unsafe { DO_SETCONTEXT_RES.take() },
unsafe { std::ptr::replace(std::ptr::addr_of_mut!(DO_SETCONTEXT_RES), None) },
Some(DoSetcontextHandlerResult {
ctx_rax: -(libc::EINTR as i64)
})
Expand Down

0 comments on commit d84b563

Please sign in to comment.