From eea3fb7af1493dc95f1aeaef916b1763a67227f7 Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 3 Jan 2025 22:17:44 +0800 Subject: [PATCH] fix: static_mut_refs lint from rustc Braces are needed to hinder clippy lint and compact in single line. Fefer to what I posted on URLO for an example: https://users.rust-lang.org/t/static-mut-refs-lint-is-amusing/123439 --------------------------------------------------------------------------- Raw static_mut_refs lint outputs: warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:208:17 | 208 | COMMAND_PORT.write(CMOS_DISABLE_NMI | register); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = 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 warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:209:17 | 209 | DATA_PORT.read() | ^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = 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 warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:215:17 | 215 | COMMAND_PORT.write(CMOS_DISABLE_NMI | register); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = 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 warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:216:17 | 216 | DATA_PORT.write(value) | ^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = 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 --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 45fff40..975fc01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,15 +205,15 @@ cfg_if::cfg_if! { fn read_cmos_register(register: u8) -> u8 { unsafe { - COMMAND_PORT.write(CMOS_DISABLE_NMI | register); - DATA_PORT.read() + (*{ &raw mut COMMAND_PORT }).write(CMOS_DISABLE_NMI | register); + (*{ &raw mut DATA_PORT }).read() } } fn write_cmos_register(register: u8, value: u8) { unsafe { - COMMAND_PORT.write(CMOS_DISABLE_NMI | register); - DATA_PORT.write(value) + (*{ &raw mut COMMAND_PORT }).write(CMOS_DISABLE_NMI | register); + (*{ &raw mut DATA_PORT }).write(value) } }