Skip to content

fix(d_net): silence static_mut_refs on EXITMSG buffer#144

Merged
sunsided merged 2 commits into
mainfrom
feature/d_net-exitmsg-static-mut-ref
May 22, 2026
Merged

fix(d_net): silence static_mut_refs on EXITMSG buffer#144
sunsided merged 2 commits into
mainfrom
feature/d_net-exitmsg-static-mut-ref

Conversation

@sunsided

Copy link
Copy Markdown
Owner

Summary

EXITMSG.len() inside PlayerQuitGame (room/src/doom/d_net.rs:302) implicitly created a shared reference to the function-local static mut EXITMSG just to read its array length, tripping the Rust 2024 static_mut_refs warning that ships as a deny-by-default candidate in the 2024 edition.

The buffer length is a compile-time constant (80), so the lint is mechanically eliminated by hoisting the length into a local const.

Before

static mut EXITMSG: [c_char; 80] = [0; 80];

M_StringCopy(
    std::ptr::addr_of_mut!(EXITMSG[0]),
    DEH_String(EXIT_MSG.as_ptr() as *const c_char),
    EXITMSG.len(),
);

EXITMSG.len() requires &EXITMSG, which is a shared reference to a static mut. cargo check emits:

warning: creating a shared reference to mutable static
   --> room/src/doom/d_net.rs:302:9
    |
302 |         EXITMSG.len(),
    |         ^^^^^^^^^^^^^ shared reference to mutable static
    = note: `#[warn(static_mut_refs)]` (part of `#[warn(rust_2024_compatibility)]`) on by default

After

const EXITMSG_LEN: usize = 80;
static mut EXITMSG: [c_char; EXITMSG_LEN] = [0; EXITMSG_LEN];

M_StringCopy(
    std::ptr::addr_of_mut!(EXITMSG[0]),
    DEH_String(EXIT_MSG.as_ptr() as *const c_char),
    EXITMSG_LEN,
);

No reference to the static is taken. The array type still uses the same constant so the length stays single-sourced.

Outcome

  • cargo check lib warnings drop from 1 to 0 (the static_mut_refs hit was the only one).
  • cargo build passes.
  • gitnexus_impact(PlayerQuitGame, upstream): LOW, 0 direct callers in the indexed graph (PlayerQuitGame is invoked from TryRunTics via direct call, not through a tracked edge).
  • gitnexus_detect_changes: LOW, no execution flows affected.

Review Instructions

  1. Read room/src/doom/d_net.rs:294-313 - confirm only the literal 80 was hoisted into EXITMSG_LEN and the offset arithmetic (EXITMSG[7] += player_idx as c_char;) is unchanged.
  2. Verify the M_StringCopy size argument is still 80 (now expressed as EXITMSG_LEN).
  3. Confirm no other call site reads EXITMSG.len() (it's a function-local static, scope is PlayerQuitGame only).

`EXITMSG.len()` inside `PlayerQuitGame` implicitly created a shared
reference to the function-local `static mut EXITMSG` to read its
length, tripping the Rust 2024 `static_mut_refs` warning. Hoist the
length into a local `const EXITMSG_LEN: usize = 80` used for both
the array type and the `M_StringCopy` size argument, so no reference
to the static is created.
Copilot AI review requested due to automatic review settings May 22, 2026 18:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a Rust 2024 static_mut_refs lint hit in PlayerQuitGame by avoiding an implicit shared reference to a function-local static mut buffer when passing its size to M_StringCopy.

Changes:

  • Hoists the literal exit-message buffer length (80) into a local const EXITMSG_LEN.
  • Replaces EXITMSG.len() with EXITMSG_LEN to avoid taking &EXITMSG (shared ref to static mut).
  • Updates the EXITMSG array type and initializer to use the new constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread room/src/doom/d_net.rs
Comment on lines 295 to +298
/// 80-byte scratch buffer holding the formatted "Player N left the game"
/// message; its address is passed to the console-player's message pointer.
static mut EXITMSG: [c_char; 80] = [0; 80];
const EXITMSG_LEN: usize = 80;
static mut EXITMSG: [c_char; EXITMSG_LEN] = [0; EXITMSG_LEN];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d324f0: the original buffer doc comment now sits directly above static mut EXITMSG, and EXITMSG_LEN got its own short doc explaining why the constant exists (so M_StringCopy doesn't need to take a shared reference to the static to read its length).

After the previous commit hoisted the buffer capacity into
`EXITMSG_LEN`, the existing doc comment attached to the new `const`
instead of the `static mut EXITMSG` it describes. Move the buffer
doc onto `EXITMSG` and add a short doc for `EXITMSG_LEN` explaining
why it exists.
@sunsided sunsided merged commit 88b357a into main May 22, 2026
3 checks passed
@sunsided sunsided deleted the feature/d_net-exitmsg-static-mut-ref branch May 22, 2026 18:31
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.

2 participants