Add test for the case span is unavailable

This commit is contained in:
Yuki Okushi
2026-05-17 14:58:25 +09:00
parent cbaee5df1b
commit 33d92f7b52
2 changed files with 31 additions and 0 deletions
@@ -0,0 +1,18 @@
//@ edition:2024
// Ensure that we don't make structured suggestions for interior mutability note
// when span is not available.
use std::sync::Mutex;
macro_rules! declare_mutex {
() => {
static mut MACRO_MUTEX: Mutex<bool> = Mutex::new(false);
};
}
declare_mutex!();
fn main() {
let _lock = unsafe { MACRO_MUTEX.lock().unwrap() };
//~^ ERROR creating a shared reference to mutable static [static_mut_refs]
}
@@ -0,0 +1,13 @@
error: creating a shared reference to mutable static
--> $DIR/static-mut-refs-interior-mutability-no-sugg.rs:16:26
|
LL | let _lock = unsafe { MACRO_MUTEX.lock().unwrap() };
| ^^^^^^^^^^^^^^^^^^ shared reference to mutable static
|
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
= help: use a type that relies on "interior mutability" instead; to read more on this, visit <https://doc.rust-lang.org/reference/interior-mutability.html>
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/static-mut-references.html>
= note: `#[deny(static_mut_refs)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
error: aborting due to 1 previous error