fix(d_net): silence static_mut_refs on EXITMSG buffer#144
Merged
Conversation
`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.
There was a problem hiding this comment.
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 localconst EXITMSG_LEN. - Replaces
EXITMSG.len()withEXITMSG_LENto avoid taking&EXITMSG(shared ref tostatic mut). - Updates the
EXITMSGarray type and initializer to use the new constant.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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]; |
Owner
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EXITMSG.len()insidePlayerQuitGame(room/src/doom/d_net.rs:302) implicitly created a shared reference to the function-localstatic mut EXITMSGjust to read its array length, tripping the Rust 2024static_mut_refswarning 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 localconst.Before
EXITMSG.len()requires&EXITMSG, which is a shared reference to astatic mut.cargo checkemits:After
No reference to the static is taken. The array type still uses the same constant so the length stays single-sourced.
Outcome
cargo checklib warnings drop from 1 to 0 (thestatic_mut_refshit was the only one).cargo buildpasses.gitnexus_impact(PlayerQuitGame, upstream): LOW, 0 direct callers in the indexed graph (PlayerQuitGame is invoked fromTryRunTicsvia direct call, not through a tracked edge).gitnexus_detect_changes: LOW, no execution flows affected.Review Instructions
room/src/doom/d_net.rs:294-313- confirm only the literal80was hoisted intoEXITMSG_LENand the offset arithmetic (EXITMSG[7] += player_idx as c_char;) is unchanged.M_StringCopysize argument is still 80 (now expressed asEXITMSG_LEN).EXITMSG.len()(it's a function-local static, scope isPlayerQuitGameonly).