Skip to content

Commit

Permalink
Merge pull request #50 from dtolnay/staticmut
Browse files Browse the repository at this point in the history
Fix static_mut_ref warning
  • Loading branch information
dtolnay authored Jan 10, 2024
2 parents 5a4dd6a + a20bb67 commit 3f46111
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/ignore.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
use crate::de::{Map, Seq, Visitor};
use crate::error::Result;
use alloc::boxed::Box;
use core::ptr;

impl dyn Visitor {
pub fn ignore() -> &'static mut dyn Visitor {
static mut IGNORE: Ignore = Ignore;
unsafe { &mut IGNORE }
//
// The following may be needed if stacked borrows gets more selective
// about the above in the future:
//
// unsafe { &mut *ptr::addr_of_mut!(IGNORE) }
//

// Conceptually we have an array of type [Ignore; ∞] in a static, which
// is zero sized, and each caller of `fn ignore` gets a unique one of
// them, as if by `&mut *ptr::addr_of_mut!(IGNORE[i++])` for some
// appropriately synchronized i.
unsafe { &mut *ptr::addr_of_mut!(IGNORE) }
}
}

Expand Down

0 comments on commit 3f46111

Please sign in to comment.