Skip to content

YJIT: Suppress warn(static_mut_refs) #10440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024
Merged

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Apr 3, 2024

As of Rust 1.77, creating a &mut for static mut is warned rust-lang/rust#114447.

warning: creating a mutable reference to mutable static is discouraged
  --> ../src/yjit/src/stats.rs:72:35
   |
72 |     unsafe { get_method_idx(name, &mut CFUNC_NAME_TO_IDX, &mut CFUNC_CALL_COUNT) }
   |                                   ^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static
   |
   = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
   = note: this will be a hard error in the 2024 edition
   = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
   = note: `#[warn(static_mut_refs)]` on by default
help: use `addr_of_mut!` instead to create a raw pointer
   |
72 |     unsafe { get_method_idx(name, addr_of_mut!(CFUNC_NAME_TO_IDX), &mut CFUNC_CALL_COUNT) }
   |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Right now, get_cfunc_idx/get_iseq_idx and set_call_counts are not used at the same time. So it's not an UB for us. This PR just suppresses the warning by using the macro suggested by the warning.

@k0kubun k0kubun requested a review from a team as a code owner April 3, 2024 17:06
@k0kubun k0kubun merged commit 354e158 into ruby:master Apr 3, 2024
99 checks passed
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.

3 participants