diff --git a/tests/ui/static/use_of_mutable_static_unsafe_block.rs b/tests/ui/static/use_of_mutable_static_unsafe_block.rs new file mode 100644 index 0000000000000..a0b5967dcaa36 --- /dev/null +++ b/tests/ui/static/use_of_mutable_static_unsafe_block.rs @@ -0,0 +1,9 @@ +// compile-flags: --edition 2024 -Zunstable-options + +fn main() { + static mut X: i32 = 1; + unsafe { + let _y = &X; + //~^ ERROR use of mutable static is discouraged + } +} diff --git a/tests/ui/static/use_of_mutable_static_unsafe_block.stderr b/tests/ui/static/use_of_mutable_static_unsafe_block.stderr new file mode 100644 index 0000000000000..aa25d3a93a570 --- /dev/null +++ b/tests/ui/static/use_of_mutable_static_unsafe_block.stderr @@ -0,0 +1,11 @@ +error[E0796]: use of mutable static is discouraged + --> $DIR/use_of_mutable_static_unsafe_block.rs:6:18 + | +LL | let _y = &X; + | ^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0796`. diff --git a/tests/ui/static/use_of_mutable_static_unsafe_fn.rs b/tests/ui/static/use_of_mutable_static_unsafe_fn.rs new file mode 100644 index 0000000000000..ccc4d034b993c --- /dev/null +++ b/tests/ui/static/use_of_mutable_static_unsafe_fn.rs @@ -0,0 +1,9 @@ +// compile-flags: --edition 2024 -Zunstable-options + +fn main() {} + +unsafe fn _foo() { + static mut X: i32 = 1; + let _y = &X; + //~^ ERROR use of mutable static is discouraged +} diff --git a/tests/ui/static/use_of_mutable_static_unsafe_fn.stderr b/tests/ui/static/use_of_mutable_static_unsafe_fn.stderr new file mode 100644 index 0000000000000..09eb955a67ad2 --- /dev/null +++ b/tests/ui/static/use_of_mutable_static_unsafe_fn.stderr @@ -0,0 +1,11 @@ +error[E0796]: use of mutable static is discouraged + --> $DIR/use_of_mutable_static_unsafe_fn.rs:7:14 + | +LL | let _y = &X; + | ^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0796`.