Skip to content

Commit

Permalink
otel: Disable static_mut_refs warning for nxt_otel_rs_span_tx()
Browse files Browse the repository at this point in the history
When compiling OTEL support with rustc 1.83.0 we started getting the
following warning

     Compiling otel v0.1.0 (/home/andrew/src/unit/src/otel)
  warning: creating a mutable reference to mutable static is discouraged
    --> src/lib.rs:42:9
     |
  42 |         SPAN_TX.take();
     |         ^^^^^^^^^^^^^^ 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: `otel` (lib) generated 1 warning
      Finished `release` profile [optimized] target(s) in 1m 07s

However it *seems* our usage is OK, so we can disable this warning
(which it seems will soon turn into a hard error), fortunately we only
need to disable it for the nxt_otel_rs_span_tx() function.

Signed-off-by: Andrew Clayton <[email protected]>
  • Loading branch information
ac000 committed Dec 10, 2024
1 parent d71ea64 commit f189d39
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/otel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub type nxt_uint_t = usize;

// Stored sender channel to send spans or a shutdown message to within the
// Tokio runtime.
#[allow(static_mut_refs)]
unsafe fn nxt_otel_rs_span_tx(destruct: bool) -> *const OnceLock<Sender<SpanMessage>> {
static mut SPAN_TX: OnceLock<Sender<SpanMessage>> = OnceLock::new();
if destruct {
Expand Down

0 comments on commit f189d39

Please sign in to comment.