Skip to content

Commit bc2c74f

Browse files
committed
Fixed static_mut_refs warning
```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 ```
1 parent 6856975 commit bc2c74f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/test/signal/test_signals.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ fn test_validate_context() -> Result<(), Box<dyn Error>> {
11611161
assert_eq!(rv, 0);
11621162
// The signal handler sees the syscall return value stored in RAX.
11631163
assert_eq!(
1164-
unsafe { DO_SETCONTEXT_RES.take() },
1164+
unsafe { std::ptr::replace(std::ptr::addr_of_mut!(DO_SETCONTEXT_RES), None) },
11651165
Some(DoSetcontextHandlerResult {
11661166
ctx_rax: -(libc::EINTR as i64)
11671167
})
@@ -1190,7 +1190,7 @@ fn test_validate_context() -> Result<(), Box<dyn Error>> {
11901190
// context, but it's unclear that just "fixing" that register without
11911191
// fixing the others would have much point. Don't assert anything about it;
11921192
// just clear it.
1193-
unsafe { DO_SETCONTEXT_RES.take() };
1193+
unsafe { std::ptr::replace(std::ptr::addr_of_mut!(DO_SETCONTEXT_RES), None) };
11941194
}
11951195

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

0 commit comments

Comments
 (0)