Skip to content

Commit

Permalink
fix: static_mut_refs lint from rustc
Browse files Browse the repository at this point in the history
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 <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

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 <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

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 <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

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 <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
  • Loading branch information
zjp-CN committed Jan 3, 2025
1 parent 8d85a32 commit eea3fb7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit eea3fb7

Please sign in to comment.